power: supply: max14656: fix potential use-before-alloc
[ Upstream commit 0cd0e49711556d2331a06b1117b68dd786cb54d2 ] Call order on probe(): - max14656_hw_init() enables interrupts on the chip - devm_request_irq() starts processing interrupts, isr could be called immediately - isr: schedules delayed work (irq_work) - irq_work: calls power_supply_changed() - devm_power_supply_register() registers the power supply Depending on timing, it's possible that power_supply_changed() is called on an unregistered power supply structure. Fix by registering the power supply before requesting the irq. Cc: Alexander Kurz <akurz@blala.de> Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
901daed2f1
commit
5a286ced49
1 changed files with 7 additions and 7 deletions
|
@ -280,6 +280,13 @@ static int max14656_probe(struct i2c_client *client,
|
|||
|
||||
INIT_DELAYED_WORK(&chip->irq_work, max14656_irq_worker);
|
||||
|
||||
chip->detect_psy = devm_power_supply_register(dev,
|
||||
&chip->psy_desc, &psy_cfg);
|
||||
if (IS_ERR(chip->detect_psy)) {
|
||||
dev_err(dev, "power_supply_register failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = devm_request_irq(dev, chip->irq, max14656_irq,
|
||||
IRQF_TRIGGER_FALLING,
|
||||
MAX14656_NAME, chip);
|
||||
|
@ -289,13 +296,6 @@ static int max14656_probe(struct i2c_client *client,
|
|||
}
|
||||
enable_irq_wake(chip->irq);
|
||||
|
||||
chip->detect_psy = devm_power_supply_register(dev,
|
||||
&chip->psy_desc, &psy_cfg);
|
||||
if (IS_ERR(chip->detect_psy)) {
|
||||
dev_err(dev, "power_supply_register failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
schedule_delayed_work(&chip->irq_work, msecs_to_jiffies(2000));
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue