* [PATCH] RDMA: Replace zero-length array with flexible-array member
@ 2022-04-01 7:54 cgel.zte
2022-04-01 11:50 ` Jason Gunthorpe
0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2022-04-01 7:54 UTC (permalink / raw)
To: mike.marciniszyn
Cc: dennis.dalessandro, jgg, linux-rdma, linux-kernel, Lv Ruyi, Zeal Robot
From: Lv Ruyi <lv.ruyi@zte.com.cn>
There is a regular need in the kernel to provide a way to declare
having a dynamically sized set of trailing elements in a structure.
Kernel code should always use “flexible array members”[1] for these
cases. The older style of one-element or zero-length arrays should
no longer be used[2].
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
drivers/infiniband/hw/hfi1/mad.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/hw/hfi1/mad.c b/drivers/infiniband/hw/hfi1/mad.c
index 4146a2113a95..09fe0eb87884 100644
--- a/drivers/infiniband/hw/hfi1/mad.c
+++ b/drivers/infiniband/hw/hfi1/mad.c
@@ -2437,7 +2437,7 @@ struct opa_port_data_counters_msg {
__be64 port_vl_xmit_wait_data;
__be64 port_vl_rcv_bubble;
__be64 port_vl_mark_fecn;
- } vls[0];
+ } vls[];
/* array size defined by #bits set in vl_select_mask*/
} port[1]; /* array size defined by #ports in attribute modifier */
};
@@ -2470,7 +2470,7 @@ struct opa_port_error_counters64_msg {
u8 reserved3[7];
struct _vls_ectrs {
__be64 port_vl_xmit_discards;
- } vls[0];
+ } vls[];
/* array size defined by #bits set in vl_select_mask */
} port[1]; /* array size defined by #ports in attribute modifier */
};
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA: Replace zero-length array with flexible-array member
2022-04-01 7:54 [PATCH] RDMA: Replace zero-length array with flexible-array member cgel.zte
@ 2022-04-01 11:50 ` Jason Gunthorpe
2022-04-01 13:32 ` Dennis Dalessandro
0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2022-04-01 11:50 UTC (permalink / raw)
To: cgel.zte
Cc: mike.marciniszyn, dennis.dalessandro, linux-rdma, linux-kernel,
Lv Ruyi, Zeal Robot
On Fri, Apr 01, 2022 at 07:54:06AM +0000, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
>
> There is a regular need in the kernel to provide a way to declare
> having a dynamically sized set of trailing elements in a structure.
> Kernel code should always use “flexible array members”[1] for these
> cases. The older style of one-element or zero-length arrays should
> no longer be used[2].
If I recall properly this doesn't work if the flex array is nested
inside another member.. Not sure what this thinks it is doing anyhow
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA: Replace zero-length array with flexible-array member
2022-04-01 11:50 ` Jason Gunthorpe
@ 2022-04-01 13:32 ` Dennis Dalessandro
0 siblings, 0 replies; 3+ messages in thread
From: Dennis Dalessandro @ 2022-04-01 13:32 UTC (permalink / raw)
To: Jason Gunthorpe, cgel.zte
Cc: mike.marciniszyn, linux-rdma, linux-kernel, Lv Ruyi, Zeal Robot
On 4/1/22 7:50 AM, Jason Gunthorpe wrote:
> On Fri, Apr 01, 2022 at 07:54:06AM +0000, cgel.zte@gmail.com wrote:
>> From: Lv Ruyi <lv.ruyi@zte.com.cn>
>>
>> There is a regular need in the kernel to provide a way to declare
>> having a dynamically sized set of trailing elements in a structure.
>> Kernel code should always use “flexible array members”[1] for these
>> cases. The older style of one-element or zero-length arrays should
>> no longer be used[2].
>
> If I recall properly this doesn't work if the flex array is nested
> inside another member.. Not sure what this thinks it is doing anyhow
I was under the impression that the main goal of using the flex array was so
that people didn't calculate sizes incorrectly. Perhaps I'm wrong though.
I don't really see this being needed. If it even works when nested as Jason
mentioned.
Now that being said there is some clean up that needs to be done to this code,
but it's not this.
-Denny
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-01 13:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 7:54 [PATCH] RDMA: Replace zero-length array with flexible-array member cgel.zte
2022-04-01 11:50 ` Jason Gunthorpe
2022-04-01 13:32 ` Dennis Dalessandro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome