* [PATCH] drivers: acpi: fan.c move a dereference below the NULL test
@ 2010-02-11 9:56 Darren Jenkins
2010-02-19 5:27 ` Len Brown
0 siblings, 1 reply; 4+ messages in thread
From: Darren Jenkins @ 2010-02-11 9:56 UTC (permalink / raw)
To: Len Brown
Cc: Zhang Rui, Thomas Renninger, Alexey Dobriyan, Matthew Garrett,
linux ACPI, Linux Kernel Mailing List, Kernel Janitors
In acpi_fan_remove() device is being dereferenced before the NULL test.
This reorders the code to ensure it is checked for NULL first.
Coverity CID: 2758
Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>
---
drivers/acpi/fan.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index acf2ab2..dc39640 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device *device)
static int acpi_fan_remove(struct acpi_device *device, int type)
{
- struct thermal_cooling_device *cdev = acpi_driver_data(device);
+ struct thermal_cooling_device *cdev;
+
+ if (!device)
+ return -EINVAL;
+
+ cdev = acpi_driver_data(device);
- if (!device || !cdev)
+ if (!cdev)
return -EINVAL;
acpi_fan_remove_fs(device);
--
1.6.3.3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] drivers: acpi: fan.c move a dereference below the NULL test
2010-02-11 9:56 [PATCH] drivers: acpi: fan.c move a dereference below the NULL test Darren Jenkins
@ 2010-02-19 5:27 ` Len Brown
2010-02-19 11:02 ` Thomas Renninger
2010-02-22 1:37 ` Zhang Rui
0 siblings, 2 replies; 4+ messages in thread
From: Len Brown @ 2010-02-19 5:27 UTC (permalink / raw)
To: Darren Jenkins
Cc: Zhang Rui, Thomas Renninger, Alexey Dobriyan, Matthew Garrett,
linux ACPI, Linux Kernel Mailing List, Kernel Janitors
I think think this is a run-time check for a programming error,
and the current fashion is to delete the check and take a fault
if this happens so the caller can be fixed.
There are a couple of checks like this in fan.c --
perhaps Rui can clean them up when he comes back next week.
thanks,
Len Brown, Intel Open Source Technology Center
On Thu, 11 Feb 2010, Darren Jenkins wrote:
> In acpi_fan_remove() device is being dereferenced before the NULL test.
> This reorders the code to ensure it is checked for NULL first.
>
> Coverity CID: 2758
>
> Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>
> ---
> drivers/acpi/fan.c | 9 +++++++--
> 1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
> index acf2ab2..dc39640 100644
> --- a/drivers/acpi/fan.c
> +++ b/drivers/acpi/fan.c
> @@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device *device)
>
> static int acpi_fan_remove(struct acpi_device *device, int type)
> {
> - struct thermal_cooling_device *cdev = acpi_driver_data(device);
> + struct thermal_cooling_device *cdev;
> +
> + if (!device)
> + return -EINVAL;
> +
> + cdev = acpi_driver_data(device);
>
> - if (!device || !cdev)
> + if (!cdev)
> return -EINVAL;
>
> acpi_fan_remove_fs(device);
> --
> 1.6.3.3
>
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] drivers: acpi: fan.c move a dereference below the NULL test
2010-02-19 5:27 ` Len Brown
@ 2010-02-19 11:02 ` Thomas Renninger
2010-02-22 1:37 ` Zhang Rui
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Renninger @ 2010-02-19 11:02 UTC (permalink / raw)
To: Len Brown
Cc: Darren Jenkins, Zhang Rui, Alexey Dobriyan, Matthew Garrett,
linux ACPI, Linux Kernel Mailing List, Kernel Janitors
On Friday 19 February 2010 06:27:46 Len Brown wrote:
> I think think this is a run-time check for a programming error,
> and the current fashion is to delete the check and take a fault
> if this happens so the caller can be fixed.
>
> There are a couple of checks like this in fan.c --
> perhaps Rui can clean them up when he comes back next week.
Please let us clean this up first and remove:
static inline void *acpi_driver_data(struct acpi_device *d)
{
return d->driver_data;
}
This has nothing to do with acpica code, it's in kernel code only.
Is there a reason for above abstraction?
If not, it's error prone and really should get eliminated.
Thomas
> thanks,
> Len Brown, Intel Open Source Technology Center
>
> On Thu, 11 Feb 2010, Darren Jenkins wrote:
>
> > In acpi_fan_remove() device is being dereferenced before the NULL
test.
> > This reorders the code to ensure it is checked for NULL first.
> >
> > Coverity CID: 2758
> >
> > Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>
> > ---
> > drivers/acpi/fan.c | 9 +++++++--
> > 1 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
> > index acf2ab2..dc39640 100644
> > --- a/drivers/acpi/fan.c
> > +++ b/drivers/acpi/fan.c
> > @@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device
*device)
> >
> > static int acpi_fan_remove(struct acpi_device *device, int type)
> > {
> > - struct thermal_cooling_device *cdev = acpi_driver_data(device);
> > + struct thermal_cooling_device *cdev;
> > +
> > + if (!device)
> > + return -EINVAL;
> > +
> > + cdev = acpi_driver_data(device);
> >
> > - if (!device || !cdev)
> > + if (!cdev)
> > return -EINVAL;
> >
> > acpi_fan_remove_fs(device);
> > --
> > 1.6.3.3
> >
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-
kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] drivers: acpi: fan.c move a dereference below the NULL test
2010-02-19 5:27 ` Len Brown
2010-02-19 11:02 ` Thomas Renninger
@ 2010-02-22 1:37 ` Zhang Rui
1 sibling, 0 replies; 4+ messages in thread
From: Zhang Rui @ 2010-02-22 1:37 UTC (permalink / raw)
To: Len Brown
Cc: Darren Jenkins, Thomas Renninger, Alexey Dobriyan,
Matthew Garrett, linux ACPI, Linux Kernel Mailing List,
Kernel Janitors
On Fri, 2010-02-19 at 13:27 +0800, Len Brown wrote:
> I think think this is a run-time check for a programming error,
> and the current fashion is to delete the check and take a fault
> if this happens so the caller can be fixed.
>
I agree.
> There are a couple of checks like this in fan.c --
> perhaps Rui can clean them up when he comes back next week.
>
I'll send the cleanup patch later.
thanks,
rui
> thanks,
> Len Brown, Intel Open Source Technology Center
>
> On Thu, 11 Feb 2010, Darren Jenkins wrote:
>
> > In acpi_fan_remove() device is being dereferenced before the NULL test.
> > This reorders the code to ensure it is checked for NULL first.
> >
> > Coverity CID: 2758
> >
> > Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>
> > ---
> > drivers/acpi/fan.c | 9 +++++++--
> > 1 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
> > index acf2ab2..dc39640 100644
> > --- a/drivers/acpi/fan.c
> > +++ b/drivers/acpi/fan.c
> > @@ -298,9 +298,14 @@ static int acpi_fan_add(struct acpi_device *device)
> >
> > static int acpi_fan_remove(struct acpi_device *device, int type)
> > {
> > - struct thermal_cooling_device *cdev = acpi_driver_data(device);
> > + struct thermal_cooling_device *cdev;
> > +
> > + if (!device)
> > + return -EINVAL;
> > +
> > + cdev = acpi_driver_data(device);
> >
> > - if (!device || !cdev)
> > + if (!cdev)
> > return -EINVAL;
> >
> > acpi_fan_remove_fs(device);
> > --
> > 1.6.3.3
> >
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-22 1:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-11 9:56 [PATCH] drivers: acpi: fan.c move a dereference below the NULL test Darren Jenkins
2010-02-19 5:27 ` Len Brown
2010-02-19 11:02 ` Thomas Renninger
2010-02-22 1:37 ` Zhang Rui
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).