[PATCH] MIPS: Fixup for Pontential NULL pointer dereference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a fixup In-Reply-To Bug 200577,
where pontential null pointer dereference may occur.
Signed-off-by: Tong Chen <tongchen@xxxxxxxxxx>
---
 arch/mips/lantiq/xway/gptu.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

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;
 }
-- 
2.28.0




[Index of Archives]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux