platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: bq27xxx: Fix kernel crash on IRQ handler register error
@ 2021-10-31  9:02 Hans de Goede
  2021-10-31 12:57 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Hans de Goede @ 2021-10-31  9:02 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Hans de Goede, linux-acpi, platform-driver-x86, linux-pm,
	Andrew F . Davis

When registering the IRQ handler fails, do not just return the error code,
this will free the devm_kalloc-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.

Fixes: 703df6c09795 ("power: bq27xxx_battery: Reorganize I2C into a module")
Cc: Andrew F. Davis <afd@ti.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/power/supply/bq27xxx_battery_i2c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c
index 46f078350fd3..cf38cbfe13e9 100644
--- a/drivers/power/supply/bq27xxx_battery_i2c.c
+++ b/drivers/power/supply/bq27xxx_battery_i2c.c
@@ -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


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

* Re: [PATCH] power: supply: bq27xxx: Fix kernel crash on IRQ handler register error
  2021-10-31  9:02 [PATCH] power: supply: bq27xxx: Fix kernel crash on IRQ handler register error Hans de Goede
@ 2021-10-31 12:57 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2021-10-31 12:57 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Sebastian Reichel, ACPI Devel Maling List, Platform Driver,
	Linux PM, Andrew F . Davis

On Sun, Oct 31, 2021 at 11:07 AM Hans de Goede <hdegoede@redhat.com> wrote:
>
> When registering the IRQ handler fails, do not just return the error code,
> this will free the devm_kalloc-ed data struct while leaving the queued

devm_kzalloc()-ed?

(main point is z/m/etc in the function name)

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


-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2021-10-31 12:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-31  9:02 [PATCH] power: supply: bq27xxx: Fix kernel crash on IRQ handler register error Hans de Goede
2021-10-31 12:57 ` Andy Shevchenko

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