LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Alexandru Ardelean <ardeleanalex@gmail.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	linux-iio <linux-iio@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] iio: adc128s052: Simplify 'adc128_probe()'
Date: Wed, 25 Aug 2021 10:11:07 +0300	[thread overview]
Message-ID: <CA+U=DspfvNU6gwRGZjWMtjrDQV2=N8H5ARnq4Sz4HWZ=FBmn_g@mail.gmail.com> (raw)
In-Reply-To: <f20a0eb45957c6931a8f35d035514484a2ac0f3d.1629838169.git.christophe.jaillet@wanadoo.fr>

On Tue, Aug 24, 2021 at 11:52 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> Turn 'adc128_probe()' into a full resource managed function to simplify the
> code.
>
> This way, the .remove function can be removed.
> Doing so, the only 'spi_get_drvdata()' call is removed and the
> corresponding 'spi_set_drvdata()' can be removed as well.
>

Minor note inline. Nothing major.

Other than that:

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

> Suggested-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
>
> When reviewing, pay special attention to the 'spi_set_drvdata()' call
> removal. I recently introduced a regression with a too aggressive cleanup
> like that.
>
> This patch should be applied after
> https://lore.kernel.org/linux-iio/f33069f0-601b-4bbb-3766-026f7a161912@wanadoo.fr/T/#meb792dcd6540f87d9ae041660ca4738a776e924a
> ---
>  drivers/iio/adc/ti-adc128s052.c | 34 +++++++++++----------------------
>  1 file changed, 11 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> index 83c1ae07b3e9..e1afdb775100 100644
> --- a/drivers/iio/adc/ti-adc128s052.c
> +++ b/drivers/iio/adc/ti-adc128s052.c
> @@ -132,6 +132,13 @@ static const struct iio_info adc128_info = {
>         .read_raw = adc128_read_raw,
>  };
>
> +static void adc128_disable_regulator(void *data)
> +{
> +       struct regulator *reg = data;
> +
> +       regulator_disable(reg);
> +}

You can also do this as:

static void adc128_disable_regulator(void *reg)
{
      regulator_disable(reg);
}

> +
>  static int adc128_probe(struct spi_device *spi)
>  {
>         struct iio_dev *indio_dev;
> @@ -151,8 +158,6 @@ static int adc128_probe(struct spi_device *spi)
>         adc = iio_priv(indio_dev);
>         adc->spi = spi;
>
> -       spi_set_drvdata(spi, indio_dev);
> -
>         indio_dev->name = spi_get_device_id(spi)->name;
>         indio_dev->modes = INDIO_DIRECT_MODE;
>         indio_dev->info = &adc128_info;
> @@ -167,29 +172,13 @@ static int adc128_probe(struct spi_device *spi)
>         ret = regulator_enable(adc->reg);
>         if (ret < 0)
>                 return ret;
> -
> -       mutex_init(&adc->lock);
> -
> -       ret = iio_device_register(indio_dev);
> +       ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator, adc->reg);
>         if (ret)
> -               goto err_disable_regulator;
> -
> -       return 0;
> -
> -err_disable_regulator:
> -       regulator_disable(adc->reg);
> -       return ret;
> -}
> -
> -static int adc128_remove(struct spi_device *spi)
> -{
> -       struct iio_dev *indio_dev = spi_get_drvdata(spi);
> -       struct adc128 *adc = iio_priv(indio_dev);
> +               return ret;
>
> -       iio_device_unregister(indio_dev);
> -       regulator_disable(adc->reg);
> +       mutex_init(&adc->lock);
>
> -       return 0;
> +       return devm_iio_device_register(&spi->dev, indio_dev);
>  }
>
>  static const struct of_device_id adc128_of_match[] = {
> @@ -231,7 +220,6 @@ static struct spi_driver adc128_driver = {
>                 .acpi_match_table = ACPI_PTR(adc128_acpi_match),
>         },
>         .probe = adc128_probe,
> -       .remove = adc128_remove,
>         .id_table = adc128_id,
>  };
>  module_spi_driver(adc128_driver);
> --
> 2.30.2
>

      reply	other threads:[~2021-08-25  7:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 20:52 Christophe JAILLET
2021-08-25  7:11 ` Alexandru Ardelean [this message]

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='CA+U=DspfvNU6gwRGZjWMtjrDQV2=N8H5ARnq4Sz4HWZ=FBmn_g@mail.gmail.com' \
    --to=ardeleanalex@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=jic23@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH] iio: adc128s052: Simplify '\''adc128_probe()'\''' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).