diff mbox series

module: silence warning about unused 'no_warn' variable

Message ID 20240322132014.906097-1-arnd@kernel.org (mailing list archive)
State New, archived
Headers show
Series module: silence warning about unused 'no_warn' variable | expand

Commit Message

Arnd Bergmann March 22, 2024, 1:20 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

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]

Add an explicit cast to void to prevent this check as well.

Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: linux-modules@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Fixes: e17e0f51aeea ("Driver core: show drivers in /sys/module/")
See-also: 4a7fb6363f2d ("add __must_check to device management code")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I'm not entirely sure what bug the __must_check on sysfs_create_link()
is trying to prevent, or why the module loader code is allowed to
ignore this. It would be nice to have an Ack from the sysfs maintainers
on this.
---
 drivers/base/module.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Greg Kroah-Hartman March 22, 2024, 1:47 p.m. UTC | #1
On Fri, Mar 22, 2024 at 02:20:05PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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]
> 
> Add an explicit cast to void to prevent this check as well.
> 
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: linux-modules@vger.kernel.org
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Fixes: e17e0f51aeea ("Driver core: show drivers in /sys/module/")
> See-also: 4a7fb6363f2d ("add __must_check to device management code")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> I'm not entirely sure what bug the __must_check on sysfs_create_link()
> is trying to prevent, or why the module loader code is allowed to
> ignore this. It would be nice to have an Ack from the sysfs maintainers
> on this.

No, let's fix this properly and unwind if we can't create the link.  You
are pointing at something from 2006, so I guess we always thought "this
can not fail" and never did anything about it since then.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/base/module.c b/drivers/base/module.c
index 46ad4d636731..0180dbcf2240 100644
--- a/drivers/base/module.c
+++ b/drivers/base/module.c
@@ -67,6 +67,8 @@  void module_add_driver(struct module *mod, struct device_driver *drv)
 					    driver_name);
 		kfree(driver_name);
 	}
+
+	(void)no_warn;
 }
 
 void module_remove_driver(struct device_driver *drv)