Skip to contentSkip to conversation

mtd: spear_smi: add NULL check on devm_kzalloc() return value

PATCH Applied Gustavo A. R. Silva 2 participants 3 messages Jul 6, 2017 – Aug 17, 2017 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: spear_smi: add NULL check on devm_kzalloc() return value

Check return value from call to devm_kzalloc()
in order to prevent a NULL pointer dereference.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression x;
identifier fld;
@@

* x = devm_kzalloc(...);
... when != x == NULL
x->fld

---
 drivers/mtd/devices/spear_smi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/devices/spear_smi.c +2 -0
index dd50698..ddf4789 100644
@@ -775,6 +775,8 @@ static int spear_smi_probe_config_dt(struct platform_device *pdev,
 	pdata->board_flash_info = devm_kzalloc(&pdev->dev,
 					       sizeof(*pdata->board_flash_info),
 					       GFP_KERNEL);
+	if (!pdata->board_flash_info)
+		return -ENOMEM;
 
 	/* Fill structs for each subnode (flash device) */
 	while ((pp = of_get_next_child(np, pp))) {
Signature · 1 line
2.5.0
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Gustavo A. R. Silva

Check return value from call to devm_kzalloc()
in order to prevent a NULL pointer dereference.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression x;
identifier fld;
@@

Quoted 5 lines

* x = devm_kzalloc(...);
... when != x == NULL
x->fld

Quoted 17 lines
---
 drivers/mtd/devices/spear_smi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/devices/spear_smi.c +2 -0
index dd50698..ddf4789 100644
@@ -775,6 +775,8 @@ static int spear_smi_probe_config_dt(struct platform_device *pdev,
 	pdata->board_flash_info = devm_kzalloc(&pdev->dev,
 					       sizeof(*pdata->board_flash_info),
 					       GFP_KERNEL);
+	if (!pdata->board_flash_info)
+		return -ENOMEM;
 
 	/* Fill structs for each subnode (flash device) */
 	while ((pp = of_get_next_child(np, pp))) {
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 5 lines · Gustavo A. R. Silva

Check return value from call to devm_kzalloc()
in order to prevent a NULL pointer dereference.

This issue was detected using Coccinelle and the following semantic patch:

Quoted 9 lines

@@
expression x;
identifier fld;
@@

* x = devm_kzalloc(...);
... when != x == NULL
x->fld

Applied to l2-mtd/master.

Thanks,

Boris

Quoted 18 lines
---
 drivers/mtd/devices/spear_smi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mtd/devices/spear_smi.c +2 -0
index dd50698..ddf4789 100644
@@ -775,6 +775,8 @@ static int spear_smi_probe_config_dt(struct platform_device *pdev,
 	pdata->board_flash_info = devm_kzalloc(&pdev->dev,
 					       sizeof(*pdata->board_flash_info),
 					       GFP_KERNEL);
+	if (!pdata->board_flash_info)
+		return -ENOMEM;
 
 	/* Fill structs for each subnode (flash device) */
 	while ((pp = of_get_next_child(np, pp))) {