public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: <Claudiu.Beznea@microchip.com>
To: <geert+renesas@glider.be>, <mturquette@baylibre.com>,
	<sboyd@kernel.org>, <Conor.Dooley@microchip.com>
Cc: <linux-clk@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] clk: microchip: mpfs-ccc: Use devm_kasprintf() for allocating formatted strings
Date: Thu, 12 Jan 2023 10:04:56 +0000	[thread overview]
Message-ID: <715515eb-0a9c-8ee8-5393-d8986facb55b@microchip.com> (raw)
In-Reply-To: <f904fd28b2087d1463ea65f059924e3b1acc193c.1672764239.git.geert+renesas@glider.be>

On 03.01.2023 18:45, Geert Uytterhoeven wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> In various places, string buffers of a fixed size are allocated, and
> filled using snprintf() with the same fixed size, which is error-prone.
> 
> Replace this by calling devm_kasprintf() instead, which always uses the
> appropriate size.
> 
> While at it, remove an unneeded intermediate variable, which allows us
> to drop a cast as a bonus.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Applied to clk-microchip-fixes, thanks!

> ---
>  drivers/clk/microchip/clk-mpfs-ccc.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/clk/microchip/clk-mpfs-ccc.c b/drivers/clk/microchip/clk-mpfs-ccc.c
> index 32aae880a14f3b1c..0ddc73e07be42973 100644
> --- a/drivers/clk/microchip/clk-mpfs-ccc.c
> +++ b/drivers/clk/microchip/clk-mpfs-ccc.c
> @@ -164,12 +164,11 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_
> 
>         for (unsigned int i = 0; i < num_clks; i++) {
>                 struct mpfs_ccc_out_hw_clock *out_hw = &out_hws[i];
> -               char *name = devm_kzalloc(dev, 23, GFP_KERNEL);
> +               char *name = devm_kasprintf(dev, GFP_KERNEL, "%s_out%u", parent->name, i);
> 
>                 if (!name)
>                         return -ENOMEM;
> 
> -               snprintf(name, 23, "%s_out%u", parent->name, i);
>                 out_hw->divider.hw.init = CLK_HW_INIT_HW(name, &parent->hw, &clk_divider_ops, 0);
>                 out_hw->divider.reg = data->pll_base[i / MPFS_CCC_OUTPUTS_PER_PLL] +
>                         out_hw->reg_offset;
> @@ -201,14 +200,13 @@ static int mpfs_ccc_register_plls(struct device *dev, struct mpfs_ccc_pll_hw_clo
> 
>         for (unsigned int i = 0; i < num_clks; i++) {
>                 struct mpfs_ccc_pll_hw_clock *pll_hw = &pll_hws[i];
> -               char *name = devm_kzalloc(dev, 18, GFP_KERNEL);
> 
> -               if (!name)
> +               pll_hw->name = devm_kasprintf(dev, GFP_KERNEL, "ccc%s_pll%u",
> +                                             strchrnul(dev->of_node->full_name, '@'), i);
> +               if (!pll_hw->name)
>                         return -ENOMEM;
> 
>                 pll_hw->base = data->pll_base[i];
> -               snprintf(name, 18, "ccc%s_pll%u", strchrnul(dev->of_node->full_name, '@'), i);
> -               pll_hw->name = (const char *)name;
>                 pll_hw->hw.init = CLK_HW_INIT_PARENTS_DATA_FIXED_SIZE(pll_hw->name,
>                                                                       pll_hw->parents,
>                                                                       &mpfs_ccc_pll_ops, 0);
> --
> 2.25.1
> 


      parent reply	other threads:[~2023-01-12 10:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-03 16:45 [PATCH] clk: microchip: mpfs-ccc: Use devm_kasprintf() for allocating formatted strings Geert Uytterhoeven
2023-01-03 17:32 ` Conor Dooley
2023-01-04 13:26   ` Geert Uytterhoeven
2023-01-04 13:40     ` Conor Dooley
2023-01-04 13:44       ` Geert Uytterhoeven
2023-01-11 19:26 ` Conor Dooley
2023-01-12  8:52   ` Claudiu.Beznea
2023-01-12 10:04 ` Claudiu.Beznea [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=715515eb-0a9c-8ee8-5393-d8986facb55b@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=Conor.Dooley@microchip.com \
    --cc=geert+renesas@glider.be \
    --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