diff mbox

[6/12] drivers/platform/x86: Correct redundant test

Message ID Pine.LNX.4.64.0907271813490.2682@ask.diku.dk (mailing list archive)
State RFC, archived
Headers show

Commit Message

Julia Lawall July 27, 2009, 4:14 p.m. UTC
From: Julia Lawall <julia@diku.dk>

device and acpi_driver_data(device) were tested just a few lines above.

A simplified version of the semantic match that finds this problem is as
follows: (http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@r exists@
local idexpression x;
expression E;
@@

if (x == NULL || ...) { ... when forall
   return ...; }
... when != \(x=E\|x--\|x++\|--x\|++x\|x-=E\|x+=E\|x|=E\|x&=E\|&x\)
(
*x == NULL
|
*x != NULL
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/platform/x86/fujitsu-laptop.c          |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Paulo Marques July 28, 2009, 5:52 p.m. UTC | #1
Julia Lawall wrote:
> [...]
> ---
>  drivers/platform/x86/fujitsu-laptop.c          |    3 ---
>  1 files changed, 0 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index 218b9a1..5306901 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -745,9 +745,6 @@ static int acpi_fujitsu_remove(struct acpi_device *device, int type)
>  
>  	fujitsu = acpi_driver_data(device);
>  
> -	if (!device || !acpi_driver_data(device))
> -		return -EINVAL;
> -

Shouldn't this still do a:

   if (!fujitsu)
     return -EINVAL;

to avoid dereferencing a NULL pointer below?

>  	fujitsu->acpi_handle = NULL;
>  
>  	return 0;
Julia Lawall July 28, 2009, 8:11 p.m. UTC | #2
On Tue, 28 Jul 2009, Paulo Marques wrote:

> Julia Lawall wrote:
> > [...]
> > ---
> >  drivers/platform/x86/fujitsu-laptop.c          |    3 ---
> >  1 files changed, 0 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> > index 218b9a1..5306901 100644
> > --- a/drivers/platform/x86/fujitsu-laptop.c
> > +++ b/drivers/platform/x86/fujitsu-laptop.c
> > @@ -745,9 +745,6 @@ static int acpi_fujitsu_remove(struct acpi_device *device, int type)
> >  
> >  	fujitsu = acpi_driver_data(device);
> >  
> > -	if (!device || !acpi_driver_data(device))
> > -		return -EINVAL;
> > -
> 
> Shouldn't this still do a:
> 
>    if (!fujitsu)
>      return -EINVAL;

acpi_driver_data just accesses a field of its argument.  Is there a worry 
that from one call to the next it could have a different value?

Perhaps it would be better to first test !device, then initialize fujitsu, 
and then test the result of fujitsu?  The acpi_driver_data, which might 
someday do something more complicated, would only be called once.

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 218b9a1..5306901 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -745,9 +745,6 @@  static int acpi_fujitsu_remove(struct acpi_device *device, int type)
 
 	fujitsu = acpi_driver_data(device);
 
-	if (!device || !acpi_driver_data(device))
-		return -EINVAL;
-
 	fujitsu->acpi_handle = NULL;
 
 	return 0;