From: Rosen Penev <rosenp@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Thorsten Scherer <t.scherer@eckelmann.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] siox: use kzalloc_flex
Date: Wed, 25 Mar 2026 21:47:25 -0700 [thread overview]
Message-ID: <20260326044725.234216-1-rosenp@gmail.com> (raw)
Use the proper function to allocate a struct with a flexible array
member.
Add __counted_by for extra runtime analysis. Add counting variable
assignment as required by __counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/siox/siox-core.c | 5 +++--
drivers/siox/siox.h | 3 ++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/siox/siox-core.c b/drivers/siox/siox-core.c
index 3e8f3b6a4555..b87e2a12d640 100644
--- a/drivers/siox/siox-core.c
+++ b/drivers/siox/siox-core.c
@@ -689,10 +689,11 @@ struct siox_master *siox_master_alloc(struct device *dev,
if (!dev)
return NULL;
- smaster = kzalloc(sizeof(*smaster) + size, GFP_KERNEL);
+ smaster = kzalloc_flex(*smaster, buf, size);
if (!smaster)
return NULL;
+ smaster->buf_len = size;
device_initialize(&smaster->dev);
smaster->busno = -1;
@@ -854,7 +855,7 @@ static struct siox_device *siox_device_add(struct siox_master *smaster,
}
smaster->buf_len = buf_len;
- smaster->buf = buf;
+ memcpy(smaster->buf, buf, buf_len);
}
ret = device_register(&sdevice->dev);
diff --git a/drivers/siox/siox.h b/drivers/siox/siox.h
index 513f2c8312f7..e6809fcafa0f 100644
--- a/drivers/siox/siox.h
+++ b/drivers/siox/siox.h
@@ -27,11 +27,12 @@ struct siox_master {
size_t setbuf_len, getbuf_len;
size_t buf_len;
- u8 *buf;
u8 status;
unsigned long last_poll;
struct task_struct *poll_thread;
+
+ u8 buf[] __counted_by(buf_len);
};
static inline void *siox_master_get_devdata(struct siox_master *smaster)
--
2.53.0
next reply other threads:[~2026-03-26 4:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 4:47 Rosen Penev [this message]
2026-03-26 8:22 ` [PATCH] siox: use kzalloc_flex Marc Kleine-Budde
2026-03-26 19:17 ` Rosen Penev
2026-03-27 6:49 ` Marc Kleine-Budde
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=20260326044725.234216-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=t.scherer@eckelmann.de \
/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