Skip to contentSkip to conversation

m68k: amiga: config: Use flexible-array member and mark expected switch fall-through

PATCH In review Gustavo A. R. Silva 2 participants 8 messages Mar 26, 2020 – Apr 21, 2020 m68k architecture

lore
Share & tools
lore
#0 lore raw

cover m68k: amiga: config: Use flexible-array member and mark expected switch fall-through

mark expected switch fall-through
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: [email protected], [email protected]

Hi,

This series aims to replace a zero-length array with a flexible-array member and mark a switch case where we are expecting to fall through.

This also coverts some /* fall through */ comments to the new pseudo-keyword fallthrough;

Building: allmodconfig m68k

Thanks

Gustavo A. R. Silva (2):
[next] m68k: amiga: config: Replace zero-length array with
flexible-array member
[next] m68k: amiga: config: Mark expected switch fall-through

 arch/m68k/amiga/config.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.0
#1 lore raw

PATCH RESEND 1/2 m68k: amiga: config: Replace zero-length array with flexible-array member

The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by this change:

"Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1]

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

---
 arch/m68k/amiga/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/m68k/amiga/config.c +1 -1
index c32ab8041cf6..06c15374200e 100644
@@ -628,7 +628,7 @@ struct savekmsg {
 	unsigned long magic2;		/* SAVEKMSG_MAGIC2 */
 	unsigned long magicptr;		/* address of magic1 */
 	unsigned long size;
-	char data[0];
+	char data[];
 };
 
 static struct savekmsg *savekmsg;
Signature · 1 line
2.26.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH RESEND 1/2][next] m68k: amiga: config: Replace zero-length array with flexible-array member

Quoted 22 lines · Gustavo A. R. Silva

The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by this change:

"Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1]

Quoted 7 lines

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

i.e. will queue in the m68k for-v5.8 branch.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw

PATCH 2/2 m68k: amiga: config: Mark expected switch fall-through

In reply to Gustavo A. R. Silva

Mark switch cases where we are expecting to fall through.

This patch fixes the following warning (Building: allmodconfig m68k):

arch/m68k/amiga/config.c: In function ‘amiga_identify’:
./arch/m68k/include/asm/amigahw.h:42:50: warning: this statement may fall through [-Wimplicit-fallthrough=]

 #define AMIGAHW_SET(name) (amiga_hw_present.name = 1)
                           ~~~~~~~~~~~~~~~~~~~~~~~^~~~

arch/m68k/amiga/config.c:223:3: note: in expansion of macro ‘AMIGAHW_SET’
AMIGAHW_SET(PCMCIA);
^~~~~~~~~~~
arch/m68k/amiga/config.c:224:2: note: here
case AMI_500:
^~~~

Replace the existing /* fall through */ comments and fix the issue above by using the new pseudo-keyword fallthrough;

---
 arch/m68k/amiga/config.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/m68k/amiga/config.c +3 -2
index 06c15374200e..4eb911d64e8d 100644
@@ -221,6 +221,7 @@ static void __init amiga_identify(void)
 	case AMI_1200:
 		AMIGAHW_SET(A1200_IDE);
 		AMIGAHW_SET(PCMCIA);
+		fallthrough;
 	case AMI_500:
 	case AMI_500PLUS:
 	case AMI_1000:
@@ -233,7 +234,7 @@ static void __init amiga_identify(void)
 	case AMI_3000T:
 		AMIGAHW_SET(AMBER_FF);
 		AMIGAHW_SET(MAGIC_REKICK);
-		/* fall through */
+		fallthrough;
 	case AMI_3000PLUS:
 		AMIGAHW_SET(A3000_SCSI);
 		AMIGAHW_SET(A3000_CLK);
@@ -242,7 +243,7 @@ static void __init amiga_identify(void)
 
 	case AMI_4000T:
 		AMIGAHW_SET(A4000_SCSI);
-		/* fall through */
+		fallthrough;
 	case AMI_4000:
 		AMIGAHW_SET(A4000_IDE);
 		AMIGAHW_SET(A3000_CLK);
Signature · 1 line
2.26.0
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2][next] m68k: amiga: config: Mark expected switch fall-through

Quoted 11 lines · Gustavo A. R. Silva

Mark switch cases where we are expecting to fall through.

This patch fixes the following warning (Building: allmodconfig m68k):

arch/m68k/amiga/config.c: In function ‘amiga_identify’:
./arch/m68k/include/asm/amigahw.h:42:50: warning: this statement may fall through [-Wimplicit-fallthrough=]

 #define AMIGAHW_SET(name) (amiga_hw_present.name = 1)
                           ~~~~~~~~~~~~~~~~~~~~~~~^~~~
arch/m68k/amiga/config.c:223:3: note: in expansion of macro ‘AMIGAHW_SET’
   AMIGAHW_SET(PCMCIA);
   ^~~~~~~~~~~
Quoted 8 lines

arch/m68k/amiga/config.c:224:2: note: here
case AMI_500:
^~~~

Replace the existing /* fall through */ comments and fix the issue above by using the new pseudo-keyword fallthrough;

i.e. will queue in the m68k for-v5.8 branch.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

Re: [PATCH 2/2][next] m68k: amiga: config: Mark expected switch fall-through

Quoted 17 lines · Geert Uytterhoeven
Quoted 15 lines · Gustavo A. R. Silva

Mark switch cases where we are expecting to fall through.

This patch fixes the following warning (Building: allmodconfig m68k):

arch/m68k/amiga/config.c: In function ‘amiga_identify’:
./arch/m68k/include/asm/amigahw.h:42:50: warning: this statement may fall through [-Wimplicit-fallthrough=]

 #define AMIGAHW_SET(name) (amiga_hw_present.name = 1)
                           ~~~~~~~~~~~~~~~~~~~~~~~^~~~
arch/m68k/amiga/config.c:223:3: note: in expansion of macro ‘AMIGAHW_SET’
   AMIGAHW_SET(PCMCIA);
   ^~~~~~~~~~~

arch/m68k/amiga/config.c:224:2: note: here
case AMI_500:
^~~~

Quoted 8 lines
Quoted 4 lines

Replace the existing /* fall through */ comments and fix the issue above by using the new pseudo-keyword fallthrough;

i.e. will queue in the m68k for-v5.8 branch.

Geert,

I wonder if you received the first patch of the series.

It seems lkml has been eating some messages, recently.

Thanks
--
Gustavo

#6 lore raw

Re: [PATCH 2/2][next] m68k: amiga: config: Mark expected switch fall-through

Hi Gustavo,

Quoted 23 lines · Gustavo A. R. Silva
Quoted 22 lines · Geert Uytterhoeven
Quoted 19 lines · Gustavo A. R. Silva

Mark switch cases where we are expecting to fall through.

This patch fixes the following warning (Building: allmodconfig m68k):

arch/m68k/amiga/config.c: In function ‘amiga_identify’:
./arch/m68k/include/asm/amigahw.h:42:50: warning: this statement may fall through [-Wimplicit-fallthrough=]

 #define AMIGAHW_SET(name) (amiga_hw_present.name = 1)
                           ~~~~~~~~~~~~~~~~~~~~~~~^~~~
arch/m68k/amiga/config.c:223:3: note: in expansion of macro ‘AMIGAHW_SET’
   AMIGAHW_SET(PCMCIA);
   ^~~~~~~~~~~

arch/m68k/amiga/config.c:224:2: note: here
case AMI_500:
^~~~

Replace the existing /* fall through */ comments and fix the issue above by using the new pseudo-keyword fallthrough;

Quoted 7 lines
Quoted 3 lines

i.e. will queue in the m68k for-v5.8 branch.

Geert,

I wonder if you received the first patch of the series.

No I haven't, and lore also only has the cover latter and patch 2/2:
https://lore.kernel.org/linux-m68k/[email protected]/

Can you please resend? Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds