2015-12-20 11:28:35

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/4] add NULL test

Add NULL tests on various calls to kzalloc and devm_kzalloc.

The semantic match that finds these problems is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,y;
identifier fld;
@@

(
x = \(vmalloc\|kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|krealloc\|
kmemdup\|kstrdup\|
devm_kzalloc\|devm_kmalloc\|devm_kcalloc\|devm_kasprintf\|
kmalloc_array\)(...,<+... __GFP_NOFAIL ...+>,...);
|
* x = \(vmalloc\|kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|krealloc\|
kmemdup\|kstrdup\|
devm_kzalloc\|devm_kmalloc\|devm_kcalloc\|devm_kasprintf\|
kmalloc_array\)(...);
)
... when != (x) == NULL
when != (x) != NULL
when != (x) == 0
when != (x) != 0
when != x = y
(
x->fld
|
*x
|
x[...]
)
// </smpl>

---

drivers/s390/char/con3215.c | 2 ++
drivers/s390/char/raw3270.c | 2 ++
sound/soc/fsl/imx-pcm-dma.c | 2 ++
sound/soc/intel/baytrail/sst-baytrail-pcm.c | 2 ++
sound/soc/omap/omap-hdmi-audio.c | 2 ++
5 files changed, 10 insertions(+)


2015-12-20 11:29:40

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/4] ASoC: imx-pcm-dma: add NULL test

Add NULL test on call to devm_kzalloc.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x;
@@

* x = devm_kzalloc(...);
... when != x == NULL
*x
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
sound/soc/fsl/imx-pcm-dma.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c
index 1fc01ed..f3d3d1f 100644
--- a/sound/soc/fsl/imx-pcm-dma.c
+++ b/sound/soc/fsl/imx-pcm-dma.c
@@ -62,6 +62,8 @@ int imx_pcm_dma_init(struct platform_device *pdev, size_t size)

config = devm_kzalloc(&pdev->dev,
sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL);
+ if (!config)
+ return -ENOMEM;
*config = imx_dmaengine_pcm_config;
if (size)
config->prealloc_buffer_size = size;

2015-12-20 11:29:19

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 2/4] ASoC: omap-hdmi-audio: add NULL test

Add NULL test on call to devm_kzalloc.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x;
identifier fld;
@@

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

Signed-off-by: Julia Lawall <[email protected]>

---
sound/soc/omap/omap-hdmi-audio.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sound/soc/omap/omap-hdmi-audio.c b/sound/soc/omap/omap-hdmi-audio.c
index 584b237..f83cc2b 100644
--- a/sound/soc/omap/omap-hdmi-audio.c
+++ b/sound/soc/omap/omap-hdmi-audio.c
@@ -368,6 +368,8 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev)
card->owner = THIS_MODULE;
card->dai_link =
devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL);
+ if (!card->dai_link)
+ return -ENOMEM;
card->dai_link->name = card->name;
card->dai_link->stream_name = card->name;
card->dai_link->cpu_dai_name = dev_name(ad->dssdev);

2015-12-20 11:28:53

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 3/4] s390/cio: add NULL test

Add NULL test on call to kzalloc.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x;
identifier fld;
@@

* x = kzalloc(...);
... when != x == NULL
x->fld
// </smpl>

Signed-off-by: Julia Lawall <[email protected]>

---
drivers/s390/char/con3215.c | 2 ++
1 files changed, 2 insertions(+)

diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 0fc3fe5..7d82bbc 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -922,6 +922,8 @@ static int __init con3215_init(void)
spin_lock_init(&raw3215_freelist_lock);
for (i = 0; i < NR_3215_REQ; i++) {
req = kzalloc(sizeof(struct raw3215_req), GFP_KERNEL | GFP_DMA);
+ if (!req)
+ return -ENOMEM;
req->next = raw3215_freelist;
raw3215_freelist = req;
}

2015-12-20 11:28:37

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 4/4] ASoC: Intel: add NULL test

Add NULL test on call to devm_kzalloc.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x;
identifier fld;
@@

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

Signed-off-by: Julia Lawall <[email protected]>

