linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] RDMA/irdma: Replace one-element array with flexible-array member
@ 2023-08-02 14:46 Gustavo A. R. Silva
  2023-08-03 18:11 ` Leon Romanovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-02 14:46 UTC (permalink / raw)
  To: Mustafa Ismail, Shiraz Saleem, Jason Gunthorpe, Leon Romanovsky,
	Gustavo A. R. Silva
  Cc: linux-rdma, linux-kernel, Gustavo A. R. Silva, linux-hardening

One-element and zero-length arrays are deprecated. So, replace
one-element array in struct irdma_qvlist_info with flexible-array
member.

A patch for this was sent a while ago[1]. However, it seems that, at
the time, the changes were partially folded[2][3], and the actual
flexible-array transformation was omitted. This patch fixes that.

The only binary difference seen before/after changes is shown below:

|  drivers/infiniband/hw/irdma/hw.o
| @@ -868,7 +868,7 @@
| drivers/infiniband/hw/irdma/hw.c:484 (discriminator 2)
|	size += struct_size(iw_qvlist, qv_info, rf->msix_count);
|      55b:      imul   $0x45c,%rdi,%rdi
|-     562:      add    $0x10,%rdi
|+     562:      add    $0x4,%rdi

which is, of course, expected as it reflects the mistake made
while folding the patch I've mentioned above.

Worth mentioning is the fact that with this change we save 12 bytes
of memory, as can be inferred from the diff snapshot above. Notice
that:

$ pahole -C rdma_qv_info idrivers/infiniband/hw/irdma/hw.o
struct irdma_qv_info {
	u32                        v_idx;                /*     0     4 */
	u16                        ceq_idx;              /*     4     2 */
	u16                        aeq_idx;              /*     6     2 */
	u8                         itr_idx;              /*     8     1 */

	/* size: 12, cachelines: 1, members: 4 */
	/* padding: 3 */
	/* last cacheline: 12 bytes */
};

Link: https://lore.kernel.org/linux-hardening/20210525230038.GA175516@embeddedor/ [1]
Link: https://lore.kernel.org/linux-hardening/bf46b428deef4e9e89b0ea1704b1f0e5@intel.com/ [2]
Link: https://lore.kernel.org/linux-rdma/20210520143809.819-1-shiraz.saleem@intel.com/T/#u [3]
Fixes: 44d9e52977a1 ("RDMA/irdma: Implement device initialization definitions")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/infiniband/hw/irdma/main.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/irdma/main.h b/drivers/infiniband/hw/irdma/main.h
index 5483684a534c..82fc5f5b002c 100644
--- a/drivers/infiniband/hw/irdma/main.h
+++ b/drivers/infiniband/hw/irdma/main.h
@@ -239,7 +239,7 @@ struct irdma_qv_info {
 
 struct irdma_qvlist_info {
 	u32 num_vectors;
-	struct irdma_qv_info qv_info[1];
+	struct irdma_qv_info qv_info[];
 };
 
 struct irdma_gen_ops {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] RDMA/irdma: Replace one-element array with flexible-array member
  2023-08-02 14:46 [PATCH][next] RDMA/irdma: Replace one-element array with flexible-array member Gustavo A. R. Silva
@ 2023-08-03 18:11 ` Leon Romanovsky
  2023-08-03 20:00   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Leon Romanovsky @ 2023-08-03 18:11 UTC (permalink / raw)
  To: Mustafa Ismail, Shiraz Saleem, Jason Gunthorpe, Gustavo A. R. Silva
  Cc: linux-rdma, linux-kernel, linux-hardening


On Wed, 02 Aug 2023 08:46:26 -0600, Gustavo A. R. Silva wrote:
> One-element and zero-length arrays are deprecated. So, replace
> one-element array in struct irdma_qvlist_info with flexible-array
> member.
> 
> A patch for this was sent a while ago[1]. However, it seems that, at
> the time, the changes were partially folded[2][3], and the actual
> flexible-array transformation was omitted. This patch fixes that.
> 
> [...]

Applied, thanks!

[1/1] RDMA/irdma: Replace one-element array with flexible-array member
      https://git.kernel.org/rdma/rdma/c/38313c6d2a02c2

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] RDMA/irdma: Replace one-element array with flexible-array member
  2023-08-03 18:11 ` Leon Romanovsky
@ 2023-08-03 20:00   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-08-03 20:00 UTC (permalink / raw)
  To: Leon Romanovsky, Mustafa Ismail, Shiraz Saleem, Jason Gunthorpe,
	Gustavo A. R. Silva
  Cc: linux-rdma, linux-kernel, linux-hardening



On 8/3/23 12:11, Leon Romanovsky wrote:
> 
> On Wed, 02 Aug 2023 08:46:26 -0600, Gustavo A. R. Silva wrote:
>> One-element and zero-length arrays are deprecated. So, replace
>> one-element array in struct irdma_qvlist_info with flexible-array
>> member.
>>
>> A patch for this was sent a while ago[1]. However, it seems that, at
>> the time, the changes were partially folded[2][3], and the actual
>> flexible-array transformation was omitted. This patch fixes that.
>>
>> [...]
> 
> Applied, thanks!

Awesome. :)

Thank you!
--
Gustavo

> 
> [1/1] RDMA/irdma: Replace one-element array with flexible-array member
>        https://git.kernel.org/rdma/rdma/c/38313c6d2a02c2
> 
> Best regards,

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-03 23:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02 14:46 [PATCH][next] RDMA/irdma: Replace one-element array with flexible-array member Gustavo A. R. Silva
2023-08-03 18:11 ` Leon Romanovsky
2023-08-03 20:00   ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).