Skip to contentSkip to conversation

MIPS: dec: prom: Address -Warray-bounds warning

PATCH Applied Gustavo A. R. Silva 4 participants 4 messages Jun 22, 2023 – Jun 23, 2023

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

PATCH 1/1 MIPS: dec: prom: Address -Warray-bounds warning

Zero-length arrays are deprecated, and we are replacing them with flexible array members instead. So, replace zero-length array with flexible-array member in struct memmap.

Address the following warning found after building (with GCC-13) mips64
with decstation_64_defconfig:
In function 'rex_setup_memory_region',
inlined from 'prom_meminit' at arch/mips/dec/prom/memory.c:91:3:
arch/mips/dec/prom/memory.c:72:31: error: array subscript i is outside array bounds of 'unsigned char[0]' [-Werror=array-bounds=]
72 | if (bm->bitmap[i] == 0xff)

      |                     ~~~~~~~~~~^~~

In file included from arch/mips/dec/prom/memory.c:16:
./arch/mips/include/asm/dec/prom.h: In function 'prom_meminit':
./arch/mips/include/asm/dec/prom.h:73:23: note: while referencing 'bitmap'
73 | unsigned char bitmap[0];

This helps with the ongoing efforts to globally enable -Warray-bounds.

This results in no differences in binary output.

---
 arch/mips/include/asm/dec/prom.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/dec/prom.h +1 -1
index 1e1247add1cf..908e96e3a311 100644
@@ -70,7 +70,7 @@ static inline bool prom_is_rex(u32 magic)
  */
 typedef struct {
 	int pagesize;
-	unsigned char bitmap[0];
+	unsigned char bitmap[];
 } memmap;
 
 
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 42 lines · Gustavo A. R. Silva

Zero-length arrays are deprecated, and we are replacing them with flexible array members instead. So, replace zero-length array with flexible-array member in struct memmap.

Address the following warning found after building (with GCC-13) mips64
with decstation_64_defconfig:
In function 'rex_setup_memory_region',
inlined from 'prom_meminit' at arch/mips/dec/prom/memory.c:91:3:
arch/mips/dec/prom/memory.c:72:31: error: array subscript i is outside array bounds of 'unsigned char[0]' [-Werror=array-bounds=]
72 | if (bm->bitmap[i] == 0xff)

      |                     ~~~~~~~~~~^~~

In file included from arch/mips/dec/prom/memory.c:16:
./arch/mips/include/asm/dec/prom.h: In function 'prom_meminit':
./arch/mips/include/asm/dec/prom.h:73:23: note: while referencing 'bitmap'
73 | unsigned char bitmap[0];

This helps with the ongoing efforts to globally enable -Warray-bounds.

This results in no differences in binary output.

---
 arch/mips/include/asm/dec/prom.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/dec/prom.h +1 -1
index 1e1247add1cf..908e96e3a311 100644
@@ -70,7 +70,7 @@ static inline bool prom_is_rex(u32 magic)
  */
 typedef struct {
 	int pagesize;
-	unsigned char bitmap[0];
+	unsigned char bitmap[];
 } memmap;
 
 
Signature · 1 line
2.34.1

applied to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
maintainer Acked-by
#2 lore raw
Quoted 3 lines · Thomas Bogendoerfer
Quoted 3 lines

Zero-length arrays are deprecated, and we are replacing them with flexible array members instead. So, replace zero-length array with flexible-array member in struct memmap.

Technically it is a semantics bug fix actually, as the TURBOchannel
firmware specification (from Jan 1993) says it's:

typedef struct{ int pagesize; unsigned char bitmap[];}memmap; int getbitmap(memmap *map);

(formatting preserved as in the document) so it should have always been a flexible array member. Maybe old (2.x) GCC versions had an issue with it or something, as otherwise I can't imagine why whoever added our typedef did it differently from the spec.

Quoted 1 line

applied to mips-next.

Not sure if you can retrofit it, but:

Maciej

#3 lore raw
Quoted 9 lines · Maciej W. Rozycki
Quoted 3 lines · Thomas Bogendoerfer
Quoted 3 lines

Zero-length arrays are deprecated, and we are replacing them with flexible array members instead. So, replace zero-length array with flexible-array member in struct memmap.

Technically it is a semantics bug fix actually, as the TURBOchannel
firmware specification (from Jan 1993) says it's:

Quoted 7 lines

typedef struct{ int pagesize; unsigned char bitmap[];}memmap; int getbitmap(memmap *map);

(formatting preserved as in the document) so it should have always been a flexible array member. Maybe old (2.x) GCC versions had an issue with it or something, as otherwise I can't imagine why whoever added our typedef did it differently from the spec.

Apparently, flexible-array members were supported in some 2.x versions as an extension to the language; and it was not until GCC 3.0 that they were fully supported by the compiler.

Quoted 6 lines
Quoted 2 lines

applied to mips-next.

Not sure if you can retrofit it, but:

Thanks!
--
Gustavo