module: don't ignore sysfs_create_link() failures
PATCH v4 1/1 module: don't ignore sysfs_create_link() failures
From: Arnd Bergmann <[email protected]>
The sysfs_create_link() return code is marked as __must_check, but the module_add_driver() function tries hard to not care, by assigning the return code to a variable. When building with 'make W=1', gcc still warns because this variable is only assigned but not used:
drivers/base/module.c: In function 'module_add_driver':drivers/base/module.c:36:6: warning: variable 'no_warn' set but not used [-Wunused-but-set-variable]
Rework the code to properly unwind and return the error code to the caller. My reading of the original code was that it tries to not fail when the links already exist, so keep ignoring -EEXIST errors.
See-also: 4a7fb6363f2d ("add __must_check to device management code")
---
Luis, can you merge this through the modules-next tree?
---
v4: minor style changes, based on feedback from Andy Shevchenko
v3: make error handling stricter, add unwinding,
fix build fail with CONFIG_MODULES=n
v2: rework to actually handle the error. I have not tested the
error handling beyond build testing, so please review carefully.
--- drivers/base/base.h | 9 ++++++--- drivers/base/bus.c | 9 ++++++++- drivers/base/module.c | 42 +++++++++++++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 15 deletions(-)
drivers/base/base.h +6 -3
@@ -192,11 +192,14 @@ extern struct kset *devices_kset;void devices_kset_move_last (struct device *dev);#if defined(CONFIG_MODULES ) && defined(CONFIG_SYSFS ) -void module_add_driver (struct module *mod,struct device_driver *drv); +int module_add_driver (struct module *mod,struct device_driver *drv);void module_remove_driver (struct device_driver *drv);#else -static inline void module_add_driver (struct module *mod, -struct device_driver *drv) { } +static inline int module_add_driver (struct module *mod, +struct device_driver *drv) +{ +return 0 ; +}static inline void module_remove_driver (struct device_driver *drv) { }#endif
drivers/base/bus.c +8 -1
@@ -674,7 +674,12 @@ int bus_add_driver(struct device_driver *drv)if (error) goto out_del_list; } -module_add_driver (drv->owner, drv); + error =module_add_driver (drv->owner, drv); +if (error) { +printk (KERN_ERR "%s: failed to create module links for %s\n" , + __func__, drv->name); + goto out_detach; + } error =driver_create_file (drv, &driver_attr_uevent);if (error) {
@@ -699,6 +704,8 @@ int bus_add_driver(struct device_driver *drv)return 0 ; +out_detach: +driver_detach (drv); out_del_list:klist_del (&priv->knode_bus); out_unregister:
drivers/base/module.c +31 -11
62 lines not on this page · raw message
Signature · 1 line
2.39.2
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
sysfs_create_link()return code is marked as__must_check, but themodule_add_driver()function tries hard to not care, by assigning the return code to a variable. When building with 'make W=1', gcc still warns because this variable is only assigned but not used:
drivers/base/module.c: In function 'module_add_driver':drivers/base/module.c:36:6: warning: variable 'no_warn' set but not used [-Wunused-but-set-variable]
Quoted 7 lines
Rework the code to properly unwind and return the error code to the caller. My reading of the original code was that it tries to not fail when the links already exist, so keep ignoring
-EEXISTerrors.Fixes e17e0f51aeea ("Driver core: show drivers in /sys/module/")Reviewed-by Greg Kroah-Hartman <[email protected]>
Luis
Greg Kroah-Hartman
maintainerQuoted 16 lines · Luis Chamberlain
Quoted 15 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
sysfs_create_link()return code is marked as__must_check, but themodule_add_driver()function tries hard to not care, by assigning the return code to a variable. When building with 'make W=1', gcc still warns because this variable is only assigned but not used:
drivers/base/module.c: In function 'module_add_driver':drivers/base/module.c:36:6: warning: variable 'no_warn' set but not used [-Wunused-but-set-variable]Rework the code to properly unwind and return the error code to the caller. My reading of the original code was that it tries to not fail when the links already exist, so keep ignoring
-EEXISTerrors.
Quoted 4 lines
Quoted 2 lines
Fixes e17e0f51aeea ("Driver core: show drivers in /sys/module/")Reviewed-by Greg Kroah-Hartman <[email protected]>Reviewed-by Luis Chamberlain <[email protected]>
Oh right, I should apply this, sorry about that, will go do that now...