public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Daniel Baluta <daniel.baluta@intel.com>
Cc: martin@martingkelly.com, linux-iio <linux-iio@vger.kernel.org>
Subject: Re: [PATCH 2/2] iio: bmi160: use all devm functions in probe
Date: Sun, 25 Nov 2018 13:51:57 +0000	[thread overview]
Message-ID: <20181125135157.508659d6@archlinux> (raw)
In-Reply-To: <CAEnQRZB9fWnCr_V68MAF5VRS32Ge4oXQ7dCL2AhnyEYuJWeiPQ@mail.gmail.com>

On Mon, 19 Nov 2018 10:48:20 +0200
Daniel Baluta <daniel.baluta@intel.com> wrote:

> On Mon, Nov 19, 2018 at 2:55 AM Martin Kelly <martin@martingkelly.com> wrote:
> >
> > From: Martin Kelly <martin@martingkelly.com>
> >
> > Currently, we're using the devm version of some but not all functions.
> > Switch to the devm version of iio_triggered_buffer_setup and
> > iio_device_register to simplify the code a bit and decrease the chance of
> > bugs.  
> 
> Yes, it makes sense.
> 
> Acked-by: Daniel Baluta <daniel.baluta@gmail.com>
Here we disagree :).  This results in the chip being uninitialized
via bmi160_chip_uninit before we remove the user space interfaces.
So the combination that is there right now was very deliberate
and is correct - that's not to say it can't be improved upon.

So if you do want to do this you need to ensure that operation
automatically occurs in the correct point in the remove and error
flows.

devm_add_action_or_reset is your friend here as it'll let you call
that uninit from the automatic unwinding path and hence at the
correct point.

Thanks,

Jonathan

> 
> >
> > Signed-off-by: Martin Kelly <martin@martingkelly.com>
> > ---
> >  drivers/iio/imu/bmi160/bmi160_core.c | 12 ++++--------
> >  1 file changed, 4 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> > index 4d9d59d9e3a9..5e4efaed5e88 100644
> > --- a/drivers/iio/imu/bmi160/bmi160_core.c
> > +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> > @@ -577,18 +577,16 @@ int bmi160_core_probe(struct device *dev, struct regmap *regmap,
> >         indio_dev->modes = INDIO_DIRECT_MODE;
> >         indio_dev->info = &bmi160_info;
> >
> > -       ret = iio_triggered_buffer_setup(indio_dev, NULL,
> > -                                        bmi160_trigger_handler, NULL);
> > +       ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> > +                                             bmi160_trigger_handler, NULL);
> >         if (ret < 0)
> >                 goto uninit;
> >
> > -       ret = iio_device_register(indio_dev);
> > +       ret = devm_iio_device_register(dev, indio_dev);
> >         if (ret < 0)
> > -               goto buffer_cleanup;
> > +               goto uninit;
> >
> >         return 0;
> > -buffer_cleanup:
> > -       iio_triggered_buffer_cleanup(indio_dev);
> >  uninit:
> >         bmi160_chip_uninit(data);
> >         return ret;
> > @@ -600,8 +598,6 @@ void bmi160_core_remove(struct device *dev)
> >         struct iio_dev *indio_dev = dev_get_drvdata(dev);
> >         struct bmi160_data *data = iio_priv(indio_dev);
> >
> > -       iio_device_unregister(indio_dev);
> > -       iio_triggered_buffer_cleanup(indio_dev);
> >         bmi160_chip_uninit(data);
> >  }
> >  EXPORT_SYMBOL_GPL(bmi160_core_remove);
> > --
> > 2.11.0
> >  

  reply	other threads:[~2018-11-26  0:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-19  0:53 [PATCH 1/2] iio: bmi160: snap timestamp closer to event Martin Kelly
2018-11-19  0:53 ` [PATCH 2/2] iio: bmi160: use all devm functions in probe Martin Kelly
2018-11-19  8:48   ` Daniel Baluta
2018-11-25 13:51     ` Jonathan Cameron [this message]
2018-11-26 23:45       ` Martin Kelly
2018-11-19  8:45 ` [PATCH 1/2] iio: bmi160: snap timestamp closer to event Daniel Baluta
2018-11-20  3:45   ` Martin Kelly
2018-11-20  3:45   ` Martin Kelly
2018-11-25 13:59 ` Jonathan Cameron
2018-11-26 23:43   ` Martin Kelly
2018-12-01 14:58     ` Jonathan Cameron

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=20181125135157.508659d6@archlinux \
    --to=jic23@kernel.org \
    --cc=daniel.baluta@intel.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=martin@martingkelly.com \
    /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