mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
@ 2026-10-31 14:28 Li Youhong
  2026-10-31 16:04 ` Biju Das
  2026-10-31 16:28 ` William Breathitt Gray
  0 siblings, 2 replies; 5+ messages in thread
From: Li Youhong @ 2026-10-31 14:28 UTC (permalink / raw)
  To: biju.das.jz, wbg
  Cc: linux-iio, linux-renesas-soc, linux-kernel,
	cosmin-gabriel.tanislav.xa, Li Youhong, stable

From: Li Youhong <liyouhong@kylinos.cn>

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
Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
---
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 | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c
index 7bfb6979193c..61fbeb122851 100644
--- a/drivers/counter/rz-mtu3-cnt.c
+++ b/drivers/counter/rz-mtu3-cnt.c
@@ -506,8 +506,11 @@ 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;
+		}
+		priv->count_is_enabled[count->id] = true;
 	} else {
 		rz_mtu3_terminate_counter(counter, count->id);
 		priv->count_is_enabled[count->id] = false;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
  2026-10-31 14:28 [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails Li Youhong
@ 2026-10-31 16:04 ` Biju Das
  2026-10-31 16:28 ` William Breathitt Gray
  1 sibling, 0 replies; 5+ messages in thread
From: Biju Das @ 2026-10-31 16:04 UTC (permalink / raw)
  To: Li Youhong, wbg
  Cc: linux-iio, linux-renesas-soc, linux-kernel,
	Cosmin-Gabriel Tanislav, Li Youhong, stable

Li Youhong,

Thanks for the patch

> -----Original Message-----
> From: Li Youhong <dayou5941@163.com>
> Sent: 31 October 2026 14:28
> To: Biju Das <biju.das.jz@bp.renesas.com>; wbg@kernel.org
> Cc: linux-iio@vger.kernel.org; linux-renesas-soc@vger.kernel.org; linux-kernel@vger.kernel.org; Cosmin-
> Gabriel Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>; Li Youhong <liyouhong@kylinos.cn>;
> stable@vger.kernel.org
> Subject: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
> 
> From: Li Youhong <liyouhong@kylinos.cn>
> 
> 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
> Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
> ---
> 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 | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c index
> 7bfb6979193c..61fbeb122851 100644
> --- a/drivers/counter/rz-mtu3-cnt.c
> +++ b/drivers/counter/rz-mtu3-cnt.c
> @@ -506,8 +506,11 @@ 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;
> +		}
> +		priv->count_is_enabled[count->id] = true;
>  	} else {
>  		rz_mtu3_terminate_counter(counter, count->id);
>  		priv->count_is_enabled[count->id] = false;


Now, Maybe we can avoid code duplication??

priv->count_is_enabled[count->id] = enable;

Cheers,
Biju


> --
> 2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
  2026-10-31 14:28 [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails Li Youhong
  2026-10-31 16:04 ` Biju Das
@ 2026-10-31 16:28 ` William Breathitt Gray
  2026-10-31 16:34   ` Biju Das
  1 sibling, 1 reply; 5+ messages in thread
From: William Breathitt Gray @ 2026-10-31 16:28 UTC (permalink / raw)
  To: Li Youhong
  Cc: William Breathitt Gray, biju.das.jz, linux-iio,
	linux-renesas-soc, linux-kernel, cosmin-gabriel.tanislav.xa,
	Li Youhong, stable

On Sat, Oct 31, 2026 at 10:28:13PM +0800, Li Youhong wrote:
> From: Li Youhong <liyouhong@kylinos.cn>
> 
> 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
> Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
> ---
> 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 | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/counter/rz-mtu3-cnt.c b/drivers/counter/rz-mtu3-cnt.c
> index 7bfb6979193c..61fbeb122851 100644
> --- a/drivers/counter/rz-mtu3-cnt.c
> +++ b/drivers/counter/rz-mtu3-cnt.c
> @@ -506,8 +506,11 @@ 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;
> +		}
> +		priv->count_is_enabled[count->id] = true;
>  	} else {
>  		rz_mtu3_terminate_counter(counter, count->id);
>  		priv->count_is_enabled[count->id] = false;
> --
> 2.25.1
> 

This patch seems similar to another we're considering for ti-eqep.[^1]
In that patch, runtime PM is managed via devm which allows us to remove
the explicit PM unwind on failures and have them implicitly handled when
the device resource is released. Should we use the same approach for
rz-mtu-cnt?

William Breathitt Gray

[^1]: https://lore.kernel.org/all/20260529095834.2561-1-sozdayvek@gmail.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
  2026-10-31 16:28 ` William Breathitt Gray
@ 2026-10-31 16:34   ` Biju Das
  2026-10-31 18:21     ` William Breathitt Gray
  0 siblings, 1 reply; 5+ messages in thread
From: Biju Das @ 2026-10-31 16:34 UTC (permalink / raw)
  To: William Breathitt Gray, Li Youhong
  Cc: linux-iio, linux-renesas-soc, linux-kernel,
	Cosmin-Gabriel Tanislav, Li Youhong, stable

Hi William Breathitt Gray,

Thanks for the feedback.

> -----Original Message-----
> From: William Breathitt Gray <wbg@kernel.org>
> Sent: 31 October 2026 16:29
> Subject: Re: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
> 
> On Sat, Oct 31, 2026 at 10:28:13PM +0800, Li Youhong wrote:
> > From: Li Youhong <liyouhong@kylinos.cn>
> >
> > 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
> > Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> > Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
> > ---
> > 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 | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/counter/rz-mtu3-cnt.c
> > b/drivers/counter/rz-mtu3-cnt.c index 7bfb6979193c..61fbeb122851
> > 100644
> > --- a/drivers/counter/rz-mtu3-cnt.c
> > +++ b/drivers/counter/rz-mtu3-cnt.c
> > @@ -506,8 +506,11 @@ 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;
> > +		}
> > +		priv->count_is_enabled[count->id] = true;
> >  	} else {
> >  		rz_mtu3_terminate_counter(counter, count->id);
> >  		priv->count_is_enabled[count->id] = false;
> > --
> > 2.25.1
> >
> 
> This patch seems similar to another we're considering for ti-eqep.[^1] In that patch, runtime PM is
> managed via devm which allows us to remove the explicit PM unwind on failures and have them implicitly
> handled when the device resource is released. Should we use the same approach for rz-mtu-cnt?

Here we save power, clock is turned on/off during counter enable/disable.
On TI case, they enable it during the probe which unnecessarily waste power.
Even disable case, the clock is on.

Cheers,
Biju

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
  2026-10-31 16:34   ` Biju Das
@ 2026-10-31 18:21     ` William Breathitt Gray
  0 siblings, 0 replies; 5+ messages in thread
From: William Breathitt Gray @ 2026-10-31 18:21 UTC (permalink / raw)
  To: Biju Das
  Cc: William Breathitt Gray, Li Youhong, linux-iio, linux-renesas-soc,
	linux-kernel, Cosmin-Gabriel Tanislav, Li Youhong, stable

On Sat, Oct 31, 2026 at 04:34:32PM +0000, Biju Das wrote:
> Hi William Breathitt Gray,
> 
> Thanks for the feedback.
> 
> > -----Original Message-----
> > From: William Breathitt Gray <wbg@kernel.org>
> > Sent: 31 October 2026 16:29
> > Subject: Re: [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails
> >
> > On Sat, Oct 31, 2026 at 10:28:13PM +0800, Li Youhong wrote:
> > > From: Li Youhong <liyouhong@kylinos.cn>
> > >
> > > 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
> > > Reviewed-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
> > > Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
> > > ---
> > > 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 | 7 +++++--
> > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/counter/rz-mtu3-cnt.c
> > > b/drivers/counter/rz-mtu3-cnt.c index 7bfb6979193c..61fbeb122851
> > > 100644
> > > --- a/drivers/counter/rz-mtu3-cnt.c
> > > +++ b/drivers/counter/rz-mtu3-cnt.c
> > > @@ -506,8 +506,11 @@ 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;
> > > +		}
> > > +		priv->count_is_enabled[count->id] = true;
> > >  	} else {
> > >  		rz_mtu3_terminate_counter(counter, count->id);
> > >  		priv->count_is_enabled[count->id] = false;
> > > --
> > > 2.25.1
> > >
V> >
> > This patch seems similar to another we're considering for ti-eqep.[^1] In that patch, runtime PM is
> > managed via devm which allows us to remove the explicit PM unwind on failures and have them implicitly
> > handled when the device resource is released. Should we use the same approach for rz-mtu-cnt?
> 
> Here we save power, clock is turned on/off during counter enable/disable.
> On TI case, they enable it during the probe which unnecessarily waste power.
> Even disable case, the clock is on.
> 
> Cheers,
> Biju

I suppose you are right. There is no need to keep the clocks powered if
the counter is disabled because we are no longer counting.

William Breathitt Gray.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-31 18:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 14:28 [PATCH v2] counter: rz-mtu3-cnt: put runtime PM ref if counter init fails Li Youhong
2026-10-31 16:04 ` Biju Das
2026-10-31 16:28 ` William Breathitt Gray
2026-10-31 16:34   ` Biju Das
2026-10-31 18:21     ` William Breathitt Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®