[alsa-devel] [PATCH 3/4] sound/soc/mxs/mxs-saif.c: add missing kfree
From: Julia Lawall julia@diku.dk
The error handling code prior to get_clk also needs to call kfree. The label name is changed to reflect its more general use.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x * return ...; } ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
--- sound/soc/mxs/mxs-saif.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..4a17bc8 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -523,8 +523,10 @@ static int mxs_saif_probe(struct platform_device *pdev) if (!saif) return -ENOMEM;
- if (pdev->id >= ARRAY_SIZE(mxs_saif)) - return -EINVAL; + if (pdev->id >= ARRAY_SIZE(mxs_saif)) { + ret = -EINVAL; + goto failed; + } mxs_saif[pdev->id] = saif;
saif->clk = clk_get(&pdev->dev, NULL); @@ -532,7 +534,7 @@ static int mxs_saif_probe(struct platform_device *pdev) ret = PTR_ERR(saif->clk); dev_err(&pdev->dev, "Cannot get the clock: %d\n", ret); - goto failed_clk; + goto failed; }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -625,7 +627,7 @@ failed_ioremap: release_mem_region(res->start, resource_size(res)); failed_get_resource: clk_put(saif->clk); -failed_clk: +failed: kfree(saif);
return ret;
On Sat, Aug 20, 2011 at 08:12:40AM +0200, Julia Lawall wrote:
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..4a17bc8 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -523,8 +523,10 @@ static int mxs_saif_probe(struct platform_device *pdev) if (!saif) return -ENOMEM;
- if (pdev->id >= ARRAY_SIZE(mxs_saif))
return -EINVAL;
- if (pdev->id >= ARRAY_SIZE(mxs_saif)) {
ret = -EINVAL;
goto failed;
- } mxs_saif[pdev->id] = saif;
Thanks, Julia. May I suggest to simple move the id-check before the allocation?
Regards,
Wolfram
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x * return ...; } ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
--- diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..e9a90e4 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -519,12 +519,11 @@ static int mxs_saif_probe(struct platform_device *pdev) struct mxs_saif *saif; int ret = 0;
+ if (pdev->id >= ARRAY_SIZE(mxs_saif)) + return -EINVAL; saif = kzalloc(sizeof(*saif), GFP_KERNEL); if (!saif) return -ENOMEM; - - if (pdev->id >= ARRAY_SIZE(mxs_saif)) - return -EINVAL; mxs_saif[pdev->id] = saif;
saif->clk = clk_get(&pdev->dev, NULL);
-----Original Message----- From: Julia Lawall [mailto:julia@diku.dk] Sent: Saturday, August 20, 2011 11:19 PM To: Wolfram Sang Cc: Liam Girdwood; kernel-janitors@vger.kernel.org; Mark Brown; Jaroslav Kysela; Takashi Iwai; Dong Aisheng-B29396; alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] sound/soc/mxs/mxs-saif.c: add missing kfree
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x
- return ...;
} ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..e9a90e4 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -519,12 +519,11 @@ static int mxs_saif_probe(struct platform_device *pdev) struct mxs_saif *saif; int ret = 0;
- if (pdev->id >= ARRAY_SIZE(mxs_saif))
saif = kzalloc(sizeof(*saif), GFP_KERNEL); if (!saif) return -ENOMEM;return -EINVAL;
if (pdev->id >= ARRAY_SIZE(mxs_saif))
return -EINVAL;
mxs_saif[pdev->id] = saif;
saif->clk = clk_get(&pdev->dev, NULL);
Thanks for the finding, Julia. It's ok to me.
BTW I guess you may need to resend a new version patch instead of following it in this mail thread. :) If yes, one minus thing, add one blank line below the line of 'return -ENOMEM' may look more comfortable.
Regards Dong Aisheng
On Sun, 21 Aug 2011, Dong Aisheng-B29396 wrote:
-----Original Message----- From: Julia Lawall [mailto:julia@diku.dk] Sent: Saturday, August 20, 2011 11:19 PM To: Wolfram Sang Cc: Liam Girdwood; kernel-janitors@vger.kernel.org; Mark Brown; Jaroslav Kysela; Takashi Iwai; Dong Aisheng-B29396; alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] sound/soc/mxs/mxs-saif.c: add missing kfree
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x
- return ...;
} ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..e9a90e4 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -519,12 +519,11 @@ static int mxs_saif_probe(struct platform_device *pdev) struct mxs_saif *saif; int ret = 0;
- if (pdev->id >= ARRAY_SIZE(mxs_saif))
saif = kzalloc(sizeof(*saif), GFP_KERNEL); if (!saif) return -ENOMEM;return -EINVAL;
if (pdev->id >= ARRAY_SIZE(mxs_saif))
return -EINVAL;
mxs_saif[pdev->id] = saif;
saif->clk = clk_get(&pdev->dev, NULL);
Thanks for the finding, Julia. It's ok to me.
BTW I guess you may need to resend a new version patch instead of following it in this mail thread. :) If yes, one minus thing, add one blank line below the line of 'return -ENOMEM' may look more comfortable.
OK, I will do both.
Thanks, julia
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x * return ...; } ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
--- sound/soc/mxs/mxs-saif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..ab453ca 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -519,12 +519,13 @@ static int mxs_saif_probe(struct platform_device *pdev) struct mxs_saif *saif; int ret = 0;
+ if (pdev->id >= ARRAY_SIZE(mxs_saif)) + return -EINVAL; + saif = kzalloc(sizeof(*saif), GFP_KERNEL); if (!saif) return -ENOMEM;
- if (pdev->id >= ARRAY_SIZE(mxs_saif)) - return -EINVAL; mxs_saif[pdev->id] = saif;
saif->clk = clk_get(&pdev->dev, NULL);
On Sun, Aug 21, 2011 at 01:18:45PM +0200, Julia Lawall wrote:
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x
- return ...;
} ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
Reviewed-by: Wolfram Sang w.sang@pengutronix.de
-----Original Message----- From: Julia Lawall [mailto:julia@diku.dk] Sent: Sunday, August 21, 2011 7:19 PM To: Dong Aisheng-B29396 Cc: Wolfram Sang; Liam Girdwood; kernel-janitors@vger.kernel.org; Mark Brown; Jaroslav Kysela; Takashi Iwai; alsa-devel@alsa-project.org; linux- kernel@vger.kernel.org Subject: [PATCH] sound/soc/mxs/mxs-saif.c: add missing kfree
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x
- return ...;
} ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
sound/soc/mxs/mxs-saif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c index 0b3adae..ab453ca 100644 --- a/sound/soc/mxs/mxs-saif.c +++ b/sound/soc/mxs/mxs-saif.c @@ -519,12 +519,13 @@ static int mxs_saif_probe(struct platform_device *pdev) struct mxs_saif *saif; int ret = 0;
- if (pdev->id >= ARRAY_SIZE(mxs_saif))
return -EINVAL;
- saif = kzalloc(sizeof(*saif), GFP_KERNEL); if (!saif) return -ENOMEM;
if (pdev->id >= ARRAY_SIZE(mxs_saif))
return -EINVAL;
mxs_saif[pdev->id] = saif;
saif->clk = clk_get(&pdev->dev, NULL);
Acked-by: Dong Aisheng b29396@freescale.com
Regards Dong Aisheng
On 21/08/11 12:18, Julia Lawall wrote:
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/)
// <smpl> @@ identifier x; expression E1!=0,E2,E3,E4; statement S; iterator I; @@
( if (...) { ... when != kfree(x) when != x = E3 when != E3 = x
- return ...;
} ... when != x = E2 when != I(...,x,...) S if (...) { ... when != x = E4 kfree(x); ... return ...; } ) // </smpl>
Signed-off-by: Julia Lawall julia@diku.dk
Acked-by: Liam Girdwood lrg@ti.com
On Sun, Aug 21, 2011 at 01:18:45PM +0200, Julia Lawall wrote:
From: Julia Lawall julia@diku.dk
Move the test on pdev->id before the kzalloc to avoid requiring kfree when the test fails. This fix was suggested by Wolfram Sang.
Applied, thanks.
participants (5)
-
Dong Aisheng-B29396
-
Julia Lawall
-
Liam Girdwood
-
Mark Brown
-
Wolfram Sang