[PATCH] mtd: atmel_nand: fix null pointer dereference

Raphaël Poggi poggi.raph at gmail.com
Tue Sep 2 12:02:41 PDT 2014


We need to allocate pdata for device tree and non device tree probe.
In device tree probe we use pdata to fill structure member with dts data.
In non device tree probe we use the pdata to handle platform_data.

Signed-off-by: Raphaël Poggi <poggi.raph at gmail.com>
---
 drivers/mtd/nand/atmel_nand.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 910ecc3..1e7c6c6 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -1194,6 +1194,10 @@ static int __init atmel_nand_probe(struct device_d *dev)
 	if (!host)
 		return -ENOMEM;
 
+	pdata = kzalloc(sizeof(struct atmel_nand_data), GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;
+
 	host->io_base = dev_request_mem_region(dev, 0);
 
 	mtd = &host->mtd;
@@ -1206,10 +1210,6 @@ static int __init atmel_nand_probe(struct device_d *dev)
 		if (res)
 			goto err_no_card;
 	} else {
-		pdata = kzalloc(sizeof(struct atmel_nand_data), GFP_KERNEL);
-		if (!pdata)
-			return -ENOMEM;
-
 		memcpy(host->board, dev->platform_data, sizeof(struct atmel_nand_data));
 	}
 
-- 
1.8.3.2




More information about the barebox mailing list