From: Li Youhong Counter enable takes a runtime PM reference before initialization but only puts it on disable. Drop the reference if initialization fails. Fixes: 0be8907359df ("counter: Add Renesas RZ/G2L MTU3a counter driver") Cc: stable@vger.kernel.org Signed-off-by: Li Youhong --- v3: - Set count_is_enabled from enable after either branch succeeds. - v2: https://lore.kernel.org/all/20261031142813.2522444-1-dayou5941@163.com/ v2: - Add Cc: stable@vger.kernel.org. - v1: https://lore.kernel.org/all/20261008020506.211566-1-dayou5941@163.com/ drivers/counter/rz-mtu3-cnt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index 7bfb6979193c..e7fe8bf45164 100644 --- a/drivers/counter/rz-mtu3-cnt.c +++ b/drivers/counter/rz-mtu3-cnt.c @@ -506,14 +506,17 @@ static int rz_mtu3_count_enable_write(struct counter_device *counter, if (enable) { pm_runtime_get_sync(counter->parent); ret = rz_mtu3_initialize_counter(counter, count->id); - if (ret == 0) - priv->count_is_enabled[count->id] = true; + if (ret < 0) { + pm_runtime_put(counter->parent); + goto exit; + } } else { rz_mtu3_terminate_counter(counter, count->id); - priv->count_is_enabled[count->id] = false; pm_runtime_put(counter->parent); } + priv->count_is_enabled[count->id] = enable; + exit: mutex_unlock(&priv->lock);