linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: rishi gupta <gupt21@gmail.com>
Cc: knaack.h@gmx.de, lars@metafoo.de,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	gregkh@linuxfoundation.org, tglx@linutronix.de,
	allison@lohutok.net, alexios.zavras@intel.com, angus@akkea.ca,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	robh+dt@kernel.org, mark.rutland@arm.com,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/3] iio: light: add driver for veml6030 ambient light sensor
Date: Sun, 27 Oct 2019 09:26:13 +0000	[thread overview]
Message-ID: <20191027092613.795b1c7c@archlinux> (raw)
In-Reply-To: <CALUj-guR0XBGLCx2WnTSGiaVPpKbPcSKNVhbb+N8VfS449_NJg@mail.gmail.com>

On Tue, 22 Oct 2019 18:02:51 +0530
rishi gupta <gupt21@gmail.com> wrote:

> Thanks Jonathan, sorry for deep thread, learnt will keep in mind.
> 
> All suggested changes done except re-ordering devm_add_action_or_reset.
> Please see inline and suggest if I missed something.
> 
...
> > > +static int veml6030_probe(struct i2c_client *client,
> > > +                       const struct i2c_device_id *id)
> > > +{
> > > +     int ret;
> > > +     struct veml6030_data *data;
> > > +     struct iio_dev *indio_dev;
> > > +     struct regmap *regmap;
> > > +
> > > +     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
> > > +             dev_err(&client->dev, "i2c adapter doesn't support plain i2c\n");
> > > +             return -EOPNOTSUPP;
> > > +     }
> > > +
> > > +     regmap = devm_regmap_init_i2c(client, &veml6030_regmap_config);
> > > +     if (IS_ERR(regmap)) {
> > > +             dev_err(&client->dev, "can't setup regmap\n");
> > > +             return PTR_ERR(regmap);
> > > +     }
> > > +
> > > +     indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> > > +     if (!indio_dev)
> > > +             return -ENOMEM;
> > > +
> > > +     data = iio_priv(indio_dev);
> > > +     i2c_set_clientdata(client, indio_dev);
> > > +     data->client = client;
> > > +     data->regmap = regmap;
> > > +
> > > +     indio_dev->dev.parent = &client->dev;
> > > +     indio_dev->name = "veml6030";
> > > +     indio_dev->channels = veml6030_channels;
> > > +     indio_dev->num_channels = ARRAY_SIZE(veml6030_channels);
> > > +     indio_dev->modes = INDIO_DIRECT_MODE;
> > > +
> > > +     if (client->irq) {
> > > +             ret = devm_request_threaded_irq(&client->dev, client->irq,
> > > +                                             NULL, veml6030_event_handler,
> > > +                                             IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> > > +                                             "veml6030", indio_dev);
> > > +             if (ret < 0) {
> > > +                     dev_err(&client->dev,
> > > +                                     "irq %d request failed\n", client->irq);
> > > +                     return ret;
> > > +             }
> > > +             indio_dev->info = &veml6030_info;
> > > +     } else {
> > > +             indio_dev->info = &veml6030_info_no_irq;
> > > +     }
> > > +
> > > +     ret = devm_add_action_or_reset(&client->dev,
> > > +                                     veml6030_als_shut_down_action, data);  
> >
> > What is this reversing?  It should be immediately after whatever that is, thus
> > ensuring we only undo whatever we need to on failure and the ordering is correct
> > for remove.  I am guessing it should be after hw_init.
> >  
> This just disables active measurements (this is the only thing we need
> to do when failure happens).
> 
> Suppose hw initialisation succeeds but call to
> devm_add_action_or_reset() fails. In this case sensor will be left
> turned on as veml6030_als_shut_down_action() will never be executed.
> Therefore I kept it before veml6030_hw_init().
> Does this sounds correct to you ?

Nope, that's the point of the _or_reset part of that call. Note that we used
to manually handle the result of devm_add_action, but this little wrapper
does that for us.

In all failure cases it will run the callback provided to it.
https://elixir.bootlin.com/linux/v4.8/source/include/linux/device.h#L688

So it should always be called 'after' the thing it is setting up the
unwinding function for.

Jonathan

> 
> > > +     if (ret < 0)
> > > +             return ret;
> > > +
> > > +     ret = veml6030_hw_init(indio_dev);
> > > +     if (ret < 0)
> > > +             return ret;
> > > +
> > > +     return devm_iio_device_register(&client->dev, indio_dev);
> > > +}

  reply	other threads:[~2019-10-27  9:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 10:51 [RESEND PATCH v2 0/3] Add driver for veml6030 ambient light sensor Rishi Gupta
2019-09-24 10:51 ` [RESEND PATCH v2 1/3] iio: light: add " Rishi Gupta
2019-10-05 14:08   ` Jonathan Cameron
2019-10-21 13:28     ` [PATCH v3 " Rishi Gupta
2019-10-22  3:57       ` [PATCH v4 " Rishi Gupta
2019-10-22 10:00         ` Jonathan Cameron
2019-10-22 12:32           ` rishi gupta
2019-10-27  9:26             ` Jonathan Cameron [this message]
2019-09-24 10:51 ` [RESEND PATCH v2 2/3] dt-bindings: iio: light: add veml6030 ALS bindings Rishi Gupta
2019-10-05 14:14   ` Jonathan Cameron
2019-10-21 13:31     ` [PATCH v3 " Rishi Gupta
2019-10-21 17:28       ` Rob Herring
2019-10-22  3:57         ` [PATCH v4 " Rishi Gupta
2019-09-24 10:51 ` [RESEND PATCH v2 3/3] iio: documentation: light: Add veml6030 sysfs documentation Rishi Gupta
2019-10-05 14:11   ` Jonathan Cameron
2019-10-21 13:31     ` [PATCH v3 " Rishi Gupta
2019-10-22  3:58       ` [PATCH v4 " Rishi Gupta
2019-10-22  9:48         ` Jonathan Cameron
2019-10-05 14:08 ` [RESEND PATCH v2 0/3] Add driver for veml6030 ambient light sensor Jonathan Cameron
2019-10-21 13:37   ` rishi gupta

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=20191027092613.795b1c7c@archlinux \
    --to=jic23@kernel.org \
    --cc=alexios.zavras@intel.com \
    --cc=allison@lohutok.net \
    --cc=angus@akkea.ca \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=gupt21@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=tglx@linutronix.de \
    /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 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).