Skip to contentSkip to conversation

fbdev: Replace 0-length array with flexible array

PATCH Applied Kees Cook 3 participants 3 messages Jan 5, 2023 – Jan 9, 2023 Framebuffer layer

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 fbdev: Replace 0-length array with flexible array

Zero-length arrays are deprecated[1]. Replace struct aperture's "ranges" 0-length array with a flexible array. (How is the size of this array verified?) Detected with GCC 13, using -fstrict-flex-arrays=3:

samples/vfio-mdev/mdpy-fb.c: In function 'mdpy_fb_probe':
samples/vfio-mdev/mdpy-fb.c:169:32: warning: array subscript 0 is outside array bounds of 'struct aperture[0]' [-Warray-bounds=]

  169 |         info->apertures->ranges[0].base = info->fix.smem_start;
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from samples/vfio-mdev/mdpy-fb.c:21:
include/linux/fb.h:510:19: note: while referencing 'ranges'
  510 |                 } ranges[0];
      |                   ^~~~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

---
 include/linux/fb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fb.h +1 -1
index 96b96323e9cb..bf59d6a3590f 100644
@@ -507,7 +507,7 @@ struct fb_info {
 		struct aperture {
 			resource_size_t base;
 			resource_size_t size;
-		} ranges[0];
+		} ranges[];
 	} *apertures;
 
 	bool skip_vt_switch; /* no VT switch on suspend/resume required */
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Kees Cook

Zero-length arrays are deprecated[1]. Replace struct aperture's "ranges" 0-length array with a flexible array. (How is the size of this array verified?) Detected with GCC 13, using -fstrict-flex-arrays=3:

samples/vfio-mdev/mdpy-fb.c: In function 'mdpy_fb_probe':
samples/vfio-mdev/mdpy-fb.c:169:32: warning: array subscript 0 is outside array bounds of 'struct aperture[0]' [-Warray-bounds=]

  169 |         info->apertures->ranges[0].base = info->fix.smem_start;
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from samples/vfio-mdev/mdpy-fb.c:21:
include/linux/fb.h:510:19: note: while referencing 'ranges'
  510 |                 } ranges[0];
      |                   ^~~~~~
Quoted 7 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Thanks!
--
Gustavo

Quoted 20 lines
---
 include/linux/fb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fb.h +1 -1
index 96b96323e9cb..bf59d6a3590f 100644
@@ -507,7 +507,7 @@ struct fb_info {
 		struct aperture {
 			resource_size_t base;
 			resource_size_t size;
-		} ranges[0];
+		} ranges[];
 	} *apertures;
 
 	bool skip_vt_switch; /* no VT switch on suspend/resume required */
Signature · 1 line
2.34.1
maintainer Applied
#2 lore raw
In reply to Kees Cook
Quoted 13 lines · Kees Cook

Zero-length arrays are deprecated[1]. Replace struct aperture's "ranges" 0-length array with a flexible array. (How is the size of this array verified?) Detected with GCC 13, using -fstrict-flex-arrays=3:

samples/vfio-mdev/mdpy-fb.c: In function 'mdpy_fb_probe':
samples/vfio-mdev/mdpy-fb.c:169:32: warning: array subscript 0 is outside array bounds of 'struct aperture[0]' [-Warray-bounds=]

   169 |         info->apertures->ranges[0].base = info->fix.smem_start;
       |         ~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from samples/vfio-mdev/mdpy-fb.c:21:
include/linux/fb.h:510:19: note: while referencing 'ranges'
   510 |                 } ranges[0];
       |                   ^~~~~~
Quoted 7 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

applied to the fbdev git tree.

Thanks!
Helge

Quoted 17 lines
---
  include/linux/fb.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fb.h +1 -1
index 96b96323e9cb..bf59d6a3590f 100644
@@ -507,7 +507,7 @@ struct fb_info {
  		struct aperture {
  			resource_size_t base;
  			resource_size_t size;
-		} ranges[0];
+		} ranges[];
  	} *apertures;
 
  	bool skip_vt_switch; /* no VT switch on suspend/resume required */