---
sound/soc/intel/baytrail/sst-baytrail-pcm.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sound/soc/intel/baytrail/sst-baytrail-pcm.c b/sound/soc/intel/baytrail/sst-baytrail-pcm.c
index 79547be..4765ad4 100644
--- a/sound/soc/intel/baytrail/sst-baytrail-pcm.c
+++ b/sound/soc/intel/baytrail/sst-baytrail-pcm.c
@@ -377,6 +377,8 @@ static int sst_byt_pcm_probe(struct snd_soc_platform *platform)

priv_data = devm_kzalloc(platform->dev, sizeof(*priv_data),
GFP_KERNEL);
+ if (!priv_data)
+ return -ENOMEM;
priv_data->byt = plat_data->dsp;
snd_soc_platform_set_drvdata(platform, priv_data);

2015-12-21 07:34:37

by Nicolin Chen

[permalink] [raw]
Subject: Re: [PATCH 1/4] ASoC: imx-pcm-dma: add NULL test

On Sun, Dec 20, 2015 at 12:15:50PM +0100, Julia Lawall wrote:
> Add NULL test on call to devm_kzalloc.
>
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x;
> @@
>
> * x = devm_kzalloc(...);
> ... when != x == NULL
> *x
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>

Acked-by: Nicolin Chen <[email protected]>

Thank you

>
> ---
> sound/soc/fsl/imx-pcm-dma.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c
> index 1fc01ed..f3d3d1f 100644
> --- a/sound/soc/fsl/imx-pcm-dma.c
> +++ b/sound/soc/fsl/imx-pcm-dma.c
> @@ -62,6 +62,8 @@ int imx_pcm_dma_init(struct platform_device *pdev, size_t size)
>
> config = devm_kzalloc(&pdev->dev,
> sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL);
> + if (!config)
> + return -ENOMEM;
> *config = imx_dmaengine_pcm_config;
> if (size)
> config->prealloc_buffer_size = size;
>

2015-12-21 09:33:49

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 3/4] s390/cio: add NULL test

On Sun, Dec 20, 2015 at 12:15:52PM +0100, Julia Lawall wrote:
> Add NULL test on call to kzalloc.
>
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x;
> identifier fld;
> @@
>
> * x = kzalloc(...);
> ... when != x == NULL
> x->fld
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>

Aplied, thanks.

2015-12-21 09:35:46

by Peter Ujfalusi

[permalink] [raw]
Subject: Re: [PATCH 2/4] ASoC: omap-hdmi-audio: add NULL test

On 12/20/2015 01:15 PM, Julia Lawall wrote:
> Add NULL test on call to devm_kzalloc.
>
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x;
> identifier fld;
> @@
>
> * x = devm_kzalloc(...);
> ... when != x == NULL
> x->fld
> // </smpl>
>
> Signed-off-by: Julia Lawall <[email protected]>

Acked-by: Peter Ujfalusi <[email protected]>

> ---
> sound/soc/omap/omap-hdmi-audio.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/sound/soc/omap/omap-hdmi-audio.c b/sound/soc/omap/omap-hdmi-audio.c
> index 584b237..f83cc2b 100644
> --- a/sound/soc/omap/omap-hdmi-audio.c
> +++ b/sound/soc/omap/omap-hdmi-audio.c
> @@ -368,6 +368,8 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev)
> card->owner = THIS_MODULE;
> card->dai_link =
> devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL);
> + if (!card->dai_link)
> + return -ENOMEM;
> card->dai_link->name = card->name;
> card->dai_link->stream_name = card->name;
> card->dai_link->cpu_dai_name = dev_name(ad->dssdev);
>


--
P?ter

2015-12-23 00:02:58

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 4/4] ASoC: Intel: add NULL test

On Sun, Dec 20, 2015 at 12:15:53PM +0100, Julia Lawall wrote:
> Add NULL test on call to devm_kzalloc.
>
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)

If there was a patch 3 in this series I seem to be missing it.


Attachments:
(No filename) (261.00 B)
signature.asc (473.00 B)
Download all attachments

2015-12-23 06:58:15

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 4/4] ASoC: Intel: add NULL test



On Wed, 23 Dec 2015, Mark Brown wrote:

> On Sun, Dec 20, 2015 at 12:15:53PM +0100, Julia Lawall wrote:
> > Add NULL test on call to devm_kzalloc.
> >
> > The semantic match that finds this problem is as follows:
> > (http://coccinelle.lip6.fr/)
>
> If there was a patch 3 in this series I seem to be missing it.

It's not for you (drivers/s390/char/con3215.c). Sorry for the confusion.

julia