]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
power: supply: max14656: fix potential use-before-alloc
authorSven Van Asbroeck <thesven73@gmail.com>
Fri, 15 Feb 2019 21:43:02 +0000 (16:43 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Jun 2019 09:54:09 +0000 (11:54 +0200)
commit5a286ced49117a29e65e47cb43fa878ade7a2a70
treef6a301a6789b3be8590fcb20cae759a6bd91e0af
parent901daed2f1739fb047aec14d5c2c6df9954874ae
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>
drivers/power/supply/max14656_charger_detector.c