Skip to contentSkip to conversation

NFSD: Avoid multiple -Wflex-array-member-not-at-end warnings

PATCH Superseded Gustavo A. R. Silva 5 participants 5 messages Jun 16, 2025 – Jun 17, 2025

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 NFSD: Avoid multiple -Wflex-array-member-not-at-end warnings

Replace flexible-array member with a fixed-size array.

With this changes, fix many instances of the following type of warnings:

fs/nfsd/nfsfh.h:79:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:763:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:669:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:549:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:705:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:678:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
Changes in v3:
- Replace flexible-array member with a fixed-size array. (NeilBrown)

Changes in v2:
- Use indices into fh_raw. (Christoph)
- Remove union and flexible-array member fh_fsid. (Christoph)
- Link: https://lore.kernel.org/linux-hardening/aEoKCuQ1YDs2Ivn0@kspp/

v1:
- Link: https://lore.kernel.org/linux-hardening/aBp37ZXBJM09yAXp@kspp/

 fs/nfsd/nfsfh.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsfh.h +1 -1
index 5103c2f4d225..760e77f3630b 100644
@@ -56,7 +56,7 @@ struct knfsd_fh {
 			u8		fh_auth_type;	/* deprecated */
 			u8		fh_fsid_type;
 			u8		fh_fileid_type;
-			u32		fh_fsid[]; /* flexible-array member */
+			u32		fh_fsid[NFS4_FHSIZE / 4 - 1];
 		};
 	};
 };
Signature · 1 line
2.43.0
reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 33 lines · Gustavo A. R. Silva

Replace flexible-array member with a fixed-size array.

With this changes, fix many instances of the following type of warnings:

fs/nfsd/nfsfh.h:79:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:763:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:669:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:549:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:705:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:678:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
Changes in v3:
- Replace flexible-array member with a fixed-size array. (NeilBrown)

Changes in v2:
- Use indices into fh_raw. (Christoph)
- Remove union and flexible-array member fh_fsid. (Christoph)
- Link: https://lore.kernel.org/linux-hardening/aEoKCuQ1YDs2Ivn0@kspp/

v1:
- Link: https://lore.kernel.org/linux-hardening/aBp37ZXBJM09yAXp@kspp/

 fs/nfsd/nfsfh.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsfh.h +0 -0
index 5103c2f4d225..760e77f3630b 100644

fs/nfsd/nfsfh.h struct knfsd_fh { · line 60

Quoted 6 lines
fs/nfsd/nfsfh.h +1 -1
@@ -56,7 +56,7 @@ struct knfsd_fh {
 			u8		fh_auth_type;	/* deprecated */
 			u8		fh_fsid_type;
 			u8		fh_fileid_type;
-			u32		fh_fsid[]; /* flexible-array member */
+			u32		fh_fsid[NFS4_FHSIZE / 4 - 1];
 		};

Thanks. I think this is a good and simple solution.

Quoted 6 lines
fs/nfsd/nfsfh.h +0 -0
 	};
 };
Signature · 1 line
2.43.0
maintainer Reviewed-by on v3 1/1
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 33 lines · Gustavo A. R. Silva

Replace flexible-array member with a fixed-size array.

With this changes, fix many instances of the following type of warnings:

fs/nfsd/nfsfh.h:79:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:763:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:669:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:549:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:705:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:678:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

---
Changes in v3:
- Replace flexible-array member with a fixed-size array. (NeilBrown)

Changes in v2:
- Use indices into fh_raw. (Christoph)
- Remove union and flexible-array member fh_fsid. (Christoph)
- Link: https://lore.kernel.org/linux-hardening/aEoKCuQ1YDs2Ivn0@kspp/

v1:
- Link: https://lore.kernel.org/linux-hardening/aBp37ZXBJM09yAXp@kspp/

 fs/nfsd/nfsfh.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsfh.h +0 -0
index 5103c2f4d225..760e77f3630b 100644

fs/nfsd/nfsfh.h struct knfsd_fh { · line 62

Quoted 8 lines
fs/nfsd/nfsfh.h +1 -1
@@ -56,7 +56,7 @@ struct knfsd_fh {
 			u8		fh_auth_type;	/* deprecated */
 			u8		fh_fsid_type;
 			u8		fh_fileid_type;
-			u32		fh_fsid[]; /* flexible-array member */
+			u32		fh_fsid[NFS4_FHSIZE / 4 - 1];
 		};
 	};
 };
maintainer
#3 lore raw
In reply to Gustavo A. R. Silva

From: Chuck Lever <[email protected]>

Quoted 5 lines · Gustavo A. R. Silva

Replace flexible-array member with a fixed-size array.

With this changes, fix many instances of the following type of warnings:

Quoted 8 lines

fs/nfsd/nfsfh.h:79:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:763:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:669:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/state.h:549:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:705:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/nfsd/xdr4.h:678:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

[...]

Applied to nfsd-testing, thanks!

[1/1] NFSD: Avoid multiple -Wflex-array-member-not-at-end warnings

      commit: 9aa83533d2e694c84d7d09f9c8eab29ad9f2adef

--
Chuck Lever

#4 lore raw
Quoted 6 lines

Applied to nfsd-testing, thanks!

[1/1] NFSD: Avoid multiple -Wflex-array-member-not-at-end warnings

       commit: 9aa83533d2e694c84d7d09f9c8eab29ad9f2adef

Thank you, folks! :)

-Gustavo