All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: "Théo Borém Fabris" <theobf@usp.br>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	linux-iio <linux-iio@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] iio: dac: max5821: convert device register to device managed function
Date: Sat, 31 Jul 2021 18:17:55 +0100	[thread overview]
Message-ID: <20210731181755.6f1024a6@jic23-huawei> (raw)
In-Reply-To: <CA+U=DsrQyDsGHDZvnfyE0n8=gdgM4ivTuFFhtw1FO_oqNW+grg@mail.gmail.com>

On Mon, 26 Jul 2021 09:53:54 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Sun, Jul 25, 2021 at 1:06 AM Théo Borém Fabris <theobf@usp.br> wrote:
> >
> > Add a device managed hook, via devm_add_action_or_reset() and
> > max5821_regulator_disable(), to disable voltage regulator on device
> > detach.
> > Replace iio_device_register() by devm_iio_device_register() and remove
> > the max5821_remove() function used to unregister the device and disable the
> > voltage regulator.
> > Remove i2c_set_clientdata() from the probe function, since
> > i2c_get_clientdata() is not used anymore.
> > Remove regulator_disable() calls from the probe function.
> >  
> 
> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

Applied to the togreg branch of iio.git and pushed out as testing for 0-day
to see if it can find anything we missed.

Thanks,

Jonathan

> 
> > Signed-off-by: Théo Borém Fabris <theobf@usp.br>
> > ---
> > Changelog:
> > V1 -> V2: Removed regulator_disable() calls and goto statements
> >
> >  drivers/iio/dac/max5821.c | 41 ++++++++++++++++-----------------------
> >  1 file changed, 17 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
> > index bd6e75699a63..bd0b7f361154 100644
> > --- a/drivers/iio/dac/max5821.c
> > +++ b/drivers/iio/dac/max5821.c
> > @@ -294,6 +294,11 @@ static const struct iio_info max5821_info = {
> >         .write_raw = max5821_write_raw,
> >  };
> >
> > +static void max5821_regulator_disable(void *reg)
> > +{
> > +       regulator_disable(reg);
> > +}
> > +
> >  static int max5821_probe(struct i2c_client *client,
> >                         const struct i2c_device_id *id)
> >  {
> > @@ -306,7 +311,6 @@ static int max5821_probe(struct i2c_client *client,
> >         if (!indio_dev)
> >                 return -ENOMEM;
> >         data = iio_priv(indio_dev);
> > -       i2c_set_clientdata(client, indio_dev);
> >         data->client = client;
> >         mutex_init(&data->lock);
> >
> > @@ -321,21 +325,29 @@ static int max5821_probe(struct i2c_client *client,
> >                 ret = PTR_ERR(data->vref_reg);
> >                 dev_err(&client->dev,
> >                         "Failed to get vref regulator: %d\n", ret);
> > -               goto error_free_reg;
> > +               return ret;
> >         }
> >
> >         ret = regulator_enable(data->vref_reg);
> >         if (ret) {
> >                 dev_err(&client->dev,
> >                         "Failed to enable vref regulator: %d\n", ret);
> > -               goto error_free_reg;
> > +               return ret;
> > +       }
> > +
> > +       ret = devm_add_action_or_reset(&client->dev, max5821_regulator_disable,
> > +                                      data->vref_reg);
> > +       if (ret) {
> > +               dev_err(&client->dev,
> > +                       "Failed to add action to managed regulator: %d\n", ret);
> > +               return ret;
> >         }
> >
> >         ret = regulator_get_voltage(data->vref_reg);
> >         if (ret < 0) {
> >                 dev_err(&client->dev,
> >                         "Failed to get voltage on regulator: %d\n", ret);
> > -               goto error_disable_reg;
> > +               return ret;
> >         }
> >
> >         data->vref_mv = ret / 1000;
> > @@ -346,25 +358,7 @@ static int max5821_probe(struct i2c_client *client,
> >         indio_dev->modes = INDIO_DIRECT_MODE;
> >         indio_dev->info = &max5821_info;
> >
> > -       return iio_device_register(indio_dev);
> > -
> > -error_disable_reg:
> > -       regulator_disable(data->vref_reg);
> > -
> > -error_free_reg:
> > -
> > -       return ret;
> > -}
> > -
> > -static int max5821_remove(struct i2c_client *client)
> > -{
> > -       struct iio_dev *indio_dev = i2c_get_clientdata(client);
> > -       struct max5821_data *data = iio_priv(indio_dev);
> > -
> > -       iio_device_unregister(indio_dev);
> > -       regulator_disable(data->vref_reg);
> > -
> > -       return 0;
> > +       return devm_iio_device_register(&client->dev, indio_dev);
> >  }
> >
> >  static const struct i2c_device_id max5821_id[] = {
> > @@ -386,7 +380,6 @@ static struct i2c_driver max5821_driver = {
> >                 .pm     = &max5821_pm_ops,
> >         },
> >         .probe          = max5821_probe,
> > -       .remove         = max5821_remove,
> >         .id_table       = max5821_id,
> >  };
> >  module_i2c_driver(max5821_driver);
> > --
> > 2.20.1
> >  


      reply	other threads:[~2021-07-31 17:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-24 22:02 [PATCH v2] iio: dac: max5821: convert device register to device managed function Théo Borém Fabris
2021-07-26  6:53 ` Alexandru Ardelean
2021-07-31 17:17   ` Jonathan Cameron [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=20210731181755.6f1024a6@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=ardeleanalex@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=theobf@usp.br \
    /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.