* [PATCH][next] MIPS: dec: prom: Address -Warray-bounds warning
@ 2023-06-22 23:43 Gustavo A. R. Silva
2023-06-23 13:10 ` Thomas Bogendoerfer
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-06-22 23:43 UTC (permalink / raw)
To: Maciej W. Rozycki, Thomas Bogendoerfer
Cc: linux-mips, linux-kernel, Gustavo A. R. Silva, linux-hardening
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.
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/323
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
arch/mips/include/asm/dec/prom.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/mips/include/asm/dec/prom.h b/arch/mips/include/asm/dec/prom.h
index 1e1247add1cf..908e96e3a311 100644
--- a/arch/mips/include/asm/dec/prom.h
+++ b/arch/mips/include/asm/dec/prom.h
@@ -70,7 +70,7 @@ static inline bool prom_is_rex(u32 magic)
*/
typedef struct {
int pagesize;
- unsigned char bitmap[0];
+ unsigned char bitmap[];
} memmap;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH][next] MIPS: dec: prom: Address -Warray-bounds warning
2023-06-22 23:43 [PATCH][next] MIPS: dec: prom: Address -Warray-bounds warning Gustavo A. R. Silva
@ 2023-06-23 13:10 ` Thomas Bogendoerfer
2023-06-23 13:41 ` Maciej W. Rozycki
0 siblings, 1 reply; 4+ messages in thread
From: Thomas Bogendoerfer @ 2023-06-23 13:10 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Maciej W. Rozycki, linux-mips, linux-kernel, linux-hardening
On Thu, Jun 22, 2023 at 05:43:57PM -0600, Gustavo A. R. Silva wrote:
> 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.
>
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/323
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> arch/mips/include/asm/dec/prom.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/mips/include/asm/dec/prom.h b/arch/mips/include/asm/dec/prom.h
> index 1e1247add1cf..908e96e3a311 100644
> --- a/arch/mips/include/asm/dec/prom.h
> +++ b/arch/mips/include/asm/dec/prom.h
> @@ -70,7 +70,7 @@ static inline bool prom_is_rex(u32 magic)
> */
> typedef struct {
> int pagesize;
> - unsigned char bitmap[0];
> + unsigned char bitmap[];
> } memmap;
>
>
> --
> 2.34.1
applied to mips-next.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH][next] MIPS: dec: prom: Address -Warray-bounds warning
2023-06-23 13:10 ` Thomas Bogendoerfer
@ 2023-06-23 13:41 ` Maciej W. Rozycki
2023-06-23 14:14 ` Gustavo A. R. Silva
0 siblings, 1 reply; 4+ messages in thread
From: Maciej W. Rozycki @ 2023-06-23 13:41 UTC (permalink / raw)
To: Thomas Bogendoerfer
Cc: Gustavo A. R. Silva, linux-mips, linux-kernel, linux-hardening
On Fri, 23 Jun 2023, Thomas Bogendoerfer wrote:
> > 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.
> applied to mips-next.
Not sure if you can retrofit it, but:
Acked-by: Maciej W. Rozycki <macro@orcam.me.uk>
Maciej
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH][next] MIPS: dec: prom: Address -Warray-bounds warning
2023-06-23 13:41 ` Maciej W. Rozycki
@ 2023-06-23 14:14 ` Gustavo A. R. Silva
0 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-06-23 14:14 UTC (permalink / raw)
To: Maciej W. Rozycki, Thomas Bogendoerfer
Cc: Gustavo A. R. Silva, linux-mips, linux-kernel, linux-hardening
On 6/23/23 07:41, Maciej W. Rozycki wrote:
> On Fri, 23 Jun 2023, Thomas Bogendoerfer wrote:
>
>>> 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.
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.
>
>> applied to mips-next.
>
> Not sure if you can retrofit it, but:
>
> Acked-by: Maciej W. Rozycki <macro@orcam.me.uk>
Thanks!
--
Gustavo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-23 14:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-22 23:43 [PATCH][next] MIPS: dec: prom: Address -Warray-bounds warning Gustavo A. R. Silva
2023-06-23 13:10 ` Thomas Bogendoerfer
2023-06-23 13:41 ` Maciej W. Rozycki
2023-06-23 14:14 ` Gustavo A. R. Silva
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.