diff mbox

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

Message ID 20170706222550.GA30998@embeddedgus
State Accepted
Delegated to: Boris Brezillon
Headers show

Commit Message

Gustavo A. R. Silva July 6, 2017, 10:25 p.m. UTC
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

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/mtd/devices/spear_smi.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Boris Brezillon July 17, 2017, 8:49 p.m. UTC | #1
Le Thu, 6 Jul 2017 17:25:50 -0500,
"Gustavo A. R. Silva" <garsilva@embeddedor.com> a écrit :

> 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
> 
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>

> ---
>  drivers/mtd/devices/spear_smi.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
> index dd50698..ddf4789 100644
> --- a/drivers/mtd/devices/spear_smi.c
> +++ b/drivers/mtd/devices/spear_smi.c
> @@ -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))) {
Boris Brezillon Aug. 17, 2017, 12:57 p.m. UTC | #2
Le Thu, 6 Jul 2017 17:25:50 -0500,
"Gustavo A. R. Silva" <garsilva@embeddedor.com> a écrit :

> 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
> 

Applied to l2-mtd/master.

Thanks,

Boris

> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/mtd/devices/spear_smi.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
> index dd50698..ddf4789 100644
> --- a/drivers/mtd/devices/spear_smi.c
> +++ b/drivers/mtd/devices/spear_smi.c
> @@ -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))) {
diff mbox

Patch

diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
index dd50698..ddf4789 100644
--- a/drivers/mtd/devices/spear_smi.c
+++ b/drivers/mtd/devices/spear_smi.c
@@ -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))) {