linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] da9052-battery: don't free IRQ that wasn't requested
@ 2012-09-05 12:34 Dan Carpenter
  2012-09-05 14:11 ` walter harms
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2012-09-05 12:34 UTC (permalink / raw)
  To: Ashish Jangam
  Cc: Anton Vorontsov, David Woodhouse, linux-kernel, kernel-janitors

We should decrement "i" before doing the free_irq().  If we call this
because request_threaded_irq() failed then we don't want to free the
thing which failed.  Or in the case where we get here because
power_supply_register() failed then the original codes does a read past
the end of the array.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/power/da9052-battery.c b/drivers/power/da9052-battery.c
index 20b86ed..d9d034d 100644
--- a/drivers/power/da9052-battery.c
+++ b/drivers/power/da9052-battery.c
@@ -623,7 +623,7 @@ static s32 __devinit da9052_bat_probe(struct platform_device *pdev)
 	return 0;
 
 err:
-	for (; i >= 0; i--) {
+	while (--i >= 0) {
 		irq = platform_get_irq_byname(pdev, da9052_bat_irqs[i]);
 		free_irq(bat->da9052->irq_base + irq, bat);
 	}

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

* Re: [patch] da9052-battery: don't free IRQ that wasn't requested
  2012-09-05 12:34 [patch] da9052-battery: don't free IRQ that wasn't requested Dan Carpenter
@ 2012-09-05 14:11 ` walter harms
  2012-09-06 15:07   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: walter harms @ 2012-09-05 14:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Ashish Jangam, Anton Vorontsov, David Woodhouse, linux-kernel,
	kernel-janitors



Am 05.09.2012 14:34, schrieb Dan Carpenter:
> We should decrement "i" before doing the free_irq().  If we call this
> because request_threaded_irq() failed then we don't want to free the
> thing which failed.  Or in the case where we get here because
> power_supply_register() failed then the original codes does a read past
> the end of the array.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/power/da9052-battery.c b/drivers/power/da9052-battery.c
> index 20b86ed..d9d034d 100644
> --- a/drivers/power/da9052-battery.c
> +++ b/drivers/power/da9052-battery.c
> @@ -623,7 +623,7 @@ static s32 __devinit da9052_bat_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err:
> -	for (; i >= 0; i--) {
> +	while (--i >= 0) {
>  		irq = platform_get_irq_byname(pdev, da9052_bat_irqs[i]);
>  		free_irq(bat->da9052->irq_base + irq, bat);
>  	}

hi da,
(my usual nitpicking ...)
since a lot of people do make mistakes on count-down-loops, is there any chance to
make this a common count-up-for()-loop ?
like:
   for (j=0; j <= i ;j++ ) {
	irq = platform_get_irq_byname(pdev, da9052_bat_irqs[j]);
	free_irq(bat->da9052->irq_base + irq, bat);
	}

re,
 wh

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

* Re: [patch] da9052-battery: don't free IRQ that wasn't requested
  2012-09-05 14:11 ` walter harms
@ 2012-09-06 15:07   ` Dan Carpenter
  2012-09-20 22:02     ` Anton Vorontsov
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2012-09-06 15:07 UTC (permalink / raw)
  To: walter harms
  Cc: Ashish Jangam, Anton Vorontsov, David Woodhouse, linux-kernel,
	kernel-janitors

On Wed, Sep 05, 2012 at 04:11:01PM +0200, walter harms wrote:
> 
> 
> Am 05.09.2012 14:34, schrieb Dan Carpenter:
> > We should decrement "i" before doing the free_irq().  If we call this
> > because request_threaded_irq() failed then we don't want to free the
> > thing which failed.  Or in the case where we get here because
> > power_supply_register() failed then the original codes does a read past
> > the end of the array.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/power/da9052-battery.c b/drivers/power/da9052-battery.c
> > index 20b86ed..d9d034d 100644
> > --- a/drivers/power/da9052-battery.c
> > +++ b/drivers/power/da9052-battery.c
> > @@ -623,7 +623,7 @@ static s32 __devinit da9052_bat_probe(struct platform_device *pdev)
> >  	return 0;
> >  
> >  err:
> > -	for (; i >= 0; i--) {
> > +	while (--i >= 0) {
> >  		irq = platform_get_irq_byname(pdev, da9052_bat_irqs[i]);
> >  		free_irq(bat->da9052->irq_base + irq, bat);
> >  	}
> 
> hi da,
> (my usual nitpicking ...)

Ha ha.  Your nit picks are welcome even if I don't always agree.

> since a lot of people do make mistakes on count-down-loops, is there any chance to
> make this a common count-up-for()-loop ?
> like:

I like the count down loops...  It feels very natural to unwind that
way.

>    for (j=0; j <= i ;j++ ) {
               ^^^^^^
The count up loops are prone to the exact same off by one bugs.  ;)
You've got one in your sample code.  Plus I'd have to declare
another variable and send a v2 patch and I am very lazy...  So in
this case I think should just take my original patch.

regards,
dan carpenter


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

* Re: [patch] da9052-battery: don't free IRQ that wasn't requested
  2012-09-06 15:07   ` Dan Carpenter
@ 2012-09-20 22:02     ` Anton Vorontsov
  0 siblings, 0 replies; 4+ messages in thread
From: Anton Vorontsov @ 2012-09-20 22:02 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: walter harms, Ashish Jangam, David Woodhouse, linux-kernel,
	kernel-janitors

On Thu, Sep 06, 2012 at 08:07:58AM -0700, Dan Carpenter wrote:
[...]
> >    for (j=0; j <= i ;j++ ) {
>                ^^^^^^
> The count up loops are prone to the exact same off by one bugs.  ;)
> You've got one in your sample code.  Plus I'd have to declare
> another variable and send a v2 patch and I am very lazy...  So in
> this case I think should just take my original patch.

Applied, thank you!

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

end of thread, other threads:[~2012-09-20 22:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-05 12:34 [patch] da9052-battery: don't free IRQ that wasn't requested Dan Carpenter
2012-09-05 14:11 ` walter harms
2012-09-06 15:07   ` Dan Carpenter
2012-09-20 22:02     ` Anton Vorontsov

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