Re: [PATCH v2 1/4] hwmon: (asus-ec-sensors) introduce ec_board_info struct for board data

From: Guenter Roeck
Date: Wed Apr 27 2022 - 09:20:11 EST


On 4/27/22 05:16, Eugene Shalygin wrote:
Sorry, I don't follow that part. One can add "__init" or "__initdata",
as in

static struct platform_driver asus_ec_sensors_platform_driver __initdata = {

to mark a function or data structure as __init. I don't think adding
"_probe" to the struct platform_driver variable name does that.


__initdata leads to modpost warning:
WARNING: modpost: drivers/hwmon/asus-ec-sensors.o(.exit.text+0x3):
Section mismatch in reference from the function cleanup_module() to
the variable .init.data:asus_ec_sensors_platform_driver
The function __exit cleanup_module() references
a variable __initdata asus_ec_sensors_platform_driver.
This is often seen when error handling in the exit function
uses functionality in the init path.
The fix is often to remove the __initdata annotation of
asus_ec_sensors_platform_driver so it may be used outside an init section.

Compiling without attributes resulted in another message:
WARNING: modpost: drivers/hwmon/asus-ec-sensors.o(.data+0x0): Section
mismatch in reference from the variable
asus_ec_sensors_platform_driver to the function
.init.text:asus_ec_probe()
The variable asus_ec_sensors_platform_driver references
the function __init asus_ec_probe()
If the reference is valid then annotate the
variable with __init* or __refdata (see linux/init.h) or name the variable:
*_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console

Here is why I added the "_probe" suffix.

Eugene

Ah yes, I forgot about the exit function. It needs a pointer to
the structure, which would be gone if marked __initdata.
Please add a comment to the structure name explaining why
it is named _probe.

Thanks,
Guenter