da9052-battery: don't free IRQ that wasn't requested
PATCH 1/1 da9052-battery: don't free IRQ that wasn't requested
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.
drivers/power/da9052-battery.c +1 -1
@@ -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); }
Am 05.09.2012 14:34, schrieb Dan Carpenter:
Quoted 13 lines
We should decrement "i" before doing the
free_irq(). If we call this becauserequest_threaded_irq()failed then we don't want to free the thing which failed. Or in the case where we get here becausepower_supply_register()failed then the original codes does a read past the end of the array.Signed-off-by Dan Carpenter <[email protected]>drivers/power/da9052-battery.c +0
-0
drivers/power/da9052-battery.c static s32 __devinit da9052_bat_probe(struct platform_device *pdev) · line 629
Quoted 8 lines
drivers/power/da9052-battery.c +1
-1@@ -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
Quoted 18 lines · walter harms
Am 05.09.2012 14:34, schrieb Dan Carpenter:
Quoted 15 lines
We should decrement "i" before doing the
free_irq(). If we call this becauserequest_threaded_irq()failed then we don't want to free the thing which failed. Or in the case where we get here becausepower_supply_register()failed then the original codes does a read past the end of the array.Signed-off-by Dan Carpenter <[email protected]>drivers/power/da9052-battery.c +0
-0@@ -623,7 +623,7 @@ static s32 __devinit da9052_bat_probe(struct platform_device *pdev)return 0 ;
Quoted 9 lines
drivers/power/da9052-battery.c static s32 __devinit da9052_bat_probe(struct platform_device *pdev) · line 629
Quoted 6 lines
drivers/power/da9052-battery.c +1
-1err: -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.
Quoted 3 lines
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.
Quoted 1 line
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
Anton Vorontsov
AppliedOn Thu, Sep 06, 2012 at 08:07:58AM -0700, Dan Carpenter wrote:
[...]
Quoted 6 lines
Quoted 1 line
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!