Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

purpose of __devexit_p in driver files

Can anyone please tell me the purpose of __devexit_p part in driver files ?

I find __devexit_p is normally using with remove functions in the driver code

Example 1:

static struct i2c_driver lsm9ds0_driver = {
    .driver = {
        .owner = THIS_MODULE,
        .name = LSM9DS0_DEV_NAME,
    },
    .probe = lsm9ds0_probe,
    .remove = __devexit_p(lsm9ds0_remove),
    .id_table = lsm9ds0_id,
};

Example 2:

static struct spi_driver light_driver = {
    .driver = {
        .name = "light",
        .owner = THIS_MODULE,
    },
    .probe = light_probe,
    .remove = __devexit_p(light_remove),
};

Is there any difference if I removed __devexit_p from above examples? Will it affect the performance of the driver when __devexit_p removed?

like image 482
runner Avatar asked Sep 28 '22 05:09

runner


1 Answers

Based on this LXR listing from 2.6.32:

/*
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

it seems to be used to conditionally expand it to the given parameter or NULL based on the code being compiled as part of a kernel module (MODULE) and on the CONFIG_HOTPLUG kernel option.

like image 86
dragosht Avatar answered Nov 03 '22 20:11

dragosht