* [PATCH] sound/soc/at32: Useless NULL test
@ 2008-09-26 13:23 Julien Brunel
2008-09-26 14:00 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Julien Brunel @ 2008-09-26 13:23 UTC (permalink / raw)
To: tiwai, liam.girdwood, broonie, linux-kernel, kernel-janitors
The test (ssc != NULL) can only be reached if the call to the function
ssc_request, the result of which ssc is assigned, succeeds. Moreover,
two statements assign NULL to ssc just before a return, which is useless
since it is a local variable. So, we suggest to delete the test and
the two assignments.
A simplified version of the semantic match that finds this problem is
as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@bad_null_test@
expression x,E;
@@
x = ssc_request(...)
... when != x = E
* x != NULL
// </smpl>
Signed-off-by: Julien Brunel <brunel@diku.dk>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
sound/soc/at32/playpaq_wm8510.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff -u -p a/sound/soc/at32/playpaq_wm8510.c b/sound/soc/at32/playpaq_wm8510.c
--- a/sound/soc/at32/playpaq_wm8510.c
+++ b/sound/soc/at32/playpaq_wm8510.c
@@ -405,7 +405,6 @@ static int __init playpaq_asoc_init(void
ssc = ssc_request(0);
if (IS_ERR(ssc)) {
ret = PTR_ERR(ssc);
- ssc = NULL;
goto err_ssc;
}
ssc_p->ssc = ssc;
@@ -476,10 +475,7 @@ err_pll0:
_gclk0 = NULL;
}
err_gclk0:
- if (ssc != NULL) {
- ssc_free(ssc);
- ssc = NULL;
- }
+ ssc_free(ssc);
err_ssc:
return ret;
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] sound/soc/at32: Useless NULL test
2008-09-26 13:23 [PATCH] sound/soc/at32: Useless NULL test Julien Brunel
@ 2008-09-26 14:00 ` Mark Brown
2008-09-26 14:45 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2008-09-26 14:00 UTC (permalink / raw)
To: Julien Brunel; +Cc: tiwai, Geoffrey Wossum, linux-kernel, kernel-janitors
On Fri, Sep 26, 2008 at 03:23:46PM +0200, Julien Brunel wrote:
> The test (ssc != NULL) can only be reached if the call to the function
> ssc_request, the result of which ssc is assigned, succeeds. Moreover,
> statements assign NULL to ssc just before a return, which is useless
> since it is a local variable. So, we suggest to delete the test and
> the two assignments.
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
For future reference if you're submitting other similar things (which I
guess you will given that you've got a tool to check for this stuff)
it'd be helpful if you could rewrite the explanation for the NULL test
to be something like:
The test (ssc != NULL) is redundant since it can only be reached
when ssc is guaranteed to have been set to a valid ssc.
which is much easier to parse.
> diff -u -p a/sound/soc/at32/playpaq_wm8510.c b/sound/soc/at32/playpaq_wm8510.c
> --- a/sound/soc/at32/playpaq_wm8510.c
> +++ b/sound/soc/at32/playpaq_wm8510.c
> @@ -405,7 +405,6 @@ static int __init playpaq_asoc_init(void
> ssc = ssc_request(0);
> if (IS_ERR(ssc)) {
> ret = PTR_ERR(ssc);
> - ssc = NULL;
> goto err_ssc;
> }
> ssc_p->ssc = ssc;
> @@ -476,10 +475,7 @@ err_pll0:
> _gclk0 = NULL;
> }
> err_gclk0:
> - if (ssc != NULL) {
> - ssc_free(ssc);
> - ssc = NULL;
> - }
> + ssc_free(ssc);
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] sound/soc/at32: Useless NULL test
2008-09-26 14:00 ` Mark Brown
@ 2008-09-26 14:45 ` Takashi Iwai
0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2008-09-26 14:45 UTC (permalink / raw)
To: Mark Brown; +Cc: Julien Brunel, Geoffrey Wossum, linux-kernel, kernel-janitors
At Fri, 26 Sep 2008 15:00:23 +0100,
Mark Brown wrote:
>
> On Fri, Sep 26, 2008 at 03:23:46PM +0200, Julien Brunel wrote:
>
> > The test (ssc != NULL) can only be reached if the call to the function
> > ssc_request, the result of which ssc is assigned, succeeds. Moreover,
> > statements assign NULL to ssc just before a return, which is useless
> > since it is a local variable. So, we suggest to delete the test and
> > the two assignments.
>
> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Applied now. Thanks.
> For future reference if you're submitting other similar things (which I
> guess you will given that you've got a tool to check for this stuff)
> it'd be helpful if you could rewrite the explanation for the NULL test
> to be something like:
>
> The test (ssc != NULL) is redundant since it can only be reached
> when ssc is guaranteed to have been set to a valid ssc.
>
> which is much easier to parse.
Agreed :)
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-26 14:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-26 13:23 [PATCH] sound/soc/at32: Useless NULL test Julien Brunel
2008-09-26 14:00 ` Mark Brown
2008-09-26 14:45 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®