Skip to contentSkip to conversation

counter: rz-mtu3-cnt: Balance runtime PM on enable failure

PATCH New Ruoyu Wang 1 participant 1 message Aug 14

Subsystems (3)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 counter: rz-mtu3-cnt: Balance runtime PM on enable failure

rz_mtu3_count_enable_write() used pm_runtime_get_sync() without checking its return value before initializing a counter. A failed runtime resume was therefore ignored and the callback continued with the device unavailable.

Use pm_runtime_resume_and_get() and return a failed resume to the Counter core. Keep the matching put when shared-channel initialization fails after a successful resume, and leave the cached enable state unchanged.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes 0be8907359df ("counter: Add Renesas RZ/G2L MTU3a counter driver")
---
 drivers/counter/rz-mtu3-cnt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/counter/rz-mtu3-cnt.c +7 -2
index 7bfb6979193ce..a8ba8ebed236d 100644
@@ -504,9 +504,14 @@ static int rz_mtu3_count_enable_write(struct counter_device *counter,
 		goto exit;
 
 	if (enable) {
-		pm_runtime_get_sync(counter->parent);
+		ret = pm_runtime_resume_and_get(counter->parent);
+		if (ret < 0)
+			goto exit;
+
 		ret = rz_mtu3_initialize_counter(counter, count->id);
-		if (ret == 0)
+		if (ret)
+			pm_runtime_put(counter->parent);
+		else
 			priv->count_is_enabled[count->id] = true;
 	} else {
 		rz_mtu3_terminate_counter(counter, count->id);
Signature · 1 line
2.51.0