power: supply: bq27xxx: Fix kernel crash on IRQ handler register error
Subsystems (5)
PATCH v2 1/1 power: supply: bq27xxx: Fix kernel crash on IRQ handler register error
When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered power_supply registered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards.
Instead properly tear-down things on IRQ handler register errors.
---
Changes in v2:
- Fix devm_kzalloc()-ed type in the commit message
--- drivers/power/supply/bq27xxx_battery_i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/supply/bq27xxx_battery_i2c.c +2 -1
@@ -187,7 +187,8 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,dev_err (&client->dev,"Unable to register IRQ %d error %d\n" , client->irq, ret); -return ret; +bq27xxx_battery_teardown (di); + goto err_failed; } }
Signature · 1 line
2.31.1
Quoted 8 lines · Hans de Goede
When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered
power_supplyregistered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards.Instead properly tear-down things on IRQ handler register errors.
FWIW,
Quoted 27 lines
Fixes 703df6c09795 ("power: bq27xxx_battery: Reorganize I2C into a module")Cc Andrew F. Davis <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Fix devm_kzalloc()-ed type in the commit message--- drivers/power/supply/bq27xxx_battery_i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/supply/bq27xxx_battery_i2c.c +2
-2@@ -187,7 +187,8 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,dev_err (&client->dev,"Unable to register IRQ %d error %d\n" , client->irq, ret); -return ret; +bq27xxx_battery_teardown (di); + goto err_failed; } } --2.31.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Hans de Goede
When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered
power_supplyregistered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards.
Quoted 4 lines
Quoted 1 line
Instead properly tear-down things on IRQ handler register errors.
FWIW,
Reviewed-by Andy Shevchenko <[email protected]>
Thanks, queued.
-- Sebastian
Quoted 32 lines
Quoted 27 lines
Fixes 703df6c09795 ("power: bq27xxx_battery: Reorganize I2C into a module")Cc Andrew F. Davis <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Fix devm_kzalloc()-ed type in the commit message--- drivers/power/supply/bq27xxx_battery_i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/supply/bq27xxx_battery_i2c.c +2
-2@@ -187,7 +187,8 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,dev_err (&client->dev,"Unable to register IRQ %d error %d\n" , client->irq, ret); -return ret; +bq27xxx_battery_teardown (di); + goto err_failed; } } --2.31.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Sebastian,
Quoted 11 lines · Sebastian Reichel
Hi,
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Hans de Goede
When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered
power_supplyregistered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Instead properly tear-down things on IRQ handler register errors.
FWIW,
Reviewed-by Andy Shevchenko <[email protected]>Thanks, queued.
Thank you, note these 2 patches (for the bq25980 driver) are also pure bug-fixes, I posted them as part of a larger series, but in hindsight I should have probably posted them separately:
https://lore.kernel.org/platform-driver-x86/[email protected]/
https://lore.kernel.org/platform-driver-x86/[email protected]/
It would be good if you can pick these 2 up too (I'll respin the rest of the series to address various review comments without them then).
Let me know if you want me to resend these 2 as a stand alone series.
Regards,
Hans
Quoted 32 lines
Quoted 32 lines
Quoted 27 lines
Fixes 703df6c09795 ("power: bq27xxx_battery: Reorganize I2C into a module")Cc Andrew F. Davis <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Fix devm_kzalloc()-ed type in the commit message--- drivers/power/supply/bq27xxx_battery_i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/supply/bq27xxx_battery_i2c.c +2
-2@@ -187,7 +187,8 @@ static int bq27xxx_battery_i2c_probe(struct i2c_client *client,dev_err (&client->dev,"Unable to register IRQ %d error %d\n" , client->irq, ret); -return ret; +bq27xxx_battery_teardown (di); + goto err_failed; } } --2.31.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Hans,
Quoted 25 lines · Hans de Goede
Hi Sebastian,
Quoted 11 lines · Sebastian Reichel
Hi,
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Hans de Goede
When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered
power_supplyregistered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards.Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Instead properly tear-down things on IRQ handler register errors.
FWIW,
Reviewed-by Andy Shevchenko <[email protected]>Thanks, queued.
Thank you, note these 2 patches (for the bq25980 driver) are also pure bug-fixes, I posted them as part of a larger series, but in hindsight I should have probably posted them separately:
Quoted 8 lines
https://lore.kernel.org/platform-driver-x86/[email protected]/
https://lore.kernel.org/platform-driver-x86/[email protected]/It would be good if you can pick these 2 up too (I'll respin the rest of the series to address various review comments without them then).
Let me know if you want me to resend these 2 as a stand alone series.
Thanks for the pointer, I queued both of them. I had to slightly rebase, since your base did not include 172d0ccea55c. I have not yet reviewed the remaining patchset, but considering there are more patches to bq25890 a rebase would be ncie.
Greetings,
-- Sebastian
Hi,
Quoted 37 lines · Sebastian Reichel
Hi Hans,
Quoted 25 lines · Hans de Goede
Hi Sebastian,
Quoted 11 lines · Sebastian Reichel
Hi,
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Hans de Goede
When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered
power_supplyregistered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards.Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Instead properly tear-down things on IRQ handler register errors.
FWIW,
Reviewed-by Andy Shevchenko <[email protected]>Thanks, queued.
Thank you, note these 2 patches (for the bq25980 driver) are also pure bug-fixes, I posted them as part of a larger series, but in hindsight I should have probably posted them separately:
Quoted 8 lines
https://lore.kernel.org/platform-driver-x86/[email protected]/
https://lore.kernel.org/platform-driver-x86/[email protected]/It would be good if you can pick these 2 up too (I'll respin the rest of the series to address various review comments without them then).
Let me know if you want me to resend these 2 as a stand alone series.
Quoted 4 lines
Thanks for the pointer, I queued both of them. I had to slightly rebase, since your base did not include
172d0ccea55c. I have not yet reviewed the remaining patchset, but considering there are more patches to bq25890 a rebase would be ncie.
Ack, I'll rebase for the next version of that series.
Regards,
Hans