Kernel-hardening archive mirror
 help / color / mirror / Atom feed
From: "José Expósito" <jose.exposito89@gmail.com>
To: tchornyi@marvell.com
Cc: davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
	kernel-hardening@lists.openwall.com, gustavoars@kernel.org,
	"José Expósito" <jose.exposito89@gmail.com>
Subject: [PATCH] net: prestera: replace zero-length array with flexible-array member
Date: Sat,  4 Dec 2021 18:13:49 +0100	[thread overview]
Message-ID: <20211204171349.22776-1-jose.exposito89@gmail.com> (raw)

One-element and zero-length arrays are deprecated and should be
replaced with flexible-array members:
https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Replace zero-length array with flexible-array member and make use
of the struct_size() helper.

Link: https://github.com/KSPP/linux/issues/78
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/net/ethernet/marvell/prestera/prestera_hw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/prestera/prestera_hw.c b/drivers/net/ethernet/marvell/prestera/prestera_hw.c
index 92cb5e9099c6..6282c9822e2b 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_hw.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_hw.c
@@ -443,7 +443,7 @@ struct prestera_msg_counter_resp {
 	__le32 offset;
 	__le32 num_counters;
 	__le32 done;
-	struct prestera_msg_counter_stats stats[0];
+	struct prestera_msg_counter_stats stats[];
 };
 
 struct prestera_msg_span_req {
@@ -1900,7 +1900,7 @@ int prestera_hw_counters_get(struct prestera_switch *sw, u32 idx,
 		.block_id = __cpu_to_le32(idx),
 		.num_counters = __cpu_to_le32(*len),
 	};
-	size_t size = sizeof(*resp) + sizeof(*resp->stats) * (*len);
+	size_t size = struct_size(resp, stats, *len);
 	int err, i;
 
 	resp = kmalloc(size, GFP_KERNEL);
-- 
2.25.1


             reply	other threads:[~2021-12-04 17:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-04 17:13 José Expósito [this message]
2021-12-04 17:38 ` [PATCH] net: prestera: replace zero-length array with flexible-array member Volodymyr Mytnyk
2021-12-06 16:50 ` Gustavo A. R. Silva
2021-12-07  0:40 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211204171349.22776-1-jose.exposito89@gmail.com \
    --to=jose.exposito89@gmail.com \
    --cc=davem@davemloft.net \
    --cc=gustavoars@kernel.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tchornyi@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).