iavf: Replace one-element array with flexible-array member
Subsystems (3)
PATCH 1/1 iavf: 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 one-element array with flexible-array member in struct iavf_qvlist_info, and refactor the rest of the code, accordingly.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
--- drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_client.c +1 -1
@@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; msg_size =struct_size (v_qvlist_info, qv_info, - v_qvlist_info->num_vectors -1 ); + v_qvlist_info->num_vectors); adapter->client_pending |=BIT (VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP ); err = iavf_aq_send_msg_to_pf(&adapter->hw,
drivers/net/ethernet/intel/iavf/iavf_client.h +1 -1
@@ -53,7 +53,7 @@ struct iavf_qv_info {struct iavf_qvlist_info {u32 num_vectors; -struct iavf_qv_info qv_info[1 ]; +struct iavf_qv_info qv_info[]; };#define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF
Signature · 1 line
2.34.1
Quoted 5 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct
iavf_qvlist_info, and refactor the rest of the code, accordingly.
Quoted 8 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Quoted 5 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct
iavf_qvlist_info, and refactor the rest of the code, accordingly.
Quoted 8 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Signature · 5 lines
Kees Cook _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Tony Nguyen
maintainerQuoted 23 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct
iavf_qvlist_info, and refactor the rest of the code, accordingly.This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/iavf/iavf_client.c +0
-0
drivers/net/ethernet/intel/iavf/iavf_client.c static int iavf_client_setup_qvlist(struct iavf_info *ldev, · line 473
Quoted 5 lines
drivers/net/ethernet/intel/iavf/iavf_client.c +1
-1@@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; msg_size =struct_size (v_qvlist_info, qv_info, - v_qvlist_info->num_vectors -1 ); + v_qvlist_info->num_vectors);
The problem is this mirrors the virtchnl struct (virtchnl_rdma_qvlist_info) so that structure needs to change as well... However, this goes back to the interface that virtchnl provides between PF and VF [1].
I think removing the iavf structure and directly using the virtchnl one would make sense. We'd need to adjust virtchnl and follow Kees' suggestion [2].
Quoted 7 lines
drivers/net/ethernet/intel/iavf/iavf_client.c +0
-0adapter->client_pending |=BIT (VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP ); err = iavf_aq_send_msg_to_pf(&adapter->hw,drivers/net/ethernet/intel/iavf/iavf_client.h +0
-0
drivers/net/ethernet/intel/iavf/iavf_client.h struct iavf_qv_info { · line 59
Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_client.h +1
-1@@ -53,7 +53,7 @@ struct iavf_qv_info {struct iavf_qvlist_info {u32 num_vectors; -struct iavf_qv_info qv_info[1 ]; +struct iavf_qv_info qv_info[]; };#define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF
[1] https://lore.kernel.org/intel-wired-lan/[email protected]/
[2] https://lore.kernel.org/intel-wired-lan/202106091424.37E833794@keescook/
Quoted 33 lines · Tony Nguyen
Quoted 23 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct
iavf_qvlist_info, and refactor the rest of the code, accordingly.This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_client.c | 2 +- drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/iavf/iavf_client.c +0
-0drivers/net/ethernet/intel/iavf/iavf_client.c static int iavf_client_setup_qvlist(struct iavf_info *ldev, · line 472
Quoted 4 lines
drivers/net/ethernet/intel/iavf/iavf_client.c +1
-1@@ -470,7 +470,7 @@ static int iavf_client_setup_qvlist(struct iavf_info *ldev, v_qvlist_info = (struct virtchnl_rdma_qvlist_info *)qvlist_info; msg_size =struct_size (v_qvlist_info, qv_info, - v_qvlist_info->num_vectors -1 ); + v_qvlist_info->num_vectors);The problem is this mirrors the virtchnl struct (
virtchnl_rdma_qvlist_info) so that structure needs to change as well... However, this goes back to the interface that virtchnl provides between PF and VF [1].
Quoted 3 lines
I think removing the iavf structure and directly using the virtchnl one would make sense. We'd need to adjust virtchnl and follow Kees' suggestion [2].
Note that at the time I suggested "[0]", but it should have been "[]". But, yes, Keeping the "over allocation" is fine since it's a hardware ABI.
Alternatively, it could be defined with a union to keep all the sizes the same:
struct iavf_qvlist_info {
u32 num_vectors;
- struct iavf_qv_info qv_info[1];
+ union {
+ struct iavf_qv_info single_qv_info;
+ DECLARE_FLEX_ARRAY(struct iavf_qv_info, qv_info)
+ };
};
-Kees
Quoted 17 lines
Quoted 8 lines
drivers/net/ethernet/intel/iavf/iavf_client.c +0
-0adapter->client_pending |=BIT (VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP ); err = iavf_aq_send_msg_to_pf(&adapter->hw,drivers/net/ethernet/intel/iavf/iavf_client.h +0
-0drivers/net/ethernet/intel/iavf/iavf_client.h struct iavf_qv_info { · line 57
Quoted 6 lines
drivers/net/ethernet/intel/iavf/iavf_client.h +1
-1@@ -53,7 +53,7 @@ struct iavf_qv_info {struct iavf_qvlist_info {u32 num_vectors; -struct iavf_qv_info qv_info[1 ]; +struct iavf_qv_info qv_info[]; };#define IAVF_CLIENT_MSIX_ALL 0xFFFFFFFF[1] https://lore.kernel.org/intel-wired-lan/[email protected]/
[2] https://lore.kernel.org/intel-wired-lan/202106091424.37E833794@keescook/
Signature · 1 line
Kees Cook