From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: linux-arm-kernel@lists.infradead.org
Cc: Duanqiang Wen <duanqiangwen@net-swift.com>,
mturquette@baylibre.com, sboyd@kernel.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] clkdev: report over-sized strings when creating clkdev entries
Date: Fri, 15 Mar 2024 11:47:55 +0000 [thread overview]
Message-ID: <E1rl62V-004UFh-Te@rmk-PC.armlinux.org.uk> (raw)
Report an error when an attempt to register a clkdev entry results in a
truncated string so the problem can be easily spotted.
Reported by: Duanqiang Wen <duanqiangwen@net-swift.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/clk/clkdev.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index ee37d0be6877..3146f26ab997 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -158,6 +158,10 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
va_list ap)
{
struct clk_lookup_alloc *cla;
+ struct va_format fmt;
+ const char *failure;
+ size_t max_size;
+ ssize_t res;
cla = kzalloc(sizeof(*cla), GFP_KERNEL);
if (!cla)
@@ -165,16 +169,34 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
cla->cl.clk_hw = hw;
if (con_id) {
- strscpy(cla->con_id, con_id, sizeof(cla->con_id));
+ res = strscpy(cla->con_id, con_id, sizeof(cla->con_id));
+ if (res < 0) {
+ max_size = sizeof(cla->con_id);
+ failure = "connection";
+ goto fail;
+ }
cla->cl.con_id = cla->con_id;
}
if (dev_fmt) {
- vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
+ res = vsnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
+ if (res >= sizeof(cla->dev_id)) {
+ max_size = sizeof(cla->dev_id);
+ failure = "device";
+ goto fail;
+ }
cla->cl.dev_id = cla->dev_id;
}
return &cla->cl;
+
+fail:
+ fmt.fmt = dev_fmt;
+ fmt.va = ≈
+ pr_err("%pV:%s: %s ID is greater than %zu\n",
+ &fmt, con_id, failure, max_size);
+ kfree(cla);
+ return NULL;
}
static struct clk_lookup *
--
2.30.2
next reply other threads:[~2024-03-15 11:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 11:47 Russell King (Oracle) [this message]
2024-04-08 3:48 ` [PATCH] clkdev: report over-sized strings when creating clkdev entries Stephen Boyd
2024-05-02 0:59 ` Stephen Boyd
2024-05-02 1:02 ` Stephen Boyd
2024-05-02 8:02 ` Russell King (Oracle)
2024-05-02 8:22 ` Russell King (Oracle)
2024-05-02 11:08 ` Russell King (Oracle)
2024-05-02 22:18 ` Stephen Boyd
2024-05-17 22:09 ` Guenter Roeck
2024-05-17 22:22 ` Russell King (Oracle)
2024-05-17 23:34 ` Guenter Roeck
2024-05-17 23:37 ` Russell King (Oracle)
2024-05-18 3:24 ` Guenter Roeck
2024-05-18 7:01 ` Russell King (Oracle)
2024-05-18 13:44 ` Guenter Roeck
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=E1rl62V-004UFh-Te@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=duanqiangwen@net-swift.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=sboyd@kernel.org \
/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).