LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use
@ 2008-02-20  0:14 Adrian Bunk
  2008-02-20  0:25 ` Harvey Harrison
  2008-02-23  7:19 ` Len Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Adrian Bunk @ 2008-02-20  0:14 UTC (permalink / raw)
  To: Zhang Rui, Thomas Sujith, Len Brown; +Cc: linux-acpi, linux-kernel

This patch fixes a check-after-use spotted by the Coverity checker.

Signed-off-by: Adrian Bunk <bunk@kernel.org>

---
570462ca4441d8d63dfd46efe6e5b2b1c251a611 diff --git a/drivers/thermal/thermal.c b/drivers/thermal/thermal.c
index e782b3e..958654b 100644
--- a/drivers/thermal/thermal.c
+++ b/drivers/thermal/thermal.c
@@ -308,10 +308,10 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	struct thermal_cooling_device_instance *pos;
 	int result;
 
-	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
+	if (!tz || !cdev)
 		return -EINVAL;
 
-	if (!tz || !cdev)
+	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
 		return -EINVAL;
 
 	dev =


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use
  2008-02-20  0:14 [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use Adrian Bunk
@ 2008-02-20  0:25 ` Harvey Harrison
  2008-02-20  0:26   ` Adrian Bunk
  2008-02-23  7:19 ` Len Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Harvey Harrison @ 2008-02-20  0:25 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: Zhang Rui, Thomas Sujith, Len Brown, linux-acpi, linux-kernel

On Wed, 2008-02-20 at 02:14 +0200, Adrian Bunk wrote:
> This patch fixes a check-after-use spotted by the Coverity checker.
> 
> Signed-off-by: Adrian Bunk <bunk@kernel.org>
> 
> ---
> 570462ca4441d8d63dfd46efe6e5b2b1c251a611 diff --git a/drivers/thermal/thermal.c b/drivers/thermal/thermal.c
> index e782b3e..958654b 100644
> --- a/drivers/thermal/thermal.c
> +++ b/drivers/thermal/thermal.c
> @@ -308,10 +308,10 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
>  	struct thermal_cooling_device_instance *pos;
>  	int result;
>  
> -	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
> +	if (!tz || !cdev)
>  		return -EINVAL;
>  
> -	if (!tz || !cdev)
> +	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
>  		return -EINVAL;
>  

How about:
	if (!tz || !cdev || trip >= tz->trips ||
	    (trip < 0 && trip != THERMAL_TRIPS_NONE))
		return -EINVAL;

Cheers,

Harvey


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use
  2008-02-20  0:25 ` Harvey Harrison
@ 2008-02-20  0:26   ` Adrian Bunk
  0 siblings, 0 replies; 4+ messages in thread
From: Adrian Bunk @ 2008-02-20  0:26 UTC (permalink / raw)
  To: Harvey Harrison
  Cc: Zhang Rui, Thomas Sujith, Len Brown, linux-acpi, linux-kernel

On Tue, Feb 19, 2008 at 04:25:02PM -0800, Harvey Harrison wrote:
> On Wed, 2008-02-20 at 02:14 +0200, Adrian Bunk wrote:
> > This patch fixes a check-after-use spotted by the Coverity checker.
> > 
> > Signed-off-by: Adrian Bunk <bunk@kernel.org>
> > 
> > ---
> > 570462ca4441d8d63dfd46efe6e5b2b1c251a611 diff --git a/drivers/thermal/thermal.c b/drivers/thermal/thermal.c
> > index e782b3e..958654b 100644
> > --- a/drivers/thermal/thermal.c
> > +++ b/drivers/thermal/thermal.c
> > @@ -308,10 +308,10 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
> >  	struct thermal_cooling_device_instance *pos;
> >  	int result;
> >  
> > -	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
> > +	if (!tz || !cdev)
> >  		return -EINVAL;
> >  
> > -	if (!tz || !cdev)
> > +	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
> >  		return -EINVAL;
> >  
> 
> How about:
> 	if (!tz || !cdev || trip >= tz->trips ||
> 	    (trip < 0 && trip != THERMAL_TRIPS_NONE))
> 		return -EINVAL;

I have no strong opinion about it, but I'd consider your suggestion less 
readable.

> Cheers,
> 
> Harvey

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use
  2008-02-20  0:14 [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use Adrian Bunk
  2008-02-20  0:25 ` Harvey Harrison
@ 2008-02-23  7:19 ` Len Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Len Brown @ 2008-02-23  7:19 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: Zhang Rui, Thomas Sujith, linux-acpi, linux-kernel

On Tuesday 19 February 2008 19:14, Adrian Bunk wrote:
> This patch fixes a check-after-use spotted by the Coverity checker.
> 
> Signed-off-by: Adrian Bunk <bunk@kernel.org>
> 
> ---
> 570462ca4441d8d63dfd46efe6e5b2b1c251a611 diff --git a/drivers/thermal/thermal.c b/drivers/thermal/thermal.c
> index e782b3e..958654b 100644
> --- a/drivers/thermal/thermal.c
> +++ b/drivers/thermal/thermal.c
> @@ -308,10 +308,10 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
>  	struct thermal_cooling_device_instance *pos;
>  	int result;
>  
> -	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
> +	if (!tz || !cdev)
>  		return -EINVAL;
>  
> -	if (!tz || !cdev)
> +	if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
>  		return -EINVAL;
>  
>  	dev =
> 
> --

this patch no longer applies because the bogus check for a programming error
was already replaced by a better check of run-time params.

thanks,
-len

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-23  7:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-20  0:14 [2.6 patch] drivers/thermal/thermal.c: fix a check-after-use Adrian Bunk
2008-02-20  0:25 ` Harvey Harrison
2008-02-20  0:26   ` Adrian Bunk
2008-02-23  7:19 ` Len Brown

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).