__devexit_p宏的功能

在驱动程序中,经常会在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(x)是一个宏定义,根据配置选项(编译为模块 or 编译到内核)来决定函数指针是括号里面的函数,还是空函数,即模块为x,内核则为NULL
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值