1 |
From ecdc999aa5958d131b1da277eeeaf487ed8fb676 Mon Sep 17 00:00:00 2001 |
2 |
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com> |
3 |
Date: Tue, 18 Sep 2018 08:55:55 -0500 |
4 |
Subject: [PATCH 038/145] mtd: rawnand: atmel: Fix potential NULL pointer |
5 |
dereference |
6 |
|
7 |
[ Upstream commit fbed20280d912449cfb40c382cb55e3d11502587 ] |
8 |
|
9 |
There is a potential execution path in which function |
10 |
of_find_compatible_node() returns NULL. In such a case, |
11 |
we end up having a NULL pointer dereference when accessing |
12 |
pointer *nfc_np* in function of_clk_get(). |
13 |
|
14 |
So, we better don't take any chances and fix this by null |
15 |
checking pointer *nfc_np* before calling of_clk_get(). |
16 |
|
17 |
Addresses-Coverity-ID: 1473052 ("Dereference null return value") |
18 |
Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver") |
19 |
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> |
20 |
Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com> |
21 |
Acked-by: Tudor Ambarus <tudor.ambarus@microchip.com> |
22 |
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> |
23 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
24 |
--- |
25 |
drivers/mtd/nand/raw/atmel/nand-controller.c | 4 ++++ |
26 |
1 file changed, 4 insertions(+) |
27 |
|
28 |
diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c |
29 |
index a068b214ebaa..a594fb1e9a99 100644 |
30 |
--- a/drivers/mtd/nand/raw/atmel/nand-controller.c |
31 |
+++ b/drivers/mtd/nand/raw/atmel/nand-controller.c |
32 |
@@ -2063,6 +2063,10 @@ atmel_hsmc_nand_controller_legacy_init(struct atmel_hsmc_nand_controller *nc) |
33 |
nand_np = dev->of_node; |
34 |
nfc_np = of_find_compatible_node(dev->of_node, NULL, |
35 |
"atmel,sama5d3-nfc"); |
36 |
+ if (!nfc_np) { |
37 |
+ dev_err(dev, "Could not find device node for sama5d3-nfc\n"); |
38 |
+ return -ENODEV; |
39 |
+ } |
40 |
|
41 |
nc->clk = of_clk_get(nfc_np, 0); |
42 |
if (IS_ERR(nc->clk)) { |
43 |
-- |
44 |
2.19.1 |
45 |
|