在驱动程序中,经常会在xxx_driver结构体中看看到__devexit_p(x),譬如:
static struct spi_driver spidev_spi = {
.driver = {
.name = "spidev", //spi_bus_type上spi_despi_devie与spi_driver匹配依赖于此名字
.owner = THIS_MODULE,
},
.probe = spidev_probe,
.remove = __devexit_p(spidev_remove),
}; 那么,它到底有什么作用啦?让我们先看看它的定义。
在include/linux/init.h中,我们可以找到了它的定义:
/* Functions marked as __devexit may be discarded at kernel link time, depending
on config options. Newer versions of binutils detect references from
retained sections to discarded sections and flag an error. Pointers to
__devexit functions must use __devexit_p(function_name), the wrapper will
insert either the function_name or NULL, depending on the config options.
*/
#if defined(MODULE) || defined(CONFIG_HOTPLUG)
#define __devexit_p(x) x
#else
#define __devexit_p(x) NULL
#endif
__devexit_p宏在Linux驱动程序中用于决定函数指针指向实际函数还是空函数。这取决于编译配置选项,如果是模块则指向实际函数,如果是内核则为空函数。

998

被折叠的 条评论
为什么被折叠?



