diff mbox series

iio: gyro: bmg160: Fix error handling in bmg160_core_probe

Message ID 20220105125633.21989-1-linmq006@gmail.com (mailing list archive)
State Superseded
Headers show
Series iio: gyro: bmg160: Fix error handling in bmg160_core_probe | expand

Commit Message

Miaoqian Lin Jan. 5, 2022, 12:56 p.m. UTC
The pm_runtime_enable will increase power disable depth.
If the probe fails, we should use pm_runtime_disable() to balance
pm_runtime_enable(). In the PM Runtime docs:
    Drivers in ->remove() callback should undo the runtime PM changes done
    in ->probe(). Usually this means calling pm_runtime_disable(),
    pm_runtime_dont_use_autosuspend() etc.
We should do this in error handling.

Fixes: 7d0ead5 ("iio: Reconcile operation order between iio_register/unregister and pm functions")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/iio/gyro/bmg160_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Jonathan Cameron Jan. 5, 2022, 1:07 p.m. UTC | #1
On Wed,  5 Jan 2022 12:56:30 +0000
Miaoqian Lin <linmq006@gmail.com> wrote:

> The pm_runtime_enable will increase power disable depth.
> If the probe fails, we should use pm_runtime_disable() to balance
> pm_runtime_enable(). In the PM Runtime docs:
>     Drivers in ->remove() callback should undo the runtime PM changes done
>     in ->probe(). Usually this means calling pm_runtime_disable(),
>     pm_runtime_dont_use_autosuspend() etc.
> We should do this in error handling.
> 
> Fixes: 7d0ead5 ("iio: Reconcile operation order between iio_register/unregister and pm functions")

Hi Miaoqian,

Please check this fixes tag against the format it should have.

Thanks,

Jonathan


> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/iio/gyro/bmg160_core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
> index 17b939a367ad..81a6d09788bd 100644
> --- a/drivers/iio/gyro/bmg160_core.c
> +++ b/drivers/iio/gyro/bmg160_core.c
> @@ -1188,11 +1188,14 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  	ret = iio_device_register(indio_dev);
>  	if (ret < 0) {
>  		dev_err(dev, "unable to register iio device\n");
> -		goto err_buffer_cleanup;
> +		goto err_pm_cleanup;
>  	}
>  
>  	return 0;
>  
> +err_pm_cleanup:
> +	pm_runtime_dont_use_autosuspend(dev);
> +	pm_runtime_disable(dev);
>  err_buffer_cleanup:
>  	iio_triggered_buffer_cleanup(indio_dev);
>  err_trigger_unregister:
Andy Shevchenko Jan. 5, 2022, 1:52 p.m. UTC | #2
On Wed, Jan 05, 2022 at 01:07:43PM +0000, Jonathan Cameron wrote:
> On Wed,  5 Jan 2022 12:56:30 +0000
> Miaoqian Lin <linmq006@gmail.com> wrote:
> 
> > The pm_runtime_enable will increase power disable depth.
> > If the probe fails, we should use pm_runtime_disable() to balance
> > pm_runtime_enable(). In the PM Runtime docs:
> >     Drivers in ->remove() callback should undo the runtime PM changes done
> >     in ->probe(). Usually this means calling pm_runtime_disable(),
> >     pm_runtime_dont_use_autosuspend() etc.
> > We should do this in error handling.
> > 
> > Fixes: 7d0ead5 ("iio: Reconcile operation order between iio_register/unregister and pm functions")
> 
> Hi Miaoqian,
> 
> Please check this fixes tag against the format it should have.

I usually advise people to put the following in the ~/.gitconfig:

[core]
	abbrev = 12

[alias]
	one = show -s --pretty='format:%h (\"%s\")'
	c = show -s --pretty='format:https://git.kernel.org/torvalds/c/%h'

`git one ...` will give a right thing.
Andy Shevchenko Jan. 5, 2022, 1:54 p.m. UTC | #3
On Wed, Jan 05, 2022 at 12:56:30PM +0000, Miaoqian Lin wrote:
> The pm_runtime_enable will increase power disable depth.
> If the probe fails, we should use pm_runtime_disable() to balance
> pm_runtime_enable(). In the PM Runtime docs:
>     Drivers in ->remove() callback should undo the runtime PM changes done
>     in ->probe(). Usually this means calling pm_runtime_disable(),
>     pm_runtime_dont_use_autosuspend() etc.
> We should do this in error handling.

Looking into culprit commit, can you fix all of them, please?
diff mbox series

Patch

diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
index 17b939a367ad..81a6d09788bd 100644
--- a/drivers/iio/gyro/bmg160_core.c
+++ b/drivers/iio/gyro/bmg160_core.c
@@ -1188,11 +1188,14 @@  int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
 	ret = iio_device_register(indio_dev);
 	if (ret < 0) {
 		dev_err(dev, "unable to register iio device\n");
-		goto err_buffer_cleanup;
+		goto err_pm_cleanup;
 	}
 
 	return 0;
 
+err_pm_cleanup:
+	pm_runtime_dont_use_autosuspend(dev);
+	pm_runtime_disable(dev);
 err_buffer_cleanup:
 	iio_triggered_buffer_cleanup(indio_dev);
 err_trigger_unregister: