linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value
@ 2017-07-06 22:25 Gustavo A. R. Silva
  2017-07-17 20:49 ` Boris Brezillon
  2017-08-17 12:57 ` Boris Brezillon
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-06 22:25 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen
  Cc: linux-mtd, linux-kernel, 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;
@@

* 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(+)

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))) {
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value
  2017-07-06 22:25 [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value Gustavo A. R. Silva
@ 2017-07-17 20:49 ` Boris Brezillon
  2017-08-17 12:57 ` Boris Brezillon
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2017-07-17 20:49 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, linux-mtd, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value
  2017-07-06 22:25 [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value Gustavo A. R. Silva
  2017-07-17 20:49 ` Boris Brezillon
@ 2017-08-17 12:57 ` Boris Brezillon
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2017-08-17 12:57 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: David Woodhouse, Brian Norris, Marek Vasut, Richard Weinberger,
	Cyrille Pitchen, linux-mtd, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-17 12:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-06 22:25 [PATCH] mtd: spear_smi: add NULL check on devm_kzalloc() return value Gustavo A. R. Silva
2017-07-17 20:49 ` Boris Brezillon
2017-08-17 12:57 ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).