Skip to contentSkip to conversation

target: pscsi: avoid Wempty-body warning

PATCH In review Arnd Bergmann 5 participants 9 messages Mar 22, 2021 – Mar 23, 2021

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

PATCH 1/1 target: pscsi: avoid Wempty-body warning

From: Arnd Bergmann <[email protected]>

Building with 'make W=1' shows a harmless warning for pscsi:

drivers/target/target_core_pscsi.c: In function 'pscsi_complete_cmd':
drivers/target/target_core_pscsi.c:624:33: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

  624 |                                 ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
      |                                 ^

Rework the coding style as suggested by gcc to avoid the warning.

---
 drivers/target/target_core_pscsi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/target/target_core_pscsi.c +3 -2
index 3cbc074992bc..913b092955f6 100644
@@ -620,8 +620,9 @@ static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status,
 			unsigned char *buf;
 
 			buf = transport_kmap_data_sg(cmd);
-			if (!buf)
-				; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
+			if (!buf) {
+				/* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
+			}
 
 			if (cdb[0] == MODE_SENSE_10) {
 				if (!(buf[3] & 0x80))
Signature · 1 line
2.29.2
#1 lore raw
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Building with 'make W=1' shows a harmless warning for pscsi:

drivers/target/target_core_pscsi.c: In function 'pscsi_complete_cmd':
drivers/target/target_core_pscsi.c:624:33: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

  624 |                                 ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
      |                                 ^

Rework the coding style as suggested by gcc to avoid the warning.

I would much, much prefer to drop the bogus warning;

	if (foo)
		; /* comment */

is a fairly usual and absolutely sensible style. The warning on hte other hand is completely stupid.

#2 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Building with 'make W=1' shows a harmless warning for pscsi:

drivers/target/target_core_pscsi.c: In function 'pscsi_complete_cmd':
drivers/target/target_core_pscsi.c:624:33: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

  624 |                                 ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
      |                                 ^

Rework the coding style as suggested by gcc to avoid the warning.

Quoted 7 lines

I would much, much prefer to drop the bogus warning;

	if (foo)
		; /* comment */

is a fairly usual and absolutely sensible style. The warning on hte other hand is completely stupid.

Agreed!

These days it seems there is a competition for the stupidest warning between compilers, and we've reached the point where working around them manages to introduce real bugs :-(

I predict we'll soon see warning such as "this comment looks like valid C code, if you really intended to comment it out, use #if 0 instead". Oh well, let's hope I have not given a new idea here...

Willy

#8 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Building with 'make W=1' shows a harmless warning for pscsi:

drivers/target/target_core_pscsi.c: In function 'pscsi_complete_cmd':
drivers/target/target_core_pscsi.c:624:33: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

  624 |                                 ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
      |                                 ^

Rework the coding style as suggested by gcc to avoid the warning.

---
 drivers/target/target_core_pscsi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/target/target_core_pscsi.c +0 -0
index 3cbc074992bc..913b092955f6 100644

drivers/target/target_core_pscsi.c static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status, · line 625

Quoted 8 lines
drivers/target/target_core_pscsi.c +3 -2
@@ -620,8 +620,9 @@ static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status,
 			unsigned char *buf;
 
 			buf = transport_kmap_data_sg(cmd);
-			if (!buf)
-				; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
+			if (!buf) {
+				/* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
+			}

But why not just delete the code?

			buf = transport_kmap_data_sg(cmd);
			/* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */

I mean, this seems like a real warning here. We're not actually handling the failure to allocate 'buf'. It's not marked as __must_check, but watch the code flow:

                        buf = transport_kmap_data_sg(cmd);
                        if (!buf)
                                ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */

                        if (cdb[0] == MODE_SENSE_10) {
                                if (!(buf[3] & 0x80))
                                        buf[3] |= 0x80;
                        } else {
                                if (!(buf[2] & 0x80))
                                        buf[2] |= 0x80;
                        }

we're about to do a NULL ptr dereference. So this should be handled somehow.

#3 lore raw
In reply to Willy Tarreau
Quoted 23 lines · Willy Tarreau
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Building with 'make W=1' shows a harmless warning for pscsi:

drivers/target/target_core_pscsi.c: In function 'pscsi_complete_cmd':
drivers/target/target_core_pscsi.c:624:33: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]

  624 |                                 ; /* XXX: TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE */
      |                                 ^

Rework the coding style as suggested by gcc to avoid the warning.

Quoted 7 lines

I would much, much prefer to drop the bogus warning;

      if (foo)
              ; /* comment */

is a fairly usual and absolutely sensible style. The warning on hte other hand is completely stupid.

Agreed!

Quoted 7 lines

These days it seems there is a competition for the stupidest warning between compilers, and we've reached the point where working around them manages to introduce real bugs :-(

I predict we'll soon see warning such as "this comment looks like valid C code, if you really intended to comment it out, use #if 0 instead". Oh well, let's hope I have not given a new idea here...

I agree that this instance of the warning is particularly stupid, but the I'd like to leave the warning option there and eventually enable it by default because it tends to find other more interesting cases, and this one is trivial to work around.

I remember previously fixing a few drivers that did obviously incorrect things like

    if (error); /* note the extra ';' */
         return error;

and a lot mostly harmless code like

#ifdef DEBUG_THIS_DRIVER /* always disabled */
#define dprintk(args...) printk(args)
#else
#define dprintk(args...)

#endif
    /* note the mismatched format string */
    dprintk(KERN_WARNING "error %d\n", &object);

Turning the empty dprintk() into no_printk() means we can catch the wrong format string during compile testing.

Arnd

#4 lore raw
Quoted 10 lines · Arnd Bergmann

I agree that this instance of the warning is particularly stupid, but the I'd like to leave the warning option there and eventually enable it by default because it tends to find other more interesting cases, and this one is trivial to work around.

I remember previously fixing a few drivers that did obviously incorrect things like

    if (error); /* note the extra ';' */
         return error;

I totally agree with this one but usually it's already reported by another one (probably the one complaining about misindenting). The case I've seen quite a few times was:

     while (condition);

At least I want the ';' on its own line to avoid it being confused with one that ends a do {} while() block.

Quoted 6 lines

and a lot mostly harmless code like

#ifdef DEBUG_THIS_DRIVER /* always disabled */
#define dprintk(args...) printk(args)
#else
#define dprintk(args...)

Quoted 6 lines
#endif
    /* note the mismatched format string */
    dprintk(KERN_WARNING "error %d\n", &object);

Turning the empty dprintk() into no_printk() means we can catch the wrong format string during compile testing.

Hmmm OK for this one. With this said, given how plenty of warnings seem to consider indent and whatever, I wouldn't be surprised if a difference is made between a totally empty body and one that results from an empty macro. But indeed this one can represent a real bug.

Willy

#5 lore raw
Quoted 11 lines · Willy Tarreau
Quoted 10 lines · Arnd Bergmann

and a lot mostly harmless code like

#ifdef DEBUG_THIS_DRIVER /* always disabled */
#define dprintk(args...) printk(args)
#else
#define dprintk(args...)

#endif
    /* note the mismatched format string */
    dprintk(KERN_WARNING "error %d\n", &object);
Quoted 7 lines
Quoted 2 lines

Turning the empty dprintk() into no_printk() means we can catch the wrong format string during compile testing.

Hmmm OK for this one. With this said, given how plenty of warnings seem to consider indent and whatever, I wouldn't be surprised if a difference is made between a totally empty body and one that results from an empty macro. But indeed this one can represent a real bug.

The -Wempty-body warning is actually really old and predates the compiler's understanding of indentation, we just always disabled it by default so far.

As a lot of subsystems are W=1 clean these days, I just went for the final 26 patches to shut up all empty-body warnings in randconfig builds. Most of these were in the dprink() category, though none of this last set actually had incorrect format strings.

Arnd

#6 lore raw
Quoted 20 lines · Arnd Bergmann
Quoted 11 lines · Willy Tarreau
Quoted 10 lines · Arnd Bergmann

and a lot mostly harmless code like

#ifdef DEBUG_THIS_DRIVER /* always disabled */
#define dprintk(args...) printk(args)
#else
#define dprintk(args...)

#endif
    /* note the mismatched format string */
    dprintk(KERN_WARNING "error %d\n", &object);
Quoted 7 lines
Quoted 2 lines

Turning the empty dprintk() into no_printk() means we can catch the wrong format string during compile testing.

Hmmm OK for this one. With this said, given how plenty of warnings seem to consider indent and whatever, I wouldn't be surprised if a difference is made between a totally empty body and one that results from an empty macro. But indeed this one can represent a real bug.

Quoted 7 lines

The -Wempty-body warning is actually really old and predates the compiler's understanding of indentation, we just always disabled it by default so far.

As a lot of subsystems are W=1 clean these days, I just went for the final 26 patches to shut up all empty-body warnings in randconfig builds. Most of these were in the dprink() category, though none of this last set actually had incorrect format strings.

I agree that if it's only 26 patches on the whole kernel to re-enable one warning it can be worth it for newcomers.

Willy

#7 lore raw
In reply to Willy Tarreau

..

Quoted 8 lines

I totally agree with this one but usually it's already reported by another one (probably the one complaining about misindenting). The case I've seen quite a few times was:

     while (condition);

At least I want the ';' on its own line to avoid it being confused with one that ends a do {} while() block.

For that one it is worth doing:

	while (condition)
		continue;

I've also managed to write:

	while (...) {
		....
	} while (...);

And if anyone thing code should be laid out as:

	do
	{
		...
	}
	while (...);
Show them:
		...
	}
	while (.......................................................
	{
		...

and ask them what it is supposed to be.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)