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

Ruoyu Wang <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel,org.kernel.vger.linux-renesas-soc
Message-ID <[email protected]>
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")
Signed-off-by: Ruoyu Wang <[email protected]>
---
 drivers/counter/rz-mtu3-cnt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c
index 7bfb6979193ce..a8ba8ebed236d 100644
--- a/drivers/counter/rz-mtu3-cnt.c
+++ b/drivers/counter/rz-mtu3-cnt.c
@@ -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);
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.