All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Michal Simek <michal.simek@amd.com>, duoming@zju.edu.cn
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	mturquette@baylibre.com
Subject: Re: [PATCH v2] clk: zynq: Prevent null pointer dereference caused by kmalloc failure
Date: Thu, 29 Feb 2024 17:22:42 -0800	[thread overview]
Message-ID: <856febae4f00b1129f695cf3c75dd380.sboyd@kernel.org> (raw)
In-Reply-To: <365f9a90.55b0.18df5394935.Coremail.duoming@zju.edu.cn>

Quoting duoming@zju.edu.cn (2024-02-29 06:16:28)
> On Thu, 29 Feb 2024 13:45:54 +0100 Michal Simek wrote:
> 
> The length of "mio_clk_00x" is 11 bytes, and the kernel will alloc 16 bytes to it.
> I use a local variable whose size is 16 bytes to replace it. The detail is shown
> below:
> 
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 7bdeaff2bfd..81d530e3357 100644
> --- a/drivers/clk/zynq/clkc.c
> +++ b/drivers/clk/zynq/clkc.c
> @@ -215,7 +215,7 @@ static void __init zynq_clk_setup(struct device_node *np)
>         int i;
>         u32 tmp;
>         int ret;
> -       char *clk_name;
> +       char clk_name[16];
>         unsigned int fclk_enable = 0;
>         const char *clk_output_name[clk_max];
>         const char *cpu_parents[4];
> @@ -427,7 +427,6 @@ static void __init zynq_clk_setup(struct device_node *np)
>                         SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock);
> 
>         tmp = strlen("mio_clk_00x");

Is tmp used now?

> -       clk_name = kmalloc(tmp, GFP_KERNEL);
>         for (i = 0; i < NUM_MIO_PINS; i++) {
>                 int idx;
> 
> @@ -439,7 +438,6 @@ static void __init zynq_clk_setup(struct device_node *np)
>                 else
>                         can_mio_mux_parents[i] = dummy_nm;
>         }
> -       kfree(clk_name);
>         clk_register_mux(NULL, "can_mux", periph_parents, 4,
>                         CLK_SET_RATE_NO_REPARENT, SLCR_CAN_CLK_CTRL, 4, 2, 0,
>                         &canclk_lock);
> 
> Do you think the above is better?
> 

It's getting there.

WARNING: multiple messages have this Message-ID (diff)
From: Stephen Boyd <sboyd@kernel.org>
To: Michal Simek <michal.simek@amd.com>, duoming@zju.edu.cn
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	mturquette@baylibre.com
Subject: Re: [PATCH v2] clk: zynq: Prevent null pointer dereference caused by kmalloc failure
Date: Thu, 29 Feb 2024 17:22:42 -0800	[thread overview]
Message-ID: <856febae4f00b1129f695cf3c75dd380.sboyd@kernel.org> (raw)
In-Reply-To: <365f9a90.55b0.18df5394935.Coremail.duoming@zju.edu.cn>

Quoting duoming@zju.edu.cn (2024-02-29 06:16:28)
> On Thu, 29 Feb 2024 13:45:54 +0100 Michal Simek wrote:
> 
> The length of "mio_clk_00x" is 11 bytes, and the kernel will alloc 16 bytes to it.
> I use a local variable whose size is 16 bytes to replace it. The detail is shown
> below:
> 
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 7bdeaff2bfd..81d530e3357 100644
> --- a/drivers/clk/zynq/clkc.c
> +++ b/drivers/clk/zynq/clkc.c
> @@ -215,7 +215,7 @@ static void __init zynq_clk_setup(struct device_node *np)
>         int i;
>         u32 tmp;
>         int ret;
> -       char *clk_name;
> +       char clk_name[16];
>         unsigned int fclk_enable = 0;
>         const char *clk_output_name[clk_max];
>         const char *cpu_parents[4];
> @@ -427,7 +427,6 @@ static void __init zynq_clk_setup(struct device_node *np)
>                         SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock);
> 
>         tmp = strlen("mio_clk_00x");

Is tmp used now?

> -       clk_name = kmalloc(tmp, GFP_KERNEL);
>         for (i = 0; i < NUM_MIO_PINS; i++) {
>                 int idx;
> 
> @@ -439,7 +438,6 @@ static void __init zynq_clk_setup(struct device_node *np)
>                 else
>                         can_mio_mux_parents[i] = dummy_nm;
>         }
> -       kfree(clk_name);
>         clk_register_mux(NULL, "can_mux", periph_parents, 4,
>                         CLK_SET_RATE_NO_REPARENT, SLCR_CAN_CLK_CTRL, 4, 2, 0,
>                         &canclk_lock);
> 
> Do you think the above is better?
> 

It's getting there.

_______________________________________________
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-01  1:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 12:22 [PATCH v2] clk: zynq: Prevent null pointer dereference caused by kmalloc failure Duoming Zhou
2024-02-29 12:22 ` Duoming Zhou
2024-02-29 12:45 ` Michal Simek
2024-02-29 12:45   ` Michal Simek
2024-02-29 14:16   ` duoming
2024-02-29 14:16     ` duoming
2024-03-01  1:22     ` Stephen Boyd [this message]
2024-03-01  1:22       ` Stephen Boyd
2024-03-01  1:21   ` Stephen Boyd
2024-03-01  1:21     ` Stephen Boyd
2024-03-01  7:02     ` Michal Simek
2024-03-01  7:02       ` Michal Simek

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=856febae4f00b1129f695cf3c75dd380.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=duoming@zju.edu.cn \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=mturquette@baylibre.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.