diff mbox series

[v2,2/4] iio: hid-sensor-trigger: Decrement runtime pm enable count on driver removal

Message ID 20201119100331.2594-3-xiang.ye@intel.com (mailing list archive)
State Superseded
Headers show
Series add custom hinge sensor support | expand

Commit Message

Ye Xiang Nov. 19, 2020, 10:03 a.m. UTC
To avoid pm_runtime_disable called repeatedly by hid sensor drivers,
decrease runtime pm enable count after call it.

Signed-off-by: Ye Xiang <xiang.ye@intel.com>
---
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jonathan Cameron Nov. 21, 2020, 5:22 p.m. UTC | #1
On Thu, 19 Nov 2020 18:03:29 +0800
Ye Xiang <xiang.ye@intel.com> wrote:

> To avoid pm_runtime_disable called repeatedly by hid sensor drivers,
> decrease runtime pm enable count after call it.
> 
> Signed-off-by: Ye Xiang <xiang.ye@intel.com>
This sounds like a fix.  If so please make that clear and add a fixes tag.

If it couldn't have been triggered before, then please explain why in this
patch description.

Thanks,

Jonathan

> ---
>  drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> index ff375790b7e8..30340abcbc8d 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> @@ -227,8 +227,10 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
>  void hid_sensor_remove_trigger(struct iio_dev *indio_dev,
>  			       struct hid_sensor_common *attrb)
>  {
> -	if (atomic_read(&attrb->runtime_pm_enable))
> +	if (atomic_read(&attrb->runtime_pm_enable)) {
>  		pm_runtime_disable(&attrb->pdev->dev);
> +		atomic_dec(&attrb->runtime_pm_enable);
> +	}
>  
>  	pm_runtime_set_suspended(&attrb->pdev->dev);
>  	pm_runtime_put_noidle(&attrb->pdev->dev);
Pandruvada, Srinivas Nov. 22, 2020, 1:54 a.m. UTC | #2
On Sat, 2020-11-21 at 17:22 +0000, Jonathan Cameron wrote:
> On Thu, 19 Nov 2020 18:03:29 +0800
> Ye Xiang <xiang.ye@intel.com> wrote:
> 
> > To avoid pm_runtime_disable called repeatedly by hid sensor
> > drivers,
> > decrease runtime pm enable count after call it.
> > 
> > Signed-off-by: Ye Xiang <xiang.ye@intel.com>
> This sounds like a fix.  If so please make that clear and add a fixes
> tag.
> 
> If it couldn't have been triggered before, then please explain why in
> this
> patch description.
Normally it is not a problem as this is called during driver remove and
next time insmod this data structure is recreated and count will init
again. This is the artifect of the shared iio devices and one of them
is still open, so the instance will not be freed.
But patch is fine as to do opposite of what is done during alloc.

Thanks,
Srinivas

> 
> Thanks,
> 
> Jonathan
> 
> > ---
> >  drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > index ff375790b7e8..30340abcbc8d 100644
> > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > @@ -227,8 +227,10 @@ static int
> > hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
> >  void hid_sensor_remove_trigger(struct iio_dev *indio_dev,
> >  			       struct hid_sensor_common *attrb)
> >  {
> > -	if (atomic_read(&attrb->runtime_pm_enable))
> > +	if (atomic_read(&attrb->runtime_pm_enable)) {
> >  		pm_runtime_disable(&attrb->pdev->dev);
> > +		atomic_dec(&attrb->runtime_pm_enable);
> > +	}
> >  
> >  	pm_runtime_set_suspended(&attrb->pdev->dev);
> >  	pm_runtime_put_noidle(&attrb->pdev->dev);
diff mbox series

Patch

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index ff375790b7e8..30340abcbc8d 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -227,8 +227,10 @@  static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 void hid_sensor_remove_trigger(struct iio_dev *indio_dev,
 			       struct hid_sensor_common *attrb)
 {
-	if (atomic_read(&attrb->runtime_pm_enable))
+	if (atomic_read(&attrb->runtime_pm_enable)) {
 		pm_runtime_disable(&attrb->pdev->dev);
+		atomic_dec(&attrb->runtime_pm_enable);
+	}
 
 	pm_runtime_set_suspended(&attrb->pdev->dev);
 	pm_runtime_put_noidle(&attrb->pdev->dev);