Skip to contentSkip to conversation

reset: fix refcount leak in reset_control_bulk_assert()

PATCH In review WenTao Liang 2 participants 2 messages Jun 11 Reset controller framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reset: fix refcount leak in reset_control_bulk_assert()

When reset_control_bulk_assert() asserts a batch of reset controls, it calls reset

Fixes 0b52297f2288 ("reset: Add support for shared reset controls")
---
 drivers/reset/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/reset/core.c +8 -1
index 38e189d04d09..daf9201bc105 100644
@@ -516,8 +516,15 @@ int reset_control_assert(struct reset_control *rstc)
 		if (WARN_ON(atomic_read(&rstc->deassert_count) == 0))
 			return -EINVAL;
 
-		if (atomic_dec_return(&rstc->deassert_count) != 0)
+		if (atomic_dec_return(&rstc->deassert_count) != 0) {
+			int err = rcdev->ops->assert(rcdev, rstc->id);
+
+			if (err) {
+				atomic_inc(&rstc->deassert_count);
+				return err;
+			}
 			return 0;
+		}
 
 		/*
 		 * Shared reset controls allow the reset line to be in any state
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer
#1 lore raw
Quoted 2 lines · WenTao Liang

When reset_control_bulk_assert() asserts a batch of reset controls, it calls reset

Can you write a better commit message?
What does this patch accomplish, and why?

Quoted 11 lines
Fixes 0b52297f2288 ("reset: Add support for shared reset controls")
---
 drivers/reset/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/reset/core.c +0 -0
index 38e189d04d09..daf9201bc105 100644

drivers/reset/core.c int reset_control_assert(struct reset_control *rstc) · line 520

Quoted 6 lines
drivers/reset/core.c +2 -1
@@ -516,8 +516,15 @@ int reset_control_assert(struct reset_control *rstc)
 		if (WARN_ON(atomic_read(&rstc->deassert_count) == 0))
 			return -EINVAL;
 
-		if (atomic_dec_return(&rstc->deassert_count) != 0)
+		if (atomic_dec_return(&rstc->deassert_count) != 0) {
+			int err = rcdev->ops->assert(rcdev, rstc->id);

This is wrong, asserting the reset must not happen unless deassert_count has been decremented to zero.

regards
Philipp