lkml.org 
[lkml]   [2024]   [Feb]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2] clk: zynq: Prevent null pointer dereference caused by kmalloc failure
From


On 2/29/24 13:22, Duoming Zhou wrote:
> The kmalloc() in zynq_clk_setup() will return null if the
> physical memory has run out. As a result, if we use snprintf
> to write data to the null address, the null pointer dereference
> bug will happen.
>
> This patch adds a stack variable to replace the kmalloc().
>
> Fixes: 0ee52b157b8e ("clk: zynq: Add clock controller driver")
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
> Changes in v2:
> - Use stack variable to replace kmalloc().
>
> drivers/clk/zynq/clkc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c
> index 7bdeaff2bfd..e4c4c9adf79 100644
> --- a/drivers/clk/zynq/clkc.c
> +++ b/drivers/clk/zynq/clkc.c
> @@ -427,7 +427,7 @@ static void __init zynq_clk_setup(struct device_node *np)
> SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock);
>
> tmp = strlen("mio_clk_00x");
> - clk_name = kmalloc(tmp, GFP_KERNEL);
> + char clk_name[tmp];

I know that Stephen asked for it but variable with variable length in the middle
of code doesn't look good or useful.
I would allocate rather bigger array on stack with size bigger than max length
which will use it.

Thanks,
Michal

\
 
 \ /
  Last update: 2024-05-27 15:28    [W:0.075 / U:0.300 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site