RDMA/cxgb4: Replace 0-length arrays with flexible arrays
Subsystems (2)
PATCH 1/1 RDMA/cxgb4: Replace 0-length arrays with flexible arrays
Zero-length arrays are deprecated[1]. Replace all remaining 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:
In function 'build_rdma_write',
inlined from 'c4iw_post_send' at ../drivers/infiniband/hw/cxgb4/qp.c:1173:10:
../drivers/infiniband/hw/cxgb4/qp.c:597:38: warning: array subscript 0 is outside array bounds of 'struct fw_ri_immd[0]' [-Warray-bounds=]
597 | wqe->write.u.immd_src[0].r2 = 0;
| ~~~~~~~~~~~~~~~~~~~~~^~~../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h: In function 'c4iw_post_send':../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:567:35: note: while referencing 'immd_src'
567 | struct fw_ri_immd immd_src[0];
| ^~~~~~~~
Additionally drop the unused C99_NOT_SUPPORTED ifndef lines.
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/infiniband/hw/cxgb4/t4fw_ri_api.h | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h +6 -20
@@ -122,9 +122,7 @@ struct fw_ri_dsgl {__be16 nsge;__be32 len0;__be64 addr0; -#ifndef C99_NOT_SUPPORTED struct fw_ri_dsge_pair sge[]; -#endif };struct fw_ri_sge {
@@ -138,9 +136,7 @@ struct fw_ri_isgl {__u8 r1;__be16 nsge;__be32 r2; -#ifndef C99_NOT_SUPPORTED struct fw_ri_sge sge[]; -#endif };struct fw_ri_immd {
@@ -148,9 +144,7 @@ struct fw_ri_immd {__u8 r1;__be16 r2;__be32 immdlen; -#ifndef C99_NOT_SUPPORTED __u8 data[]; -#endif };struct fw_ri_tpte {
@@ -320,9 +314,7 @@ struct fw_ri_res_wr {__be32 op_nres;__be32 len16_pkd;__u64 cookie; -#ifndef C99_NOT_SUPPORTED struct fw_ri_res res[]; -#endif };#define FW_RI_RES_WR_NRES_S 0
@@ -562,12 +554,10 @@ struct fw_ri_rdma_write_wr {__be32 plen;__be32 stag_sink;__be64 to_sink; -#ifndef C99_NOT_SUPPORTED union { -struct fw_ri_immd immd_src[0 ]; -struct fw_ri_isgl isgl_src[0 ]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src); } u; -#endif };struct fw_ri_send_wr {
@@ -581,12 +571,10 @@ struct fw_ri_send_wr {__be32 plen;__be32 r3;__be64 r4; -#ifndef C99_NOT_SUPPORTED union { -struct fw_ri_immd immd_src[0 ]; -struct fw_ri_isgl isgl_src[0 ]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src); } u; -#endif };#define FW_RI_SEND_WR_SENDOP_S 0
@@ -618,12 +606,10 @@ struct fw_ri_rdma_write_cmpl_wr {struct fw_ri_isgl isgl_src; } u_cmpl;__be64 r3; -#ifndef C99_NOT_SUPPORTED union fw_ri_write { -struct fw_ri_immd immd_src[0 ]; -struct fw_ri_isgl isgl_src[0 ]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src); } u; -#endif };struct fw_ri_rdma_read_wr {
Signature · 1 line
2.34.1
Quoted 16 lines · Kees Cook
Zero-length arrays are deprecated[1]. Replace all remaining 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:
In function '
build_rdma_write',inlined from 'c4iw_post_send' at ../drivers/infiniband/hw/cxgb4/qp.c:1173:10: ../drivers/infiniband/hw/cxgb4/qp.c:597:38: warning: array subscript 0 is outside array bounds of 'struct fw_ri_immd[0]' [-Warray-bounds=] 597 | wqe->write.u.immd_src[0].r2 = 0; | ~~~~~~~~~~~~~~~~~~~~~^~~
../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h: In function 'c4iw_post_send':../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:567:35: note: while referencing 'immd_src'
567 | structfw_ri_immdimmd_src[0];
| ^~~~~~~~Additionally drop the unused
C99_NOT_SUPPORTEDifndef lines.
Quoted 8 lines
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
Cc Potnuri Bharat Teja <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks!
--
Gustavo
Quoted 96 lines
--- drivers/infiniband/hw/cxgb4/t4fw_ri_api.h | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-)drivers/infiniband/hw/cxgb4/t4fw_ri_api.h +6
-20@@ -122,9 +122,7 @@ struct fw_ri_dsgl {__be16 nsge;__be32 len0;__be64 addr0; -#ifndef C99_NOT_SUPPORTED struct fw_ri_dsge_pair sge[]; -#endif };struct fw_ri_sge {@@ -138,9 +136,7 @@ struct fw_ri_isgl {__u8 r1;__be16 nsge;__be32 r2; -#ifndef C99_NOT_SUPPORTED struct fw_ri_sge sge[]; -#endif };struct fw_ri_immd {@@ -148,9 +144,7 @@ struct fw_ri_immd {__u8 r1;__be16 r2;__be32 immdlen; -#ifndef C99_NOT_SUPPORTED __u8 data[]; -#endif };struct fw_ri_tpte {@@ -320,9 +314,7 @@ struct fw_ri_res_wr {__be32 op_nres;__be32 len16_pkd;__u64 cookie; -#ifndef C99_NOT_SUPPORTED struct fw_ri_res res[]; -#endif };#define FW_RI_RES_WR_NRES_S 0@@ -562,12 +554,10 @@ struct fw_ri_rdma_write_wr {__be32 plen;__be32 stag_sink;__be64 to_sink; -#ifndef C99_NOT_SUPPORTED union { -struct fw_ri_immd immd_src[0 ]; -struct fw_ri_isgl isgl_src[0 ]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src); } u; -#endif };struct fw_ri_send_wr {@@ -581,12 +571,10 @@ struct fw_ri_send_wr {__be32 plen;__be32 r3;__be64 r4; -#ifndef C99_NOT_SUPPORTED union { -struct fw_ri_immd immd_src[0 ]; -struct fw_ri_isgl isgl_src[0 ]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src); } u; -#endif };#define FW_RI_SEND_WR_SENDOP_S 0@@ -618,12 +606,10 @@ struct fw_ri_rdma_write_cmpl_wr {struct fw_ri_isgl isgl_src; } u_cmpl;__be64 r3; -#ifndef C99_NOT_SUPPORTED union fw_ri_write { -struct fw_ri_immd immd_src[0 ]; -struct fw_ri_isgl isgl_src[0 ]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src); } u; -#endif };struct fw_ri_rdma_read_wr {Signature · 1 line
2.34.1
Quoted 27 lines · Kees Cook
Zero-length arrays are deprecated[1]. Replace all remaining 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:
In function '
build_rdma_write',inlined from 'c4iw_post_send' at ../drivers/infiniband/hw/cxgb4/qp.c:1173:10: ../drivers/infiniband/hw/cxgb4/qp.c:597:38: warning: array subscript 0 is outside array bounds of 'struct fw_ri_immd[0]' [-Warray-bounds=] 597 | wqe->write.u.immd_src[0].r2 = 0; | ~~~~~~~~~~~~~~~~~~~~~^~~
../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h: In function 'c4iw_post_send':../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:567:35: note: while referencing 'immd_src'
567 | structfw_ri_immdimmd_src[0];
| ^~~~~~~~Additionally drop the unused
C99_NOT_SUPPORTEDifndef lines.[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
Cc Potnuri Bharat Teja <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>--- drivers/infiniband/hw/cxgb4/t4fw_ri_api.h | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-)
<...>
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h struct fw_ri_rdma_write_cmpl_wr { · line 611
Quoted 11 lines
#define
FW_RI_SEND_WR_SENDOP_S0drivers/infiniband/hw/cxgb4/t4fw_ri_api.h +2
-3@@ -618,12 +606,10 @@ struct fw_ri_rdma_write_cmpl_wr {struct fw_ri_isgl isgl_src; } u_cmpl;__be64 r3; -#ifndef C99_NOT_SUPPORTEDunion fw_ri_write { - struct fw_ri_immd immd_src[0]; - struct fw_ri_isgl isgl_src[0]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src);
smatch built from commit 40351132df3b ("strlen: add __builtin and __fortify functions") produces the following warning:drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:575:17: warning: array of flexible structures
Is it expected? What will prevent from getting this warning from 0-day build bots?
Thanks
Quoted 8 lines
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h +0
-1} u; -#endif };struct fw_ri_rdma_read_wr {Signature · 1 line
2.34.1
Quoted 47 lines · Leon Romanovsky
Quoted 27 lines · Kees Cook
Zero-length arrays are deprecated[1]. Replace all remaining 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:
In function '
build_rdma_write',inlined from 'c4iw_post_send' at ../drivers/infiniband/hw/cxgb4/qp.c:1173:10: ../drivers/infiniband/hw/cxgb4/qp.c:597:38: warning: array subscript 0 is outside array bounds of 'struct fw_ri_immd[0]' [-Warray-bounds=] 597 | wqe->write.u.immd_src[0].r2 = 0; | ~~~~~~~~~~~~~~~~~~~~~^~~
../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h: In function 'c4iw_post_send':../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:567:35: note: while referencing 'immd_src'
567 | structfw_ri_immdimmd_src[0];
| ^~~~~~~~Additionally drop the unused
C99_NOT_SUPPORTEDifndef lines.[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
Cc Potnuri Bharat Teja <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>--- drivers/infiniband/hw/cxgb4/t4fw_ri_api.h | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-)<...>
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h struct fw_ri_rdma_write_cmpl_wr { · line 611
Quoted 11 lines
#define
FW_RI_SEND_WR_SENDOP_S0drivers/infiniband/hw/cxgb4/t4fw_ri_api.h +2
-3@@ -618,12 +606,10 @@ struct fw_ri_rdma_write_cmpl_wr {struct fw_ri_isgl isgl_src; } u_cmpl;__be64 r3; -#ifndef C99_NOT_SUPPORTEDunion fw_ri_write { - struct fw_ri_immd immd_src[0]; - struct fw_ri_isgl isgl_src[0]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src);smatch built from commit
40351132df3b("strlen: add__builtinand__fortifyfunctions") produces the following warning:drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:575:17: warning: array of flexible structures
Quoted 2 lines
Is it expected? What will prevent from getting this warning from 0-day build bots?
Err, I'm not sure I understand? Does smatch define "C99_NOT_SUPPORTED"?
Signature · 1 line
Kees Cook
Quoted 48 lines · Kees Cook
Quoted 47 lines · Leon Romanovsky
Quoted 27 lines · Kees Cook
Zero-length arrays are deprecated[1]. Replace all remaining 0-length arrays with flexible arrays. Detected with GCC 13, using -fstrict-flex-arrays=3:
In function '
build_rdma_write',inlined from 'c4iw_post_send' at ../drivers/infiniband/hw/cxgb4/qp.c:1173:10: ../drivers/infiniband/hw/cxgb4/qp.c:597:38: warning: array subscript 0 is outside array bounds of 'struct fw_ri_immd[0]' [-Warray-bounds=] 597 | wqe->write.u.immd_src[0].r2 = 0; | ~~~~~~~~~~~~~~~~~~~~~^~~
../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h: In function 'c4iw_post_send':../drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:567:35: note: while referencing 'immd_src'
567 | structfw_ri_immdimmd_src[0];
| ^~~~~~~~Additionally drop the unused
C99_NOT_SUPPORTEDifndef lines.[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
Cc Potnuri Bharat Teja <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Leon Romanovsky <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>--- drivers/infiniband/hw/cxgb4/t4fw_ri_api.h | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-)<...>
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h struct fw_ri_rdma_write_cmpl_wr { · line 611
Quoted 11 lines
#define
FW_RI_SEND_WR_SENDOP_S0drivers/infiniband/hw/cxgb4/t4fw_ri_api.h +2
-3@@ -618,12 +606,10 @@ struct fw_ri_rdma_write_cmpl_wr {struct fw_ri_isgl isgl_src; } u_cmpl;__be64 r3; -#ifndef C99_NOT_SUPPORTEDunion fw_ri_write { - struct fw_ri_immd immd_src[0]; - struct fw_ri_isgl isgl_src[0]; + DECLARE_FLEX_ARRAY(struct fw_ri_immd, immd_src); + DECLARE_FLEX_ARRAY(struct fw_ri_isgl, isgl_src);smatch built from commit
40351132df3b("strlen: add__builtinand__fortifyfunctions") produces the following warning:drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:575:17: warning: array of flexible structures
Quoted 4 lines
Quoted 2 lines
Is it expected? What will prevent from getting this warning from 0-day build bots?
Err, I'm not sure I understand? Does smatch define "
C99_NOT_SUPPORTED"?
Why should it define? You removed C99_NOT_SUPPORTED.
Just download smatch, build from scratch and run over this patch. It generates new warning.
➜ kernel git:(wip/leon-for-next) mkt ci --no-sparse --no-extra-warnings ccdbefcf661e (HEAD -> build) RDMA/cxgb4: Replace 0-length arrays with flexible arrays
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line) #11:
inlined from 'c4iw_post_send' at ../drivers/infiniband/hw/cxgb4/qp.c:1173:10:
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h:558:17: warning: array of flexible structures
....
Quoted 3 lines
Signature · 2 lines
-- Kees Cook