Skip to contentSkip to conversation

MIPS: lantiq: check the return value of kzalloc()

PATCH Applied [email protected] 2 participants 2 messages Mar 25, 2022 – Mar 30, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: lantiq: check the return value of kzalloc()

From: Xiaoke Wang <[email protected]>

kzalloc() is a memory allocation function which can return NULL when some internal memory errors happen. So it is better to check the return value of it to prevent potential wrong memory access or memory leak.

---
 arch/mips/lantiq/falcon/sysctrl.c |  2 ++
 arch/mips/lantiq/xway/gptu.c      |  2 ++
 arch/mips/lantiq/xway/sysctrl.c   | 46 ++++++++++++++++++++-----------
 3 files changed, 34 insertions(+), 16 deletions(-)
arch/mips/lantiq/falcon/sysctrl.c +2 -0
index 42222f8..446a253 100644
@@ -167,6 +167,8 @@ static inline void clkdev_add_sys(const char *dev, unsigned int module,
 {
 	struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL);
 
+	if (!clk)
+		return;
 	clk->cl.dev_id = dev;
 	clk->cl.con_id = NULL;
 	clk->cl.clk = clk;
arch/mips/lantiq/xway/gptu.c +2 -0
index 3d5683e..200fe9f 100644
@@ -122,6 +122,8 @@ static inline void clkdev_add_gptu(struct device *dev, const char *con,
 {
 	struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL);
 
+	if (!clk)
+		return;
 	clk->cl.dev_id = dev_name(dev);
 	clk->cl.con_id = con;
 	clk->cl.clk = clk;
arch/mips/lantiq/xway/sysctrl.c +30 -16

75 lines not on this page · raw message

maintainer Applied
#1 lore raw
Quoted 7 lines · On Fri, Mar 25, 2022 at 07:49:41PM +0800, [email protected] wrote:

From: Xiaoke Wang <[email protected]>

kzalloc() is a memory allocation function which can return NULL when some internal memory errors happen. So it is better to check the return value of it to prevent potential wrong memory access or memory leak.

Quoted 6 lines
---
 arch/mips/lantiq/falcon/sysctrl.c |  2 ++
 arch/mips/lantiq/xway/gptu.c      |  2 ++
 arch/mips/lantiq/xway/sysctrl.c   | 46 ++++++++++++++++++++-----------
 3 files changed, 34 insertions(+), 16 deletions(-)

applied to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]