Re: [PATCH v6 2/2] iio: light: Add support for ltrf216a sensor

From: Jonathan Cameron
Date: Sun Jun 19 2022 - 08:35:37 EST




>
> > + /* reset sensor, chip fails to respond to this, so ignore any errors */
> > + ltrf216a_reset(indio_dev);
> > +
> > + ret = pm_runtime_set_active(&client->dev);
> > + if (ret)
> > + goto error_power_down;
>
> Why do you need to power down here?
>
> > + pm_runtime_enable(&client->dev);

We now have devm_pm_runtime_enable() which will also deal
with disabling use_autosuspend for you and should help you
sort out some of the ordering.


> > + pm_runtime_set_autosuspend_delay(&client->dev, 5000);
> > + pm_runtime_use_autosuspend(&client->dev);
> > +
> > + ltrf216a_set_power_state(data, true);
>
> The below code suggests that you are mixing badly devm_ with non-devm_
> APIs, don't do this. You have to group devm_ first followed by
> non-devm_ calls.
>
> ...
>
> > +static int ltrf216a_remove(struct i2c_client *client)
> > +{
> > + struct iio_dev *indio_dev = i2c_get_clientdata(client);
> > +
> > + iio_device_unregister(indio_dev);
> > + pm_runtime_disable(&client->dev);
> > + pm_runtime_set_suspended(&client->dev);
> > + ltrf216a_disable(indio_dev);
> > +
> > + return 0;
>
> I believe the ordering of freeing resources and reverting state is not
> in reverse. See above why.

In particular you are calling disable there which is already handled
by devm_ unwinding.
>
> > +}
>