Skip to contentSkip to conversation

staging: greybus: Replace zero-length array by DECLARE_FLEX_ARRAY() helper

PATCH Superseded Deepak R Varma 2 participants 3 messages Jan 4, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: Replace zero-length array by DECLARE_FLEX_ARRAY() helper

The code currently uses C90 standard extension based zero length array struct which is now deprecated and the new C99 standard extension of flexible array declarations are to be used instead. Also, the macro DECLARE_FLEX_ARRAY() allows to use single flexible array member in a structure. Refer to these links [1], [2] for details.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://lkml.kernel.org/r/YxKY6O2hmdwNh8r8@work

Issue identified using Coccinelle flexible_array.cocci semantic patch.

---
 drivers/staging/greybus/usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/usb.c +1 -1
index 8e9d9d59a357..b7badf87a3f0 100644
@@ -27,7 +27,7 @@ struct gb_usb_hub_control_request {
 };
 
 struct gb_usb_hub_control_response {
-	u8 buf[0];
+	DECLARE_FLEX_ARRAY(u8, buf);
 };
 
 struct gb_usb_device {

--
2.34.1

Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Deepak R Varma

The code currently uses C90 standard extension based zero length array struct which is now deprecated and the new C99 standard extension of flexible array declarations are to be used instead. Also, the macro DECLARE_FLEX_ARRAY() allows to use single flexible array member in a structure. Refer to these links [1], [2] for details.

Thank you for citing some references in your commit, it's a good and helpful practice. This might have been another helpful one:

https://lore.kernel.org/lkml/[email protected]/

Quoted 2 lines

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://lkml.kernel.org/r/YxKY6O2hmdwNh8r8@work

FYI, Linux mailing lists hosted by kernel.org are normally cited using "lore.kernel.org" now, e.g.:
https://lore.kernel.org/lkml/YxKY6O2hmdwNh8r8@work
Your patch is fine, this is just so you can consider this in the future.

Quoted 3 lines

Issue identified using Coccinelle flexible_array.cocci semantic patch.

Looks good to me.

Quoted 22 lines
---
  drivers/staging/greybus/usb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/usb.c +1 -2
index 8e9d9d59a357..b7badf87a3f0 100644
@@ -27,7 +27,7 @@ struct gb_usb_hub_control_request {
  };
 
  struct gb_usb_hub_control_response {
-	u8 buf[0];
+	DECLARE_FLEX_ARRAY(u8, buf);
  };
 
  struct gb_usb_device {
--

2.34.1

#2 lore raw
Quoted 7 lines · Alex Elder
Quoted 5 lines · Deepak R Varma

The code currently uses C90 standard extension based zero length array struct which is now deprecated and the new C99 standard extension of flexible array declarations are to be used instead. Also, the macro DECLARE_FLEX_ARRAY() allows to use single flexible array member in a structure. Refer to these links [1], [2] for details.

Quoted 5 lines

Thank you for citing some references in your commit, it's a good and helpful practice. This might have been another helpful one:

https://lore.kernel.org/lkml/[email protected]/

Hello Alex,
Thank you so much for the feedback. I will include the additional reference and send in a v2.

Quoted 9 lines
Quoted 3 lines

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://lkml.kernel.org/r/YxKY6O2hmdwNh8r8@work

FYI, Linux mailing lists hosted by kernel.org are normally cited using "lore.kernel.org" now, e.g.:
https://lore.kernel.org/lkml/YxKY6O2hmdwNh8r8@work
Your patch is fine, this is just so you can consider this in the future.

Sure, I will. This is very helpful to know.

Quoted 6 lines
Quoted 4 lines

Issue identified using Coccinelle flexible_array.cocci semantic patch.

Looks good to me.

Appreciate your time for the review and comments. I will include the reviewed by tag in my v2.

Regards,
./drv

Quoted 26 lines
Quoted 22 lines
---
  drivers/staging/greybus/usb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/usb.c +1 -2
index 8e9d9d59a357..b7badf87a3f0 100644
@@ -27,7 +27,7 @@ struct gb_usb_hub_control_request {
  };
 
  struct gb_usb_hub_control_response {
-	u8 buf[0];
+	DECLARE_FLEX_ARRAY(u8, buf);
  };
 
  struct gb_usb_device {
--

2.34.1