[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240229122250.24786-1-duoming@zju.edu.cn>
Date: Thu, 29 Feb 2024 20:22:50 +0800
From: Duoming Zhou <duoming@....edu.cn>
To: linux-kernel@...r.kernel.org
Cc: linux-arm-kernel@...ts.infradead.org,
linux-clk@...r.kernel.org,
michal.simek@....com,
sboyd@...nel.org,
mturquette@...libre.com,
Duoming Zhou <duoming@....edu.cn>
Subject: [PATCH v2] clk: zynq: Prevent null pointer dereference caused by kmalloc failure
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@....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];
for (i = 0; i < NUM_MIO_PINS; i++) {
int idx;
@@ -439,7 +439,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);
--
2.17.1
Powered by blists - more mailing lists