diff mbox series

Input: cyapa - Fix rumtime PM imbalance on error

Message ID 20210407040740.20257-1-dinghao.liu@zju.edu.cn (mailing list archive)
State Under Review
Headers show
Series Input: cyapa - Fix rumtime PM imbalance on error | expand

Commit Message

Dinghao Liu April 7, 2021, 4:07 a.m. UTC
When mutex_lock_interruptible() fails, a pairing PM usage
counter decrement is needed to keep the counter balanced.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/input/mouse/cyapa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Dmitry Torokhov April 8, 2021, 6:19 a.m. UTC | #1
Hi Dinghao,

On Wed, Apr 07, 2021 at 12:07:38PM +0800, Dinghao Liu wrote:
> When mutex_lock_interruptible() fails, a pairing PM usage
> counter decrement is needed to keep the counter balanced.

Thank you for the patch.

> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  drivers/input/mouse/cyapa.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> index 77cc653edca2..e411ab45a218 100644
> --- a/drivers/input/mouse/cyapa.c
> +++ b/drivers/input/mouse/cyapa.c
> @@ -904,8 +904,10 @@ static ssize_t cyapa_update_rt_suspend_scanrate(struct device *dev,
>  	pm_runtime_get_sync(dev);
>  
>  	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
> -	if (error)
> +	if (error) {
> +		pm_runtime_put_noidle(dev);

Why "noidle" and not pm_runtime_put_sync_autosuspend() like we do in
case of normal flow?

>  		return error;
> +	}
>  
>  	cyapa->runtime_suspend_sleep_time = min_t(u16, time, 1000);
>  	cyapa->runtime_suspend_power_mode =
> -- 
> 2.17.1
> 

Thanks.
Dinghao Liu April 8, 2021, 6:29 a.m. UTC | #2
> Hi Dinghao,
> 
> On Wed, Apr 07, 2021 at 12:07:38PM +0800, Dinghao Liu wrote:
> > When mutex_lock_interruptible() fails, a pairing PM usage
> > counter decrement is needed to keep the counter balanced.
> 
> Thank you for the patch.
> 
> > 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> > ---
> >  drivers/input/mouse/cyapa.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
> > index 77cc653edca2..e411ab45a218 100644
> > --- a/drivers/input/mouse/cyapa.c
> > +++ b/drivers/input/mouse/cyapa.c
> > @@ -904,8 +904,10 @@ static ssize_t cyapa_update_rt_suspend_scanrate(struct device *dev,
> >  	pm_runtime_get_sync(dev);
> >  
> >  	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
> > -	if (error)
> > +	if (error) {
> > +		pm_runtime_put_noidle(dev);
> 
> Why "noidle" and not pm_runtime_put_sync_autosuspend() like we do in
> case of normal flow?
> 

pm_runtime_put_noidle() only decrease the refcount, while 
pm_runtime_put_sync_autosuspend() will execute an extra
pm_runtime_autosuspend(). I'm not sure if the autosuspend is necessary
in this error handling path, so I only balance the counter.

Regards,
Dinghao
diff mbox series

Patch

diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index 77cc653edca2..e411ab45a218 100644
--- a/drivers/input/mouse/cyapa.c
+++ b/drivers/input/mouse/cyapa.c
@@ -904,8 +904,10 @@  static ssize_t cyapa_update_rt_suspend_scanrate(struct device *dev,
 	pm_runtime_get_sync(dev);
 
 	error = mutex_lock_interruptible(&cyapa->state_sync_lock);
-	if (error)
+	if (error) {
+		pm_runtime_put_noidle(dev);
 		return error;
+	}
 
 	cyapa->runtime_suspend_sleep_time = min_t(u16, time, 1000);
 	cyapa->runtime_suspend_power_mode =