nfsd: Replace one-element array with flexible-array member
Subsystems (2)
PATCH 1/1 nfsd: Replace one-element array with flexible-array member
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace a one-element array with a flexible-arrayº member in struct vbi_anc_data and refactor the rest of the code, accordingly.
This results in no differences in binary output.
--- fs/nfsd/nfs4callback.c | 2 +- fs/nfsd/xdr4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/nfsd/nfs4callback.c +1 -1
@@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, {encode_nfs_cb_opnum4 (xdr,OP_CB_RECALL_ANY );encode_uint32 (xdr, ra->ra_keep); -encode_bitmap4 (xdr, ra->ra_bmval,ARRAY_SIZE (ra->ra_bmval)); +encode_bitmap4 (xdr, ra->ra_bmval,1 ); hdr->nops++; }
fs/nfsd/xdr4.h +1 -1
@@ -899,7 +899,7 @@ struct nfsd4_operation {struct nfsd4_cb_recall_any {struct nfsd4_callback ra_cb;u32 ra_keep; -u32 ra_bmval[1 ]; +u32 ra_bmval[]; };#endif
Signature · 1 line
2.34.1
Chuck Lever
maintainerQuoted 3 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace a one-element array with a flexible-arrayº member in struct
vbi_anc_dataand refactor
I don't know what "struct vbi_anc_data" is. Is the patch description correct?
Quoted 18 lines
the rest of the code, accordingly.
This results in no differences in binary output.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- fs/nfsd/nfs4callback.c | 2 +- fs/nfsd/xdr4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfsd/nfs4callback.c +0
-0
fs/nfsd/nfs4callback.c encode_cb_recallany4args(struct xdr_stream *xdr, · line 356
Quoted 5 lines
fs/nfsd/nfs4callback.c +1
-1@@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, {encode_nfs_cb_opnum4 (xdr,OP_CB_RECALL_ANY );encode_uint32 (xdr, ra->ra_keep); -encode_bitmap4 (xdr, ra->ra_bmval,ARRAY_SIZE (ra->ra_bmval)); +encode_bitmap4 (xdr, ra->ra_bmval,1 );
I find the new code less self-documenting.
fs/nfsd/xdr4.h struct nfsd4_operation { · line 902
Quoted 13 lines
fs/nfsd/nfs4callback.c +0
-0hdr->nops++; }fs/nfsd/xdr4.h +1
-1@@ -899,7 +899,7 @@ struct nfsd4_operation {struct nfsd4_cb_recall_any {struct nfsd4_callback ra_cb;u32 ra_keep; -u32 ra_bmval[1 ]; +u32 ra_bmval[];
This is not a placeholder for "1 or more elements". We actually want just a single u32 element in this array. Doesn't this change the sizeof(struct nfsd4_cb_recall_any) ?
Quoted 6 lines
fs/nfsd/xdr4.h +0
-0};#endif Signature · 1 line
2.34.1
Quoted 7 lines · Chuck Lever
Quoted 3 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace a one-element array with a flexible-arrayº member in struct
vbi_anc_dataand refactorI don't know what "struct
vbi_anc_data" is. Is the patch description correct?
Oops, copy/paste error. I'll fix it up. :)
Quoted 32 lines
Quoted 20 lines
the rest of the code, accordingly.
This results in no differences in binary output.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- fs/nfsd/nfs4callback.c | 2 +- fs/nfsd/xdr4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfsd/nfs4callback.c +0
-0fs/nfsd/nfs4callback.c encode_cb_recallany4args(struct xdr_stream *xdr, · line 356
Quoted 5 lines
fs/nfsd/nfs4callback.c +1
-1@@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, {encode_nfs_cb_opnum4 (xdr,OP_CB_RECALL_ANY );encode_uint32 (xdr, ra->ra_keep); -encode_bitmap4 (xdr, ra->ra_bmval,ARRAY_SIZE (ra->ra_bmval)); +encode_bitmap4 (xdr, ra->ra_bmval,1 );I find the new code less self-documenting.
Quoted 3 lines
fs/nfsd/nfs4callback.c +0
-0hdr->nops++; }
Quoted 14 lines
fs/nfsd/xdr4.h struct nfsd4_operation { · line 902
Quoted 10 lines
fs/nfsd/xdr4.h +1
-1@@ -899,7 +899,7 @@ struct nfsd4_operation {struct nfsd4_cb_recall_any {struct nfsd4_callback ra_cb;u32 ra_keep; -u32 ra_bmval[1 ]; +u32 ra_bmval[];This is not a placeholder for "1 or more elements". We actually want just a single u32 element in this array. Doesn't this change the
sizeof(struct nfsd4_cb_recall_any)?
I see. Yes, it does change the size. Can we replace it with a simple object of type u32? or do you actually need this to stay an array?
Thanks
--
Gustav
Quoted 8 lines
Quoted 8 lines
fs/nfsd/xdr4.h +0
-0};#endif Signature · 1 line
2.34.1
Chuck Lever
maintainerQuoted 58 lines · Gustavo A. R. Silva
Quoted 7 lines · Chuck Lever
Quoted 3 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace a one-element array with a flexible-arrayº member in struct
vbi_anc_dataand refactorI don't know what "struct
vbi_anc_data" is. Is the patch description correct?Oops, copy/paste error. I'll fix it up. :)
Quoted 29 lines
Quoted 20 lines
the rest of the code, accordingly.
This results in no differences in binary output.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- fs/nfsd/nfs4callback.c | 2 +- fs/nfsd/xdr4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfsd/nfs4callback.c +0
-0fs/nfsd/nfs4callback.c encode_cb_recallany4args(struct xdr_stream *xdr, · line 356
Quoted 5 lines
fs/nfsd/nfs4callback.c +1
-1@@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, {encode_nfs_cb_opnum4 (xdr,OP_CB_RECALL_ANY );encode_uint32 (xdr, ra->ra_keep); -encode_bitmap4 (xdr, ra->ra_bmval,ARRAY_SIZE (ra->ra_bmval)); +encode_bitmap4 (xdr, ra->ra_bmval,1 );I find the new code less self-documenting.
Quoted 16 lines
fs/nfsd/xdr4.h struct nfsd4_operation { · line 902
Quoted 12 lines
fs/nfsd/nfs4callback.c +0
-0hdr->nops++; }fs/nfsd/xdr4.h +1
-1@@ -899,7 +899,7 @@ struct nfsd4_operation {struct nfsd4_cb_recall_any {struct nfsd4_callback ra_cb;u32 ra_keep; -u32 ra_bmval[1 ]; +u32 ra_bmval[];This is not a placeholder for "1 or more elements". We actually want just a single u32 element in this array. Doesn't this change the
sizeof(struct nfsd4_cb_recall_any)?
Quoted 2 lines
I see. Yes, it does change the size. Can we replace it with a simple object of type u32? or do you actually need this to stay an array?
It's not impossible to make it a scalar u32, however...
In this area of code, *_bmval is always a bitmap -- an array of u32s. Helpers like encode_bitmap4() assume an array. I think it would be less confusing overall to human readers if it remained an array.
In this case, it is a single element array because CB_RECALL_ANY doesn't happen to use bits above the first 32-bit word of the bitmap.
We could make it a 2-element array, I think, without harm. Send a patch for that, and Dai can test it to make sure there are no unexpected interoperability consequences.
I hope that would avoid suspicious-looking array definitions.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fs/nfsd/xdr4.h +0
-0};#endif Signature · 1 line
2.34.1
Quoted 64 lines · Chuck Lever
Quoted 58 lines · Gustavo A. R. Silva
Quoted 7 lines · Chuck Lever
Quoted 3 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace a one-element array with a flexible-arrayº member in struct
vbi_anc_dataand refactorI don't know what "struct
vbi_anc_data" is. Is the patch description correct?Oops, copy/paste error. I'll fix it up. :)
Quoted 29 lines
Quoted 20 lines
the rest of the code, accordingly.
This results in no differences in binary output.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- fs/nfsd/nfs4callback.c | 2 +- fs/nfsd/xdr4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfsd/nfs4callback.c +0
-0fs/nfsd/nfs4callback.c encode_cb_recallany4args(struct xdr_stream *xdr, · line 356
Quoted 5 lines
fs/nfsd/nfs4callback.c +1
-1@@ -353,7 +353,7 @@ encode_cb_recallany4args(struct xdr_stream *xdr, {encode_nfs_cb_opnum4 (xdr,OP_CB_RECALL_ANY );encode_uint32 (xdr, ra->ra_keep); -encode_bitmap4 (xdr, ra->ra_bmval,ARRAY_SIZE (ra->ra_bmval)); +encode_bitmap4 (xdr, ra->ra_bmval,1 );I find the new code less self-documenting.
Quoted 16 lines
fs/nfsd/xdr4.h struct nfsd4_operation { · line 902
Quoted 12 lines
fs/nfsd/nfs4callback.c +0
-0hdr->nops++; }fs/nfsd/xdr4.h +1
-1@@ -899,7 +899,7 @@ struct nfsd4_operation {struct nfsd4_cb_recall_any {struct nfsd4_callback ra_cb;u32 ra_keep; -u32 ra_bmval[1 ]; +u32 ra_bmval[];This is not a placeholder for "1 or more elements". We actually want just a single u32 element in this array. Doesn't this change the
sizeof(struct nfsd4_cb_recall_any)?Quoted 2 lines
I see. Yes, it does change the size. Can we replace it with a simple object of type u32? or do you actually need this to stay an array?
It's not impossible to make it a scalar u32, however...
Quoted 7 lines
In this area of code,
*_bmvalis always a bitmap -- an array of u32s. Helpers likeencode_bitmap4()assume an array. I think it would be less confusing overall to human readers if it remained an array.In this case, it is a single element array because
CB_RECALL_ANYdoesn't happen to use bits above the first 32-bit word of the bitmap.
I see. If this is never going to be treated as a flexible array, then it can stay as is.
-fstrict-flex-arrays=3 should not warn about this because the array will never ever be tried to be accessed beyond element 1. :)
Thanks for the feedback!
--
Gustavo
Quoted 13 lines
We could make it a 2-element array, I think, without harm. Send a patch for that, and Dai can test it to make sure there are no unexpected interoperability consequences.
I hope that would avoid suspicious-looking array definitions.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fs/nfsd/xdr4.h +0
-0};#endif Signature · 1 line
2.34.1