fix -Wempty-body build warnings
cover fix -Wempty-body build warnings
Hi,
When -Wextra is used, gcc emits many warnings about an empty 'if' or 'else' body, like this:
../fs/posix_acl.c: In function ‘get_acl’:../fs/posix_acl.c:127:22: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
/* fall through */ ;
^To quieten these warnings, add a new macro "do_empty()". I originally wanted to use do_nothing(), but that's already in use.
It would sorta be nice if "fallthrough" could be coerced for this instead of using something like do_empty().
Or should we just use "{}" in place of ";"?
This causes some odd coding style issue IMO. E.g., see this change:
original:
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)
/* fall through */ ;
with new macro:
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)
do_empty(); /* fall through */
using {}:
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)
{} /* fall through */
or
{ /* fall through */ }
or even
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED) {
/* fall through */ }
or
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED) {
} /* fall through */drivers/base/devcoredump.c | 5 +++-- drivers/dax/bus.c | 5 +++-- drivers/input/mouse/synaptics.c | 3 ++- drivers/target/target_core_pscsi.c | 3 ++- drivers/usb/core/sysfs.c | 2 +- fs/nfsd/nfs4state.c | 3 ++- fs/posix_acl.c | 2 +- include/linux/kernel.h | 8 ++++++++ sound/drivers/vx/vx_core.c | 3 ++- 9 files changed, 24 insertions(+), 10 deletions(-)
RFC PATCH 1/9 kernel.h: add do_empty() macro
Add the do_empty() macro to silence gcc warnings about an empty body following an "if" statement when -Wextra is used.
However, for debug printk calls that are being disabled, use either no_printk() or pr_debug() [and optionally dynamic printk debugging] instead.
--- include/linux/kernel.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/kernel.h +8 -0
@@ -40,6 +40,14 @@#define READ 0#define WRITE 1 +/* +* When using -Wextra, an "if" statement followed by an empty block +* (containing only a ';'), produces a warning from gcc: +* warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] +* Replace the empty body with do_empty() to silence this warning. +*/ +#define do_empty () do { } while (0) +/** * ARRAY_SIZE - get the number of elements in array @arr * @arr: array to be sized
Re: [RFC PATCH 1/9] kernel.h: add do_empty() macro
Quoted 6 lines · Randy Dunlap
Add the
do_empty()macro to silence gcc warnings about an empty body following an "if" statement when -Wextra is used.However, for debug printk calls that are being disabled, use either
no_printk()orpr_debug()[and optionally dynamic printk debugging] instead.
[]
Quoted 1 line
+#define
do_empty()do { } while (0)
If this is really useful
(I think the warning is somewhat silly)
bikeshed:
I think do_nothing() is more descriptive
Re: [RFC PATCH 1/9] kernel.h: add do_empty() macro
Quoted 8 lines · Joe Perches
Quoted 6 lines · Randy Dunlap
Add the
do_empty()macro to silence gcc warnings about an empty body following an "if" statement when -Wextra is used.However, for debug printk calls that are being disabled, use either
no_printk()orpr_debug()[and optionally dynamic printk debugging] instead.[]
Quoted 8 lines
Quoted 1 line
+#define
do_empty()do { } while (0)If this is really useful
(I think the warning is somewhat silly)bikeshed:
I think
do_nothing()is more descriptive
Yes, I do too, as I more or less mentioned in the cover letter.
Signature · 1 line
~Randy
Re: [RFC PATCH 1/9] kernel.h: add do_empty() macro
In reply to Randy DunlapQuoted 7 lines · Randy Dunlap
include/linux/kernel.h +1
-0@@ -40,6 +40,14 @@#define READ 0#define WRITE 1 +/*
include/linux/kernel.h line 53
Quoted 10 lines
include/linux/kernel.h +7
-0+* When using -Wextra, an "if" statement followed by an empty block +* (containing only a ';'), produces a warning from gcc: +* warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] +* Replace the empty body with do_empty() to silence this warning. +*/ +#define do_empty () do { } while (0) +/** * ARRAY_SIZE - get the number of elements in array @arr * @arr: array to be sized
I'm less than enthusiast about introducing a new macro to suppress "empty body" warnings. Anyone who encounters code in which this macro is used will have to look up the definition of this macro to learn what it does. Has it been considered to suppress empty body warnings by changing the empty bodies from ";" into "{}"?
Thanks,
Bart.
Re: [RFC PATCH 1/9] kernel.h: add do_empty() macro
Quoted 11 lines · Bart Van Assche
Quoted 10 lines · Randy Dunlap
include/linux/kernel.h +0
-0@@ -40,6 +40,14 @@ #define READ 0 #define WRITE 1+/*
+ * When using -Wextra, an "if" statement followed by an empty block
+ * (containing only a ';'), produces a warning from gcc:
+ * warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
+ * Replace the empty body withdo_empty()to silence this warning.
Quoted 8 lines
Quoted 6 lines
+ */
include/linux/kernel.h +2
-0+#define do_empty () do { } while (0) +/**
*ARRAY_SIZE- get the number of elements in array @arr
* @arr: array to be sizedI'm less than enthusiast about introducing a new macro to suppress "empty body" warnings. Anyone who encounters code in which this macro is used will have to look up the definition of this macro to learn what it does. Has it been considered to suppress empty body warnings by changing the empty bodies from ";" into "{}"?
I mentioned that possibility in PATCH 0/9 (cover letter)... which should have been RFC PATCH 0/9.
So yes, it is possible.
You are the only other person who has mentioned it.
thanks.
Signature · 1 line
~Randy
PATCH 2/9 fs: fix empty-body warning in posix_acl.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../fs/posix_acl.c: In function ‘get_acl’:../fs/posix_acl.c:127:22: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
/* fall through */ ;
^--- fs/posix_acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/posix_acl.c +1 -1
@@ -124,7 +124,7 @@ struct posix_acl *get_acl(struct inode ** be an unlikely race.) */ if (cmpxchg (p,ACL_NOT_CACHED , sentinel) !=ACL_NOT_CACHED ) -/* fall through */ ; +do_empty ();/* fall through */ /* * Normally, the ACL returned by ->get_acl will be cached.
Re: [PATCH 2/9] fs: fix empty-body warning in posix_acl.c
Quoted 2 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
Please don't do this.
First off, "do_empty()" adds nothing but confusion. Now it syntactically looks like it does something, and it's a new pattern to everybody. I've never seen it before.
Secondly, even if we were to do this, then the patch would be wrong:
fs/posix_acl.c struct posix_acl *get_acl(struct inode * · line 127
Quoted 3 lines
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)fs/posix_acl.c +1
-1-/* fall through */ ; +do_empty ();/* fall through */
That comment made little sense before, but it makes _no_ sense now.
What fall-through? I'm guessing it meant to say "nothing", and somebody was confused. With "do_empty()", it's even more confusing.
Thirdly, there's a *reason* why "-Wextra" isn't used.
The warnings enabled by -Wextra are usually complete garbage, and trying to fix them often makes the code worse. Exactly like here.
Linus
Re: [PATCH 2/9] fs: fix empty-body warning in posix_acl.c
Quoted 18 lines · Linus Torvalds
Quoted 2 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
Please don't do this.
First off, "
do_empty()" adds nothing but confusion. Now it syntactically looks like it does something, and it's a new pattern to everybody. I've never seen it before.Secondly, even if we were to do this, then the patch would be wrong:
fs/posix_acl.c struct posix_acl *get_acl(struct inode * · line 127
Quoted 3 lines
if (cmpxchg(p, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)fs/posix_acl.c +1
-1-/* fall through */ ; +do_empty ();/* fall through */ That comment made little sense before, but it makes _no_ sense now.
Quoted 7 lines
What fall-through? I'm guessing it meant to say "nothing", and somebody was confused. With "
do_empty()", it's even more confusing.Thirdly, there's a *reason* why "-Wextra" isn't used.
The warnings enabled by -Wextra are usually complete garbage, and trying to fix them often makes the code worse. Exactly like here.
OK, no problem. That's why PATCH 0/9 says RFC.
Oops. Crap. It was *supposed* to say RFC. :(
Signature · 1 line
~Randy
Re: [PATCH 2/9] fix empty-body warning in posix_acl.c
In reply to Linus TorvaldsQuoted 8 lines · Linus Torvalds
Thirdly, there's a *reason* why "-Wextra" isn't used.
The warnings enabled by -Wextra are usually complete garbage, and trying to fix them often makes the code worse. Exactly like here.
As the instigator of this warning cleanup activity, even _I_ don’t recommend building with all of -Wextra. Doing so on an allmodconfig build generates 500 megabytes of warning text (not exaggerating), primarily due to -Wunused-parameter and Wmissing-field-initializers.
I strongly recommend disabling them with -Wno-unused-parameter -Wno-missing-field-initializers since the spew is completely unactionable.
On the other hand, -Woverride-init found a legit bug that was breaking DVD drives, fixed in commit 03264ddde2453f6877a7d637d84068079632a3c5.
I believe finding a good set of compiler warning settings can lead to lots of good bugs being spotted and (hopefully) fixed. Why let syzbot do all the work?
zzy
PATCH 3/9 input: fix empty-body warning in synaptics.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../drivers/input/mouse/synaptics.c: In function ‘synaptics_process_packet’:../drivers/input/mouse/synaptics.c:1106:6: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
; /* Nothing, treat a pen as a single finger */
^
--- drivers/input/mouse/synaptics.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/mouse/synaptics.c +2 -1
@@ -20,6 +20,7 @@* Trademarks are the property of their respective owners. */ +#include <linux/kernel.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/dmi.h>
@@ -1103,7 +1104,7 @@ static void synaptics_process_packet(strbreak ;case 2 :if (SYN_MODEL_PEN (info->model_id)) - ;/* Nothing, treat a pen as a single finger */ +do_empty ();/* Nothing, treat a pen as a single finger */ break ; case 4 ... 15:if (SYN_CAP_PALMDETECT (info->capabilities))
PATCH 4/9 sound: fix empty-body warning in vx_core.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../sound/drivers/vx/vx_core.c:515:3: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
--- sound/drivers/vx/vx_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/drivers/vx/vx_core.c +2 -1
@@ -13,6 +13,7 @@#include <linux/init.h> #include <linux/device.h> #include <linux/firmware.h> +#include <linux/kernel.h> #include <linux/module.h> #include <linux/io.h> #include <sound/core.h>
@@ -512,7 +513,7 @@ irqreturn_t snd_vx_threaded_irq_handler(* received by the board is equal to one of those given to it). */ if (events &TIME_CODE_EVENT_PENDING ) - ;/* so far, nothing to do yet */ +do_empty ();/* so far, nothing to do yet */ /* The frequency has changed on the board (UER mode). */ if (events &FREQUENCY_CHANGE_EVENT_PENDING )
PATCH 5/9 usb: fix empty-body warning in sysfs.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../drivers/usb/core/sysfs.c: In function ‘usb_create_sysfs_intf_files’:../drivers/usb/core/sysfs.c:1266:3: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
; /* We don't actually care if the function fails. */
^
--- drivers/usb/core/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/sysfs.c +1 -1
@@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(structif (!alt->string && !(udev->quirks &USB_QUIRK_CONFIG_INTF_STRINGS )) alt->string =usb_cache_string (udev, alt->desc.iInterface);if (alt->string &&device_create_file (&intf->dev, &dev_attr_interface)) - ;/* We don't actually care if the function fails. */ +do_empty ();/* We don't actually care if the function fails. */ intf->sysfs_files_created =1 ; }
Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c
drivers/usb/core/sysfs.c void usb_create_sysfs_intf_files(struct · line 1268
Quoted 9 lines · Randy Dunlap
+++
linux-next-20200327/drivers/usb/core/sysfs.cdrivers/usb/core/sysfs.c +1
-1@@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(structif (!alt->string && !(udev->quirks &USB_QUIRK_CONFIG_INTF_STRINGS )) alt->string =usb_cache_string (udev, alt->desc.iInterface);if (alt->string &&device_create_file (&intf->dev, &dev_attr_interface)) - ;/* We don't actually care if the function fails. */ +do_empty ();/* We don't actually care if the function fails. */ intf->sysfs_files_created =1 ; }
Why not just?
+ if (alt->string)
+ device_create_file(&intf->dev, &dev_attr_interface);
Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c
Quoted 14 lines · Matthew Wilcox
drivers/usb/core/sysfs.c void usb_create_sysfs_intf_files(struct · line 1268
Quoted 9 lines · Randy Dunlap
+++
linux-next-20200327/drivers/usb/core/sysfs.cdrivers/usb/core/sysfs.c +1
-1@@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(structif (!alt->string && !(udev->quirks &USB_QUIRK_CONFIG_INTF_STRINGS )) alt->string =usb_cache_string (udev, alt->desc.iInterface);if (alt->string &&device_create_file (&intf->dev, &dev_attr_interface)) - ;/* We don't actually care if the function fails. */ +do_empty ();/* We don't actually care if the function fails. */ intf->sysfs_files_created =1 ; }Why not just?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (alt->string) + device_create_file(&intf->dev, &dev_attr_interface);
Yes, looks good. Thanks.
Signature · 1 line
~Randy
Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c
In reply to Matthew WilcoxQuoted 13 lines · Matthew Wilcox
drivers/usb/core/sysfs.c void usb_create_sysfs_intf_files(struct · line 1268
Quoted 9 lines · Randy Dunlap
+++
linux-next-20200327/drivers/usb/core/sysfs.cdrivers/usb/core/sysfs.c +1
-1@@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(structif (!alt->string && !(udev->quirks &USB_QUIRK_CONFIG_INTF_STRINGS )) alt->string =usb_cache_string (udev, alt->desc.iInterface);if (alt->string &&device_create_file (&intf->dev, &dev_attr_interface)) - ;/* We don't actually care if the function fails. */ +do_empty ();/* We don't actually care if the function fails. */ intf->sysfs_files_created =1 ; }Why not just?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (alt->string) + device_create_file(&intf->dev, &dev_attr_interface);
This is another __must_check function call.
The reason we don't care if the call fails is because the file being created holds the USB interface string descriptor, something which is purely informational and hardly ever gets set (and no doubt gets used even less often).
Is this another situation where the comment should be expanded and the code modified to include a useless test and cast-to-void?
Or should device_create_file() not be __must_check after all?
Greg?
Alan Stern
Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c
Quoted 25 lines · Alan Stern
Quoted 13 lines · Matthew Wilcox
drivers/usb/core/sysfs.c void usb_create_sysfs_intf_files(struct · line 1268
Quoted 9 lines · Randy Dunlap
+++
linux-next-20200327/drivers/usb/core/sysfs.cdrivers/usb/core/sysfs.c +1
-1@@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(structif (!alt->string && !(udev->quirks &USB_QUIRK_CONFIG_INTF_STRINGS )) alt->string =usb_cache_string (udev, alt->desc.iInterface);if (alt->string &&device_create_file (&intf->dev, &dev_attr_interface)) - ;/* We don't actually care if the function fails. */ +do_empty ();/* We don't actually care if the function fails. */ intf->sysfs_files_created =1 ; }Why not just?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (alt->string) + device_create_file(&intf->dev, &dev_attr_interface);This is another
__must_checkfunction call.The reason we don't care if the call fails is because the file being created holds the USB interface string descriptor, something which is purely informational and hardly ever gets set (and no doubt gets used even less often).
Quoted 4 lines
Is this another situation where the comment should be expanded and the code modified to include a useless test and cast-to-void?
Or should
device_create_file()not be__must_checkafter all?
One approach to dealing with __must_check function that you don't want to check is to cause failure to call
pr_debug("usb: interface descriptor file not created");
or similar. It silences the compiler, serves as documentation, and creates a message that is almost certainly never seen.
This is what I did in drivers/md/md.c...
if (mddev->kobj.sd &&
sysfs_create_group(&mddev->kobj, &md_bitmap_group))
pr_debug("pointless warning\n");(I give better warnings elsewhere - I must have run out of patience by
this point).
NeilBrown
Re: [PATCH 5/9] usb: fix empty-body warning in sysfs.c
Quoted 38 lines · NeilBrown
Quoted 25 lines · Alan Stern
Quoted 13 lines · Matthew Wilcox
drivers/usb/core/sysfs.c void usb_create_sysfs_intf_files(struct · line 1268
Quoted 9 lines · Randy Dunlap
+++
linux-next-20200327/drivers/usb/core/sysfs.cdrivers/usb/core/sysfs.c +1
-1@@ -1263,7 +1263,7 @@ void usb_create_sysfs_intf_files(structif (!alt->string && !(udev->quirks &USB_QUIRK_CONFIG_INTF_STRINGS )) alt->string =usb_cache_string (udev, alt->desc.iInterface);if (alt->string &&device_create_file (&intf->dev, &dev_attr_interface)) - ;/* We don't actually care if the function fails. */ +do_empty ();/* We don't actually care if the function fails. */ intf->sysfs_files_created =1 ; }Why not just?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (alt->string) + device_create_file(&intf->dev, &dev_attr_interface);This is another
__must_checkfunction call.The reason we don't care if the call fails is because the file being created holds the USB interface string descriptor, something which is purely informational and hardly ever gets set (and no doubt gets used even less often).
Quoted 4 lines
Is this another situation where the comment should be expanded and the code modified to include a useless test and cast-to-void?
Or should
device_create_file()not be__must_checkafter all?One approach to dealing with
__must_checkfunction that you don't want to check is to cause failure to call
pr_debug("usb: interface descriptor file not created");
or similar. It silences the compiler, serves as documentation, and creates a message that is almost certainly never seen.
Quoted 8 lines
This is what I did in
drivers/md/md.c...if (mddev->kobj.sd && sysfs_create_group(&mddev->kobj, &md_bitmap_group)) pr_debug("pointless warning\n");(I give better warnings elsewhere - I must have run out of patience by
this point).
That's a decent idea. I'll do something along those lines.
Alan Stern
PATCH 6/9 nfsd: fix empty-body warning in nfs4state.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
--- fs/nfsd/nfs4state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfsd/nfs4state.c +2 -1
@@ -34,6 +34,7 @@#include <linux/file.h> #include <linux/fs.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h>
@@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty (); new->cl_minorversion =0 ;gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
Quoted 14 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]Signed-off-by Randy Dunlap <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Chuck Lever <[email protected]>
I have a patch in my queue that addresses this particular warning, but your change works for me too.
Unless Bruce objects.
Quoted 15 lines
---
fs/nfsd/nfs4state.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +1
-0@@ -34,6 +34,7 @@#include <linux/file.h> #include <linux/fs.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h>
fs/nfsd/nfs4state.c nfsd4_setclientid(struct svc_rqst *rqstp · line 3902
Quoted 8 lines
fs/nfsd/nfs4state.c +1
-1@@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty (); new->cl_minorversion =0 ;gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);
--
Chuck Lever
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
Quoted 29 lines · Chuck Lever
Quoted 12 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]Signed-off-by Randy Dunlap <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Chuck Lever <[email protected]>I have a patch in my queue that addresses this particular warning, but your change works for me too.
Acked-by Chuck Lever <[email protected]>Unless Bruce objects.
Quoted 8 lines
---
fs/nfsd/nfs4state.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0@@ -34,6 +34,7 @@
Quoted 15 lines
Quoted 7 lines
fs/nfsd/nfs4state.c +1
-0#include <linux/file.h> #include <linux/fs.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h> fs/nfsd/nfs4state.c nfsd4_setclientid(struct svc_rqst *rqstp · line 3902
Quoted 8 lines
fs/nfsd/nfs4state.c +1
-1@@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty (); new->cl_minorversion =0 ;gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);
This empty else seems silly and could likely be better handled by a comment above the first if, something like:
/* for now only handle case 1: probable callback update */
if (conf && same_verf(&conf->cl_verifier, &clverifier)) {
copy_clid(new, conf);
gen_confirm(new, nn);
}with no else use.
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
Quoted 49 lines · Joe Perches
Quoted 29 lines · Chuck Lever
Quoted 12 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]Signed-off-by Randy Dunlap <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Chuck Lever <[email protected]>I have a patch in my queue that addresses this particular warning, but your change works for me too.
Acked-by Chuck Lever <[email protected]>Unless Bruce objects.
Quoted 8 lines
---
fs/nfsd/nfs4state.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0@@ -34,6 +34,7 @@Quoted 15 lines
Quoted 7 lines
fs/nfsd/nfs4state.c +1
-0#include <linux/file.h> #include <linux/fs.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h> fs/nfsd/nfs4state.c nfsd4_setclientid(struct svc_rqst *rqstp · line 3902
Quoted 8 lines
fs/nfsd/nfs4state.c +1
-1@@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty (); new->cl_minorversion =0 ;gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);This empty else seems silly and could likely be better handled by a comment above the first if, something like:
Quoted 7 lines
/* for now only handle case 1: probable callback update */ if (conf && same_verf(&conf->cl_verifier, &clverifier)) { copy_clid(new, conf); gen_confirm(new, nn); }with no else use.
I'll just let Chuck handle it with his current patch, whatever it is.
thanks.
Signature · 1 line
~Randy
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
In reply to Chuck LeverT24gU2F0LCAyMDIwLTA0LTE4IGF0IDE0OjQ1IC0wNDAwLCBDaHVjayBMZXZlciB3cm90ZToNCj4g PiBPbiBBcHIgMTgsIDIwMjAsIGF0IDI6NDEgUE0sIFJhbmR5IER1bmxhcCA8cmR1bmxhcEBpbmZy YWRlYWQub3JnPg0KPiA+IHdyb3RlOg0KPiA+IA0KPiA+IEZpeCBnY2MgZW1wdHktYm9keSB3YXJu aW5nIHdoZW4gLVdleHRyYSBpcyB1c2VkOg0KPiA+IA0KPiA+IC4uL2ZzL25mc2QvbmZzNHN0YXRl LmM6Mzg5ODozOiB3YXJuaW5nOiBzdWdnZXN0IGJyYWNlcyBhcm91bmQgZW1wdHkNCj4gPiBib2R5 IGluIGFuIOKAmGVsc2XigJkgc3RhdGVtZW50IFstV2VtcHR5LWJvZHldDQo+ID4gDQo+ID4gU2ln bmVkLW9mZi1ieTogUmFuZHkgRHVubGFwIDxyZHVubGFwQGluZnJhZGVhZC5vcmc+DQo+ID4gQ2M6 IExpbnVzIFRvcnZhbGRzIDx0b3J2YWxkc0BsaW51eC1mb3VuZGF0aW9uLm9yZz4NCj4gPiBDYzog QW5kcmV3IE1vcnRvbiA8YWtwbUBsaW51eC1mb3VuZGF0aW9uLm9yZz4NCj4gPiBDYzogIkouIEJy dWNlIEZpZWxkcyIgPGJmaWVsZHNAZmllbGRzZXMub3JnPg0KPiA+IENjOiBDaHVjayBMZXZlciA8 Y2h1Y2subGV2ZXJAb3JhY2xlLmNvbT4NCj4gPiBDYzogbGludXgtbmZzQHZnZXIua2VybmVsLm9y Zw0KPiANCj4gSSBoYXZlIGEgcGF0Y2ggaW4gbXkgcXVldWUgdGhhdCBhZGRyZXNzZXMgdGhpcyBw YXJ0aWN1bGFyIHdhcm5pbmcsDQo+IGJ1dCB5b3VyIGNoYW5nZSB3b3JrcyBmb3IgbWUgdG9vLg0K PiANCj4gQWNrZWQtYnk6IENodWNrIExldmVyIDxjaHVjay5sZXZlckBvcmFjbGUuY29tPg0KPiAN Cj4gVW5sZXNzIEJydWNlIG9iamVjdHMuDQo+IA0KPiANCj4gPiAtLS0NCj4gPiBmcy9uZnNkL25m czRzdGF0ZS5jIHwgICAgMyArKy0NCj4gPiAxIGZpbGUgY2hhbmdlZCwgMiBpbnNlcnRpb25zKCsp LCAxIGRlbGV0aW9uKC0pDQo+ID4gDQo+ID4gLS0tIGxpbnV4LW5leHQtMjAyMDA0MTcub3JpZy9m cy9uZnNkL25mczRzdGF0ZS5jDQo+ID4gKysrIGxpbnV4LW5leHQtMjAyMDA0MTcvZnMvbmZzZC9u ZnM0c3RhdGUuYw0KPiA+IEBAIC0zNCw2ICszNCw3IEBADQo+ID4gDQo+ID4gI2luY2x1ZGUgPGxp bnV4L2ZpbGUuaD4NCj4gPiAjaW5jbHVkZSA8bGludXgvZnMuaD4NCj4gPiArI2luY2x1ZGUgPGxp bnV4L2tlcm5lbC5oPg0KPiA+ICNpbmNsdWRlIDxsaW51eC9zbGFiLmg+DQo+ID4gI2luY2x1ZGUg PGxpbnV4L25hbWVpLmg+DQo+ID4gI2luY2x1ZGUgPGxpbnV4L3N3YXAuaD4NCj4gPiBAQCAtMzg5 NSw3ICszODk2LDcgQEAgbmZzZDRfc2V0Y2xpZW50aWQoc3RydWN0IHN2Y19ycXN0ICpycXN0cA0K PiA+IAkJY29weV9jbGlkKG5ldywgY29uZik7DQo+ID4gCQlnZW5fY29uZmlybShuZXcsIG5uKTsN Cj4gPiAJfSBlbHNlIC8qIGNhc2UgNCAobmV3IGNsaWVudCkgb3IgY2FzZXMgMiwgMyAoY2xpZW50 IHJlYm9vdCk6ICovDQo+ID4gLQkJOw0KPiA+ICsJCWRvX2VtcHR5KCk7DQoNClVyZ2guLi4gVGhp cyBpcyBqdXN0IGZvciBkb2N1bWVudGF0aW9uIHB1cnBvc2VzIGFueXdheSwgc28gd2h5IG5vdCBq dXN0DQp0dXJuIGl0IGFsbCBpbnRvIGEgY29tbWVudCBieSBtb3ZpbmcgdGhlICdlbHNlJyBpbnRv IHRoZSBjb21tZW50IGZpZWxkPw0KDQppLmUuDQoJfSAvKiBlbHNlIGNhc2UgNCAoLi4uLiAqLw0K DQoJbmV3LT5jbF9taW5vcnZlcnNpb24gPSAwOw0KPiA+IAlnZW5fY2FsbGJhY2sobmV3LCBzZXRj bGlkLCBycXN0cCk7DQo+ID4gCWFkZF90b191bmNvbmZpcm1lZChuZXcpOw0KPiANCj4gLS0NCj4g Q2h1Y2sgTGV2ZXINCj4gDQo+IA0KDQotLSANClRyb25kIE15a2xlYnVzdA0KTGludXggTkZTIGNs aWVudCBtYWludGFpbmVyLCBIYW1tZXJzcGFjZQ0KdHJvbmQubXlrbGVidXN0QGhhbW1lcnNwYWNl LmNvbQ0KDQoNCg=
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
Quoted 48 lines · Trond Myklebust
Quoted 31 lines · Chuck Lever
Quoted 8 lines
On Apr 18, 2020, at 2:41 PM, Randy Dunlap <[email protected]> wrote:
Fix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]Quoted 6 lines
Signed-off-by Randy Dunlap <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Chuck Lever <[email protected]>I have a patch in my queue that addresses this particular warning, but your change works for me too.
Acked-by Chuck Lever <[email protected]>Unless Bruce objects.
Quoted 8 lines
---
fs/nfsd/nfs4state.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0@@ -34,6 +34,7 @@Quoted 12 lines
fs/nfsd/nfs4state.c nfsd4_setclientid(struct svc_rqst *rqstp · line 3899
Quoted 12 lines
fs/nfsd/nfs4state.c +2
-1#include <linux/file.h> #include <linux/fs.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h> @@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty ();Urgh... This is just for documentation purposes anyway, so why not just turn it all into a comment by moving the 'else' into the comment field?
Quoted 6 lines
i.e.
} /* else case 4 (.... */ new->cl_minorversion = 0;Quoted 2 lines
Quoted 2 lines
fs/nfsd/nfs4state.c +0
-0gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);
Like I said earlier, since Chuck has a patch that addresses this, let's just go with that.
thanks.
Signature · 1 line
~Randy
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
Quoted 56 lines · Randy Dunlap
Quoted 51 lines · Trond Myklebust
Quoted 31 lines · Chuck Lever
Quoted 8 lines
On Apr 18, 2020, at 2:41 PM, Randy Dunlap <[email protected]> wrote:
Fix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]Quoted 6 lines
Signed-off-by Randy Dunlap <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Chuck Lever <[email protected]>I have a patch in my queue that addresses this particular warning, but your change works for me too.
Acked-by Chuck Lever <[email protected]>Unless Bruce objects.
Quoted 8 lines
---
fs/nfsd/nfs4state.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0@@ -34,6 +34,7 @@Quoted 12 lines
fs/nfsd/nfs4state.c nfsd4_setclientid(struct svc_rqst *rqstp · line 3899
Quoted 12 lines
fs/nfsd/nfs4state.c +2
-1#include <linux/file.h> #include <linux/fs.h> +#include <linux/kernel.h> #include <linux/slab.h> #include <linux/namei.h> #include <linux/swap.h> @@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty ();Urgh... This is just for documentation purposes anyway, so why not just turn it all into a comment by moving the 'else' into the comment field?
i.e.
} /* else case 4 (.... */
Quoted 6 lines
Quoted 3 lines
new->cl_minorversion = 0;Quoted 2 lines
Quoted 2 lines
fs/nfsd/nfs4state.c +0
-0gen_callback (new, setclid, rqstp);add_to_unconfirmed (new);Like I said earlier, since Chuck has a patch that addresses this, let's just go with that.
I'll post that patch for review as part of my NFSD for-5.8 patches.
--
Chuck Lever
Re: [PATCH 6/9] nfsd: fix empty-body warning in nfs4state.c
In reply to Randy DunlapHello!
Quoted 16 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
../fs/nfsd/nfs4state.c:3898:3: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]Signed-off-by Randy Dunlap <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Chuck Lever <[email protected]>--- fs/nfsd/nfs4state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/nfsd/nfs4state.c +0
-0
[...]
fs/nfsd/nfs4state.c nfsd4_setclientid(struct svc_rqst *rqstp · line 3899
Quoted 6 lines
fs/nfsd/nfs4state.c +1
-1@@ -3895,7 +3896,7 @@ nfsd4_setclientid(struct svc_rqst *rqstpcopy_clid (new, conf);gen_confirm (new, nn); }else /* case 4 (new client) or cases 2, 3 (client reboot): */ - ; +do_empty ();
In this case explicit {} would probably have been better, as described inDocumentation/process/coding-style.rst, clause (3).
MBR, Sergei
PATCH 7/9 drivers/base: fix empty-body warnings in devcoredump.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../drivers/base/devcoredump.c:297:42: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] ../drivers/base/devcoredump.c:301:42: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
--- drivers/base/devcoredump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/base/devcoredump.c +3 -2
@@ -9,6 +9,7 @@* * Author: Johannes Berg <[email protected]> */ +#include <linux/kernel.h> #include <linux/module.h> #include <linux/device.h> #include <linux/devcoredump.h>
@@ -294,11 +295,11 @@ void dev_coredumpm(struct device *dev, sif (sysfs_create_link (&devcd->devcd_dev.kobj, &dev->kobj,"failing_device" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ if (sysfs_create_link (&dev->kobj, &devcd->devcd_dev.kobj,"devcoredump" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ INIT_DELAYED_WORK (&devcd->del_wk, devcd_del);schedule_delayed_work (&devcd->del_wk,DEVCD_TIMEOUT );
Re: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 4 lines · Randy Dunlap
drivers/base/devcoredump.c +0
-0@@ -294,11 +295,11 @@ void dev_coredumpm(struct device *dev, sif (sysfs_create_link (&devcd->devcd_dev.kobj, &dev->kobj,"failing_device" ))
drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, s · line 305
Quoted 10 lines
drivers/base/devcoredump.c +2
-2-/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ if (sysfs_create_link (&dev->kobj, &devcd->devcd_dev.kobj,"devcoredump" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ INIT_DELAYED_WORK (&devcd->del_wk, devcd_del);schedule_delayed_work (&devcd->del_wk,DEVCD_TIMEOUT );
Could just remove the 'if's?
+ sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj,
+ "failing_device");
Re: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 19 lines · Matthew Wilcox
Quoted 4 lines · Randy Dunlap
drivers/base/devcoredump.c +0
-0@@ -294,11 +295,11 @@ void dev_coredumpm(struct device *dev, sif (sysfs_create_link (&devcd->devcd_dev.kobj, &dev->kobj,"failing_device" ))drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, s · line 305
Quoted 10 lines
drivers/base/devcoredump.c +2
-2-/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ if (sysfs_create_link (&dev->kobj, &devcd->devcd_dev.kobj,"devcoredump" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ INIT_DELAYED_WORK (&devcd->del_wk, devcd_del);schedule_delayed_work (&devcd->del_wk,DEVCD_TIMEOUT );Could just remove the 'if's?
Review
Quoted 2 lines
(quoted diff) +2
-0+ sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj, + "failing_device");
OK.
thanks.
Signature · 1 line
~Randy
Re: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 19 lines · Randy Dunlap
Quoted 18 lines · Matthew Wilcox
Quoted 4 lines · Randy Dunlap
drivers/base/devcoredump.c +0
-0@@ -294,11 +295,11 @@ void dev_coredumpm(struct device *dev, sif (sysfs_create_link (&devcd->devcd_dev.kobj, &dev->kobj,"failing_device" ))drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, s · line 305
Quoted 10 lines
drivers/base/devcoredump.c +2
-2-/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ if (sysfs_create_link (&dev->kobj, &devcd->devcd_dev.kobj,"devcoredump" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ INIT_DELAYED_WORK (&devcd->del_wk, devcd_del);schedule_delayed_work (&devcd->del_wk,DEVCD_TIMEOUT );Could just remove the 'if's?
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj, + "failing_device");OK.
sysfs_create_link is __must_check
Re: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 20 lines · Joe Perches
Quoted 19 lines · Randy Dunlap
Quoted 18 lines · Matthew Wilcox
Quoted 4 lines · Randy Dunlap
drivers/base/devcoredump.c +0
-0@@ -294,11 +295,11 @@ void dev_coredumpm(struct device *dev, sif (sysfs_create_link (&devcd->devcd_dev.kobj, &dev->kobj,"failing_device" ))drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, s · line 305
Quoted 10 lines
drivers/base/devcoredump.c +2
-2-/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ if (sysfs_create_link (&dev->kobj, &devcd->devcd_dev.kobj,"devcoredump" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ INIT_DELAYED_WORK (&devcd->del_wk, devcd_del);schedule_delayed_work (&devcd->del_wk,DEVCD_TIMEOUT );Could just remove the 'if's?
Quoted 7 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj, + "failing_device");OK.
sysfs_create_linkis__must_check
Oh, I missed the declaration -- I just saw the definition. This is a situation where __must_check hurts us and it should be removed.
Or this code is wrong and it should be
WARN(sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj, "failing_device");
like drivers/pci/controller/vmd.c and drivers/i2c/i2c-mux.c
Either way, the do_empty() construct feels like the wrong way of covering up the warning.
Johannes Berg
maintainerRe: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 24 lines · Matthew Wilcox
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/base/devcoredump.c void dev_coredumpm(struct device *dev, s · line 305
Quoted 13 lines
drivers/base/devcoredump.c +2
-2if (sysfs_create_link (&devcd->devcd_dev.kobj, &dev->kobj,"failing_device" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ if (sysfs_create_link (&dev->kobj, &devcd->devcd_dev.kobj,"devcoredump" )) -/* nothing - symlink will be missing */ ; +do_empty ();/* nothing - symlink will be missing */ INIT_DELAYED_WORK (&devcd->del_wk, devcd_del);schedule_delayed_work (&devcd->del_wk,DEVCD_TIMEOUT );Could just remove the 'if's?
Quoted 7 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj, + "failing_device");OK.
sysfs_create_linkis__must_check
Quoted 7 lines
Oh, I missed the declaration -- I just saw the definition. This is a situation where
__must_checkhurts us and it should be removed.Or this code is wrong and it should be
WARN(sysfs_create_link(&devcd->devcd_dev.kobj, &dev->kobj, "failing_device");
Perhaps it should be. I didn't think it really mattered _that_ much if the symlink suddenly went missing, but OTOH I don't even know how it could possibly fail.
johannes
Re: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
In reply to Joe PerchesQuoted 2 lines · Joe Perches
sysfs_create_linkis__must_check
The way to handle __must_check if you really really don't want to test and have good reasons is
(a) add a big comment about why this case ostensibly doesn't need the check
(b) cast a test of it to '(void)' or something (I guess we could add
a helper for this). So something like
/* We will always clean up, we don't care whether this fails
or succeeds */
(void)!!sysfs_create_link(...)There are other alternatives (like using WARN_ON_ONCE() instead, for example). So it depends on the code. Which is why that comment is important to show why the code chose that option.
However, I wonder if in this case we should just remove the __must_check. Greg? It goes back a long long time.
Particularly for the "nowarn" version of that function. I'm not seeing why you'd have to care, particularly if you don't even care about the link already existing..
Linus
Greg Kroah-Hartman
maintainerRe: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 16 lines · Linus Torvalds
Quoted 2 lines · Joe Perches
sysfs_create_linkis__must_checkThe way to handle
__must_checkif you really really don't want to test and have good reasons is(a) add a big comment about why this case ostensibly doesn't need the check
(b) cast a test of it to '(void)' or something (I guess we could add
a helper for this). So something like/* We will always clean up, we don't care whether this fails or succeeds */ (void)!!sysfs_create_link(...)
Quoted 6 lines
There are other alternatives (like using
WARN_ON_ONCE()instead, for example). So it depends on the code. Which is why that comment is important to show why the code chose that option.However, I wonder if in this case we should just remove the
__must_check. Greg? It goes back a long long time.
Yeah, maybe it is time to remove it, the gyrations people go through to remove the warning when they "know" they are doing it right feels pretty bad compared to forcing people to check things for "normal" calls to the function.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
In reply to Randy DunlapQuoted 16 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
../drivers/base/devcoredump.c:297:42: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]../drivers/base/devcoredump.c:301:42: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]Signed-off-by Randy Dunlap <[email protected]>Cc Johannes Berg <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>--- drivers/base/devcoredump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/base/devcoredump.c line 12
Quoted 4 lines
drivers/base/devcoredump.c +1
-0@@ -9,6 +9,7 @@* * Author: Johannes Berg <[email protected]> */ +#include <linux/kernel.h>
Why the need for this .h file being added for reformatting the code?
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 7/9] drivers/base: fix empty-body warnings in devcoredump.c
Quoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Randy Dunlap
Fix gcc empty-body warning when -Wextra is used:
../drivers/base/devcoredump.c:297:42: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]../drivers/base/devcoredump.c:301:42: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]Signed-off-by Randy Dunlap <[email protected]>Cc Johannes Berg <[email protected]>Cc Linus Torvalds <[email protected]>Cc Andrew Morton <[email protected]>--- drivers/base/devcoredump.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 9 lines
drivers/base/devcoredump.c line 12
Quoted 7 lines
drivers/base/devcoredump.c +1
-0@@ -9,6 +9,7 @@* * Author: Johannes Berg <[email protected]> */ +#include <linux/kernel.h> Why the need for this .h file being added for reformatting the code?
Ah, the function you add, nevermind, need more coffee...
PATCH 8/9 dax: fix empty-body warnings in bus.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../drivers/dax/bus.c:93:27: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body] ../drivers/dax/bus.c:98:29: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
--- drivers/dax/bus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dax/bus.c +3 -2
@@ -2,6 +2,7 @@/* Copyright(c) 2017-2018 Intel Corporation. All rights reserved. */ #include <linux/memremap.h> #include <linux/device.h> +#include <linux/kernel.h> #include <linux/mutex.h> #include <linux/list.h> #include <linux/slab.h>
@@ -90,12 +91,12 @@ static ssize_t do_id_store(struct device }else rc = -ENOMEM ; }else -/* nothing to remove */ ; +do_empty ();/* nothing to remove */ }else if (action =ID_REMOVE ) {list_del (&dax_id->list);kfree (dax_id); }else -/* dax_id already added */ ; +do_empty ();/* dax_id already added */ mutex_unlock (&dax_bus_lock);if (rc <0 )
Re: [PATCH 8/9] dax: fix empty-body warnings in bus.c
drivers/dax/bus.c static ssize_t do_id_store(struct device · line 99
Quoted 10 lines · Randy Dunlap
drivers/dax/bus.c +2
-2rc = -ENOMEM ; }else -/* nothing to remove */ ; +do_empty ();/* nothing to remove */ }else if (action =ID_REMOVE ) {list_del (&dax_id->list);kfree (dax_id); }else -/* dax_id already added */ ; +do_empty ();/* dax_id already added */
This is just nasty. Please just always turn this bogus warning off as the existing code is a perfectly readable idiom while the new code is just nasty crap for no good reason at all.
PATCH 9/9 target: fix empty-body warning in target_core_pscsi.c
In reply to Randy DunlapFix gcc empty-body warning when -Wextra is used:
../drivers/target/target_core_pscsi.c:624:5: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
--- drivers/target/target_core_pscsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/target/target_core_pscsi.c +2 -1
@@ -18,6 +18,7 @@#include <linux/slab.h> #include <linux/spinlock.h> #include <linux/genhd.h> +#include <linux/kernel.h> #include <linux/cdrom.h> #include <linux/ratelimit.h> #include <linux/module.h>
@@ -621,7 +622,7 @@ static void pscsi_complete_cmd(struct se buf =transport_kmap_data_sg (cmd);if (!buf) - ;/* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */ +do_empty ();/* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */ if (cdb[0 ] =MODE_SENSE_10 ) {if (!(buf[3 ] &0x80 ))