Skip to contentSkip to conversation

devcoredump: avoid -Wempty-body warnings

PATCH In review Arnd Bergmann 2 participants 4 messages Mar 22, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devcoredump: avoid -Wempty-body warnings

From: Arnd Bergmann <[email protected]>

Cleaning out the last -Wempty-body warnings found some interesting cases with empty macros, along with harmless warnings like this one:

drivers/base/devcoredump.c: In function 'dev_coredumpm':
drivers/base/devcoredump.c:297:56: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
297 | /* nothing - symlink will be missing */;
| ^
drivers/base/devcoredump.c:301:56: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
301 | /* nothing - symlink will be missing */;
| ^

Randy tried addressing this one before, and there were multiple other ideas in that thread.

Pick up the one that Matthew Wilcox suggested by adding a WARN_ON_ONCE() and a comment.

---
 drivers/base/devcoredump.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/base/devcoredump.c +9 -6
index 9243468e2c99..88e0d931439e 100644
@@ -292,13 +292,16 @@ void dev_coredumpm(struct device *dev, struct module *owner,
 	if (device_add(&devcd->devcd_dev))
 		goto put_device;
 
-	if (sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
-			      "failing_device"))
-		/* nothing - symlink will be missing */;
+	/*
+	 * These should normally not fail, but there is no problem
+	 * continuing without the links, so just warn instead of
+	 * failing.
+	 */
+	WARN_ON_ONCE(sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
+				       "failing_device"));
 
-	if (sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
-			      "devcoredump"))
-		/* nothing - symlink will be missing */;
+	WARN_ON_ONCE(sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
+				       "devcoredump"));
 
 	INIT_DELAYED_WORK(&devcd->del_wk, devcd_del);
 	schedule_delayed_work(&devcd->del_wk, DEVCD_TIMEOUT);
Signature · 1 line
2.29.2
#1 lore raw
Quoted 41 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Cleaning out the last -Wempty-body warnings found some interesting cases with empty macros, along with harmless warnings like this one:

drivers/base/devcoredump.c: In function 'dev_coredumpm':
drivers/base/devcoredump.c:297:56: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
297 | /* nothing - symlink will be missing */;
| ^
drivers/base/devcoredump.c:301:56: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
301 | /* nothing - symlink will be missing */;
| ^

Randy tried addressing this one before, and there were multiple other ideas in that thread.

Pick up the one that Matthew Wilcox suggested by adding a WARN_ON_ONCE() and a comment.

---
 drivers/base/devcoredump.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/base/devcoredump.c +3 -3
index 9243468e2c99..88e0d931439e 100644
@@ -292,13 +292,16 @@ void dev_coredumpm(struct device *dev, struct module *owner,
 	if (device_add(&devcd->devcd_dev))
 		goto put_device;
 
-	if (sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
-			      "failing_device"))
-		/* nothing - symlink will be missing */;
+	/*
+	 * These should normally not fail, but there is no problem
+	 * continuing without the links, so just warn instead of

drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, struct module *owner, · line 304

Quoted 10 lines
drivers/base/devcoredump.c +6 -3
+	 * failing.
+	 */
+	WARN_ON_ONCE(sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
+				       "failing_device"));
 
-	if (sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
-			      "devcoredump"))
-		/* nothing - symlink will be missing */;
+	WARN_ON_ONCE(sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
+				       "devcoredump"));

We do not want to reboot machines that have panic-on-warn set, so if this really needs a trace dump, please do that instead...

thanks,

greg k-h

#2 lore raw
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

drivers/base/devcoredump.c +6 -0
+      * These should normally not fail, but there is no problem
+      * continuing without the links, so just warn instead of
+      * failing.
+      */
+     WARN_ON_ONCE(sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
+                                    "failing_device"));
Quoted 7 lines

drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, struct module *owner, · line 304

Quoted 5 lines
drivers/base/devcoredump.c +2 -3
-     if (sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
-                           "devcoredump"))
-             /* nothing - symlink will be missing */;
+     WARN_ON_ONCE(sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
+                                    "devcoredump"));

We do not want to reboot machines that have panic-on-warn set,

Fair enough.

Quoted 1 line

so if this really needs a trace dump, please do that instead...

I don't think the backtrace is needed here, if it ever happens it's either going to be -ENOMEM or completely reproducible. I can instead do the cast to (void) that Linus suggested, or a simple if(...) dev_warn() or dev_warn_once() to have some indication of the failure.

Arnd

#3 lore raw
Quoted 19 lines · Arnd Bergmann
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

drivers/base/devcoredump.c +6 -0
+      * These should normally not fail, but there is no problem
+      * continuing without the links, so just warn instead of
+      * failing.
+      */
+     WARN_ON_ONCE(sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
+                                    "failing_device"));
Quoted 7 lines

drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, struct module *owner, · line 304

Quoted 5 lines
drivers/base/devcoredump.c +2 -3
-     if (sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
-                           "devcoredump"))
-             /* nothing - symlink will be missing */;
+     WARN_ON_ONCE(sysfs_create_link(&dev->kobj, &devcd->devcd_dev.kobj,
+                                    "devcoredump"));

We do not want to reboot machines that have panic-on-warn set,

Quoted 8 lines

Fair enough.

Quoted 1 line

so if this really needs a trace dump, please do that instead...

I don't think the backtrace is needed here, if it ever happens it's either going to be -ENOMEM or completely reproducible. I can instead do the cast to (void) that Linus suggested, or a simple if(...) dev_warn() or dev_warn_once() to have some indication of the failure.

dev_warn() should be fine I think.

thanks,

greg k-h