diff mbox series

MIPS: Fixup for Pontential NULL pointer dereference

Message ID 20200901045530.12969-1-tongchen@whu.edu.cn (mailing list archive)
State New
Headers show
Series MIPS: Fixup for Pontential NULL pointer dereference | expand

Commit Message

Tong Chen Sept. 1, 2020, 4:55 a.m. UTC
This is a fixup In-Reply-To Bug 200577,
where pontential null pointer dereference may occur.
Signed-off-by: Tong Chen <tongchen@whu.edu.cn>
---
 arch/mips/lantiq/xway/gptu.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/arch/mips/lantiq/xway/gptu.c b/arch/mips/lantiq/xway/gptu.c
index 3d5683e75cf1..3c4253e64541 100644
--- a/arch/mips/lantiq/xway/gptu.c
+++ b/arch/mips/lantiq/xway/gptu.c
@@ -117,11 +117,12 @@  static void gptu_disable(struct clk *clk)
 	free_irq(irqres[clk->bits].start, NULL);
 }
 
-static inline void clkdev_add_gptu(struct device *dev, const char *con,
+static inline int clkdev_add_gptu(struct device *dev, const char *con,
 							unsigned int timer)
 {
 	struct clk *clk = kzalloc(sizeof(struct clk), GFP_KERNEL);
-
+	if (!clk)
+		return 0;
 	clk->cl.dev_id = dev_name(dev);
 	clk->cl.con_id = con;
 	clk->cl.clk = clk;
@@ -129,12 +130,14 @@  static inline void clkdev_add_gptu(struct device *dev, const char *con,
 	clk->disable = gptu_disable;
 	clk->bits = timer;
 	clkdev_add(&clk->cl);
+	return 1;
 }
 
 static int gptu_probe(struct platform_device *pdev)
 {
 	struct clk *clk;
 	struct resource *res;
+	int clk_num = 0;
 
 	if (of_irq_to_resource_table(pdev->dev.of_node, irqres, 6) != 6) {
 		dev_err(&pdev->dev, "Failed to get IRQ list\n");
@@ -169,14 +172,14 @@  static int gptu_probe(struct platform_device *pdev)
 	}
 
 	/* register the clocks */
-	clkdev_add_gptu(&pdev->dev, "timer1a", TIMER1A);
-	clkdev_add_gptu(&pdev->dev, "timer1b", TIMER1B);
-	clkdev_add_gptu(&pdev->dev, "timer2a", TIMER2A);
-	clkdev_add_gptu(&pdev->dev, "timer2b", TIMER2B);
-	clkdev_add_gptu(&pdev->dev, "timer3a", TIMER3A);
-	clkdev_add_gptu(&pdev->dev, "timer3b", TIMER3B);
-
-	dev_info(&pdev->dev, "gptu: 6 timers loaded\n");
+	clk_num += clkdev_add_gptu(&pdev->dev, "timer1a", TIMER1A);
+	clk_num += clkdev_add_gptu(&pdev->dev, "timer1b", TIMER1B);
+	clk_num += clkdev_add_gptu(&pdev->dev, "timer2a", TIMER2A);
+	clk_num += clkdev_add_gptu(&pdev->dev, "timer2b", TIMER2B);
+	clk_num += clkdev_add_gptu(&pdev->dev, "timer3a", TIMER3A);
+	clk_num += clkdev_add_gptu(&pdev->dev, "timer3b", TIMER3B);
+
+	dev_info(&pdev->dev, "gptu: %d timers loaded\n", clk_num);
 
 	return 0;
 }