linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Duanqiang Wen <duanqiangwen@net-swift.com>
Cc: mturquette@baylibre.com, sboyd@kernel.org,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH clk] clk: clkdev: add error messages for name exceeding maximum length
Date: Wed, 13 Mar 2024 10:09:04 +0000	[thread overview]
Message-ID: <ZfF7QE0Jqok2uKrL@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240313064252.50233-1-duanqiangwen@net-swift.com>

On Wed, Mar 13, 2024 at 02:42:52PM +0800, Duanqiang Wen wrote:
> diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
> index ee37d0be6877..620dc1e80b48 100644
> --- a/drivers/clk/clkdev.c
> +++ b/drivers/clk/clkdev.c
> @@ -158,6 +158,9 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
>  	va_list ap)
>  {
>  	struct clk_lookup_alloc *cla;
> +	struct device *dev;
> +
> +	dev = clk_hw_get_dev(hw);

Sorry, but no, clkdev should have minimal dependencies on CCF (it was
designed to be completely independent). I'd prefer not to add this.
Just print the formatted dev_fmt+ap and the con_id when reporting
errors.

>  
>  	cla = kzalloc(sizeof(*cla), GFP_KERNEL);
>  	if (!cla)
> @@ -165,11 +168,19 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
>  
>  	cla->cl.clk_hw = hw;
>  	if (con_id) {
> +		if (strlen(dev_fmt) >= MAX_CON_ID) {

This is wrong (uses dev_fmt not con_id). Also, use sizeof(cla->con_id)
to test against.

> +			pr_err("%s:con_id string cannot be greater than 16 characters\n", dev_fmt);

Cleanup?

> +			return NULL;
> +		}
>  		strscpy(cla->con_id, con_id, sizeof(cla->con_id));
>  		cla->cl.con_id = cla->con_id;
>  	}
>  
>  	if (dev_fmt) {
> +		if (strlen(dev_fmt) >= MAX_DEV_ID) {

This is also wrong. The length of the format string does not give any
information on how long the resulting string actually is.

> +			pr_err("%s:dev_id string cannot be greater than 20 characters\n", dev_fmt);

Cleanup?

> +			return NULL;
> +		}
>  		vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);

Using vsnprintf() here and checking whether the return value is larger
than sizeof(cla->dev_id) would be better.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      reply	other threads:[~2024-03-13 10:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13  6:42 [PATCH clk] clk: clkdev: add error messages for name exceeding maximum length Duanqiang Wen
2024-03-13 10:09 ` Russell King (Oracle) [this message]

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=ZfF7QE0Jqok2uKrL@shell.armlinux.org.uk \
    --to=linux@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 NNTP newsgroup(s).