All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Ardelean <aardelean@deviqon.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio <linux-iio@vger.kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 4/5] iio: accel: mma9551: Use devm managed functions to tidy up probe()
Date: Mon, 24 May 2021 11:13:46 +0300	[thread overview]
Message-ID: <CAASAkoYLYaSZeV_FqtVhnhRPzkYPeR02CnaMusEn9rnwb6m4ug@mail.gmail.com> (raw)
In-Reply-To: <20210523162315.1965869-5-jic23@kernel.org>

On Sun, 23 May 2021 at 19:24, Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> The error handling in here left runtime pm enabled, and didn't do the
> same steps as occurred in remove.  Moving over to fully devm_ managed
> makes it harder to get this stuff wrong, so let's do that.
>

Reviewed-by: Alexandru Ardelean <aardelean@deviqon.com>

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/accel/mma9551.c | 71 ++++++++++++++++++++-----------------
>  1 file changed, 38 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c
> index a0bb4ccdbec7..f539772f8295 100644
> --- a/drivers/iio/accel/mma9551.c
> +++ b/drivers/iio/accel/mma9551.c
> @@ -389,6 +389,15 @@ static irqreturn_t mma9551_event_handler(int irq, void *private)
>         return IRQ_HANDLED;
>  }
>
> +static void mma9551_disable_cb(void *_data)
> +{
> +       struct mma9551_data *data = _data;
> +
> +       mutex_lock(&data->mutex);
> +       mma9551_set_device_state(data->client, false);
> +       mutex_unlock(&data->mutex);
> +}
> +
>  static int mma9551_init(struct mma9551_data *data)
>  {
>         int ret;
> @@ -397,7 +406,12 @@ static int mma9551_init(struct mma9551_data *data)
>         if (ret)
>                 return ret;
>
> -       return mma9551_set_device_state(data->client, true);
> +       ret = mma9551_set_device_state(data->client, true);
> +       if (ret)
> +               return ret;
> +
> +       return devm_add_action_or_reset(&data->client->dev, mma9551_disable_cb,
> +                                       data);
>  }
>
>  static int mma9551_gpio_probe(struct iio_dev *indio_dev)
> @@ -442,6 +456,16 @@ static int mma9551_gpio_probe(struct iio_dev *indio_dev)
>         return 0;
>  }
>
> +static void mma9551_rpm_susp(void *d)
> +{
> +       pm_runtime_set_suspended(d);
> +}
> +
> +static void mma9551_rpm_disable(void *d)
> +{
> +       pm_runtime_disable(d);
> +}
> +
>  static int mma9551_probe(struct i2c_client *client,
>                          const struct i2c_device_id *id)
>  {
> @@ -475,46 +499,28 @@ static int mma9551_probe(struct i2c_client *client,
>
>         ret = mma9551_gpio_probe(indio_dev);
>         if (ret < 0)
> -               goto out_poweroff;
> +               return ret;
>
>         ret = pm_runtime_set_active(&client->dev);
>         if (ret < 0)
> -               goto out_poweroff;
> +               return ret;
> +
> +       ret = devm_add_action_or_reset(&client->dev, mma9551_rpm_susp,
> +                                      &client->dev);
> +       if (ret)
> +               return ret;
>
>         pm_runtime_enable(&client->dev);
> +       ret = devm_add_action_or_reset(&client->dev, mma9551_rpm_disable,
> +                                      &client->dev);
> +       if (ret)
> +               return ret;
> +
>         pm_runtime_set_autosuspend_delay(&client->dev,
>                                          MMA9551_AUTO_SUSPEND_DELAY_MS);
>         pm_runtime_use_autosuspend(&client->dev);
>
> -       ret = iio_device_register(indio_dev);
> -       if (ret < 0) {
> -               dev_err(&client->dev, "unable to register iio device\n");
> -               goto out_poweroff;
> -       }
> -
> -       return 0;
> -
> -out_poweroff:
> -       mma9551_set_device_state(client, false);
> -
> -       return ret;
> -}
> -
> -static int mma9551_remove(struct i2c_client *client)
> -{
> -       struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -       struct mma9551_data *data = iio_priv(indio_dev);
> -
> -       iio_device_unregister(indio_dev);
> -
> -       pm_runtime_disable(&client->dev);
> -       pm_runtime_set_suspended(&client->dev);
> -
> -       mutex_lock(&data->mutex);
> -       mma9551_set_device_state(data->client, false);
> -       mutex_unlock(&data->mutex);
> -
> -       return 0;
> +       return devm_iio_device_register(&client->dev, indio_dev);
>  }
>
>  static __maybe_unused int mma9551_runtime_suspend(struct device *dev)
> @@ -569,7 +575,6 @@ static struct i2c_driver mma9551_driver = {
>                    .pm = &mma9551_pm_ops,
>                    },
>         .probe = mma9551_probe,
> -       .remove = mma9551_remove,
>         .id_table = mma9551_id,
>  };
>
> --
> 2.31.1
>

  reply	other threads:[~2021-05-24  8:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23 16:23 [PATCH 0/5] iio: accel: mma9551/mma9553 Cleanup and update Jonathan Cameron
2021-05-23 16:23 ` [PATCH 1/5] iio: accel: mma9551/mma9553: Drop explicit ACPI match support Jonathan Cameron
2021-05-23 19:17   ` Andy Shevchenko
2021-05-24  7:28   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 2/5] iio: accel: mma9551/mma9553: Simplify pm logic Jonathan Cameron
2021-05-24  7:33   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 3/5] iio: accel: mma9551: Add support to get irqs directly from fwnode Jonathan Cameron
2021-05-24  6:13   ` Andy Shevchenko
2021-05-24  9:27     ` Jonathan Cameron
2021-06-03 18:40       ` Jonathan Cameron
2021-05-24  8:16   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 4/5] iio: accel: mma9551: Use devm managed functions to tidy up probe() Jonathan Cameron
2021-05-24  8:13   ` Alexandru Ardelean [this message]
2021-05-23 16:23 ` [PATCH 5/5] iio: accel: mma9553: " Jonathan Cameron
2021-05-24  8:15   ` Alexandru Ardelean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAASAkoYLYaSZeV_FqtVhnhRPzkYPeR02CnaMusEn9rnwb6m4ug@mail.gmail.com \
    --to=aardelean@deviqon.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.