Skip to contentSkip to conversation

i2c: riic: fix refcount leak in riic_i2c_resume_noirq()

PATCH Applied Wentao Liang 3 participants 3 messages Jun 8

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: riic: fix refcount leak in riic_i2c_resume_noirq()

When riic_i2c_resume_noirq() is called, it deasserts the reset using reset_control_deassert(), which for shared resets increments a reference count. If pm_runtime_force_resume() then fails, the function returns without calling reset_control_assert() to decrement the count. This leaves the reset deasserted and the reference count unbalanced, which can prevent other users of the shared reset from properly asserting it later.

Fix the leak by calling reset_control_assert() on the error handling path for a failed pm_runtime_force_resume().

Fixes e383f0961422 ("i2c: riic: Move suspend handling to NOIRQ phase")
---
 drivers/i2c/busses/i2c-riic.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-riic.c +3 -1
index 9e3595b3623e..6d2ebf67dd62 100644
@@ -725,8 +725,10 @@ static int riic_i2c_resume_noirq(struct device *dev)
 		return ret;
 
 	ret = pm_runtime_force_resume(dev);
-	if (ret)
+	if (ret) {
+		reset_control_assert(riic->rstc);
 		return ret;
+	}
 
 	ret = riic_init_hw(riic);
 	if (ret) {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Wentao Liang

When riic_i2c_resume_noirq() is called, it deasserts the reset using reset_control_deassert(), which for shared resets increments a reference count. If pm_runtime_force_resume() then fails, the function returns without calling reset_control_assert() to decrement the count. This leaves the reset deasserted and the reference count unbalanced, which can prevent other users of the shared reset from properly asserting it later.

Quoted 6 lines

Fix the leak by calling reset_control_assert() on the error handling path for a failed pm_runtime_force_resume().

Fixes e383f0961422 ("i2c: riic: Move suspend handling to NOIRQ phase")

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
maintainer Applied
#2 lore raw
In reply to Wentao Liang

Hi Wentao,

Quoted 8 lines · Wentao Liang

When riic_i2c_resume_noirq() is called, it deasserts the reset using reset_control_deassert(), which for shared resets increments a reference count. If pm_runtime_force_resume() then fails, the function returns without calling reset_control_assert() to decrement the count. This leaves the reset deasserted and the reference count unbalanced, which can prevent other users of the shared reset from properly asserting it later.

Quoted 6 lines

Fix the leak by calling reset_control_assert() on the error handling path for a failed pm_runtime_force_resume().

Fixes e383f0961422 ("i2c: riic: Move suspend handling to NOIRQ phase")

merged to i2c/i2c-host-fixes.

Thanks,
Andi