iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
PATCH 1/1 iommufd/iommufd_private.h: Avoid -Wflex-array-member-not-at-end warning
-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 corresponding structure. Notice that struct iommufd_vevent is a flexible structure, this is a structure that contains a flexible-array member.
Fix the following warning:
drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
--- drivers/iommu/iommufd/iommufd_private.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/iommufd_private.h +3 -1
@@ -614,7 +614,6 @@ struct iommufd_veventq {struct iommufd_eventq common;struct iommufd_viommu *viommu;struct list_head node;/* for iommufd_viommu::veventqs */ -struct iommufd_vevent lost_events_header;enum iommu_veventq_type type;unsigned int depth;
@@ -622,6 +621,9 @@ struct iommufd_veventq {/* Use common.lock for protection */ u32 num_events;u32 sequence; + +/* Must be last as it ends in a flexible-array member. */ +struct iommufd_vevent lost_events_header; }; static inline struct iommufd_veventq *
Signature · 1 line
2.43.0
Quoted 11 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 corresponding structure. Notice that struct
iommufd_veventis a flexible structure, this is a structure that contains a flexible-array member.Fix the following warning:
drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
IIUIC, there might be data corruption due to this? If so, I think we should do:
[PATCH rc] iommufd: Fix flex-array-member-not-at-end in struct iommufd_veventq
And add:
Quoted 1 line
Signed-off-by Gustavo A. R. Silva <[email protected]>
With that,
Thanks for the patch!
Quoted 9 lines · Nicolin Chen
Quoted 8 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 corresponding structure. Notice that struct
iommufd_veventis a flexible structure, this is a structure that contains a flexible-array member.
Quoted 5 lines
Quoted 3 lines
Fix the following warning:
drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]IIUIC, there might be data corruption due to this? If so, I think
Yep. Also, after taking a look at the commit you mention, the counted_by annotation in struct iommufd_vevent is wrong in commit e8e1ef9b77a7 ("iommufd/viommu: Add iommufd_viommu_report_event helper"). The counter, in this case vevent->data_len must always be initialized before the first reference to the flexible array:
drivers/iommu/iommufd/driver.c +1 -1
@@ -161,8 +161,8 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu, vevent = &veventq->lost_events_header; goto out_set_header; } -memcpy (vevent->event_data, event_data, data_len); vevent->data_len = data_len; +memcpy (vevent->event_data, event_data, data_len); veventq->num_events++; out_set_header:
I'll turn this into a small patch series to fix the above issue as well.
Thanks
-Gustavo
Quoted 12 lines · Gustavo A. R. Silva
Quoted 9 lines · Nicolin Chen
Quoted 8 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 corresponding structure. Notice that struct
iommufd_veventis a flexible structure, this is a structure that contains a flexible-array member.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Fix the following warning:
drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array- member-not-at-end]IIUIC, there might be data corruption due to this? If so, I think
Okay, I didn't find evidence of data corruption. So, this patch can be applied to a -next tree.
Quoted 11 lines
Yep. Also, after taking a look at the commit you mention, the
counted_byannotation in structiommufd_veventis wrong in commite8e1ef9b77a7("iommufd/viommu: Addiommufd_viommu_report_eventhelper"). The counter, in this casevevent->data_lenmust always be initialized before the first reference to the flexible array:drivers/iommu/iommufd/driver.c +0
-0
drivers/iommu/iommufd/driver.c int iommufd_viommu_report_event(struct iommufd_viommu *viommu, · line 168
Quoted 9 lines
drivers/iommu/iommufd/driver.c +1
-1@@ -161,8 +161,8 @@ int iommufd_viommu_report_event(struct iommufd_viommu *viommu, vevent = &veventq->lost_events_header; goto out_set_header; } - memcpy(vevent->event_data, event_data, data_len); vevent->data_len = data_len; + memcpy(vevent->event_data, event_data, data_len); veventq->num_events++; out_set_header:
I will submit the above as a separate patch.
Thanks
-Gustavo
Quoted 13 lines · Gustavo A. R. Silva
Quoted 12 lines · Gustavo A. R. Silva
Quoted 11 lines · Nicolin Chen
Quoted 10 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 corresponding structure. Notice that struct
iommufd_veventis a flexible structure, this is a structure that contains a flexible-array member.Fix the following warning:
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
drivers/iommu/iommufd/iommufd_private.h:621:31: warning:
structure containing a flexible array member is not at the end of another structure [-Wflex-array- member-not-at-end]IIUIC, there might be data corruption due to this? If so, I think
Okay, I didn't find evidence of data corruption. So, this patch can be applied to a -next tree.
Revisiting the design, the "lost_events_header" doesn't allocate data but only uses its internal header to raise a flag. So there should not be any data corruption.
Yea, I think we are fine with your for-next patch.
Thanks
Nicolin
Quoted 11 lines
From: Gustavo A. R. Silva <[email protected]>
Sent: Monday, November 10, 2025 7:36 PM-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 corresponding structure. Notice that struct
iommufd_veventis a flexible structure, this is a structure that contains a flexible-array member.
Quoted 7 lines
Fix the following warning:
drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [- Wflex-array-member-not-at-end]Signed-off-by Gustavo A. R. Silva <[email protected]>
Quoted 8 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 corresponding structure. Notice that struct
iommufd_veventis a flexible structure, this is a structure that contains a flexible-array member.
Quoted 8 lines
Fix the following warning:
drivers/iommu/iommufd/iommufd_private.h:621:31: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/iommu/iommufd/iommufd_private.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Applied thanks
Jason