Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: coreboot: store owner from modules with coreboot_driver_register()

Modules registering driver with coreboot_driver_register() might
forget to set .owner field. The field is used by some of other kernel
parts for reference counting (try_module_get()), so it is expected that
drivers will set it.

Solve the problem by moving this task away from the drivers to the core
code, just like we did for platform_driver in
commit 9447057eaff8 ("platform_device: use a macro instead of
platform_driver_register").

Moving the .owner setting code to the core this effectively fixes
missing .owner in framebuffer-coreboot, memconsole-coreboot and vpd
drivers.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240330-module-owner-coreboot-v1-1-ddba098b6dcf@linaro.org
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Tzung-Bi Shih
46c6685e 4cece764

+9 -3
+4 -2
drivers/firmware/google/coreboot_table.c
··· 85 85 kfree(device); 86 86 } 87 87 88 - int coreboot_driver_register(struct coreboot_driver *driver) 88 + int __coreboot_driver_register(struct coreboot_driver *driver, 89 + struct module *owner) 89 90 { 90 91 driver->drv.bus = &coreboot_bus_type; 92 + driver->drv.owner = owner; 91 93 92 94 return driver_register(&driver->drv); 93 95 } 94 - EXPORT_SYMBOL(coreboot_driver_register); 96 + EXPORT_SYMBOL(__coreboot_driver_register); 95 97 96 98 void coreboot_driver_unregister(struct coreboot_driver *driver) 97 99 {
+5 -1
drivers/firmware/google/coreboot_table.h
··· 97 97 const struct coreboot_device_id *id_table; 98 98 }; 99 99 100 + /* use a macro to avoid include chaining to get THIS_MODULE */ 101 + #define coreboot_driver_register(driver) \ 102 + __coreboot_driver_register(driver, THIS_MODULE) 100 103 /* Register a driver that uses the data from a coreboot table. */ 101 - int coreboot_driver_register(struct coreboot_driver *driver); 104 + int __coreboot_driver_register(struct coreboot_driver *driver, 105 + struct module *owner); 102 106 103 107 /* Unregister a driver that uses the data from a coreboot table. */ 104 108 void coreboot_driver_unregister(struct coreboot_driver *driver);