Skip to contentSkip to conversation

usb: gadget: uvc: Avoid -Wflex-array-member-not-at-end warnings

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Mar 17, 2025 – Apr 7, 2025

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

PATCH 1/1 usb: gadget: uvc: Avoid -Wflex-array-member-not-at-end warnings

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the structure. Notice that struct uvc_input_header_descriptor is a flexible structure --a structure that contains a flexible-array member.

With this, fix three of the following warnings:

drivers/usb/gadget/function/uvc_configfs.h:77:57: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
 drivers/usb/gadget/function/uvc_configfs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/uvc_configfs.h +3 -1
index 2f78cd4f396f..9391614135e9 100644
@@ -74,10 +74,12 @@ static inline struct uvcg_format *to_uvcg_format(struct config_item *item)
 
 struct uvcg_streaming_header {
 	struct config_item				item;
-	struct uvc_input_header_descriptor		desc;
 	unsigned					linked;
 	struct list_head				formats;
 	unsigned					num_fmt;
+
+	/* Must be last --ends in a flexible-array member. */
+	struct uvc_input_header_descriptor		desc;
 };
 
 static inline struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item *item)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Gustavo A. R. Silva

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally.

Move the conflicting declaration to the end of the structure. Notice that struct uvc_input_header_descriptor is a flexible structure --a structure that contains a flexible-array member.

With this, fix three of the following warnings:

drivers/usb/gadget/function/uvc_configfs.h:77:57: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
 drivers/usb/gadget/function/uvc_configfs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/uvc_configfs.h +0 -0
index 2f78cd4f396f..9391614135e9 100644
@@ -74,10 +74,12 @@ static inline struct uvcg_format *to_uvcg_format(struct config_item *item)
 
 struct uvcg_streaming_header {
 	struct config_item				item;

drivers/usb/gadget/function/uvc_configfs.h static inline struct uvcg_format *to_uvcg_format(struct config_item *item) · line 85

Quoted 10 lines
drivers/usb/gadget/function/uvc_configfs.h +3 -1
-	struct uvc_input_header_descriptor		desc;
 	unsigned					linked;
 	struct list_head				formats;
 	unsigned					num_fmt;
+
+	/* Must be last --ends in a flexible-array member. */
+	struct uvc_input_header_descriptor		desc;
 };
 
 static inline struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item *item)

This looks correct to me, and may be fixing some bugs -- I can see the allocation routine for this is already expecting the bmaControls (in desc) to be trailing:

                /* bmaControls */
                *size += h->num_fmt * UVCG_STREAMING_CONTROL_SIZE;
Signature · 1 line
Kees Cook