From: Jonathan Cameron <jic23@kernel.org>
To: William Breathitt Gray <vilhelm.gray@gmail.com>,
knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/3] iio: stx104: Unregister IIO device on remove callback
Date: Sun, 24 Jul 2016 14:20:49 +0100 [thread overview]
Message-ID: <89591cf2-5219-5043-294e-0299bb9d2794@kernel.org> (raw)
In-Reply-To: <704fdc7b267770e76b061943da02b8a93fa37c3b.1468944073.git.vilhelm.gray@gmail.com>
On 19/07/16 17:25, William Breathitt Gray wrote:
> The devm_iio_device_register function should not be used if custom
> operations must be performed in the remove callback. This patch replaces
> the dem_iio_device_register call with a iio_device_register call and
> respective iio_device_unregister call in the remove callback.
>
> Fixes: 765550e4d98d ("iio: stx104: Add GPIO support for the Apex Embedded Systems STX104")
> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Applied to the fixes-togreg-post-rc1 branch (it's more convenient
right now than the fixes-togreg branch) and marked for stable.
These will go upstream in a few weeks after I'm back from travelling
and the merge windows has closed.
Thanks,
Jonathan
> ---
> drivers/iio/dac/stx104.c | 38 +++++++++++++++++++++++++++++---------
> 1 file changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/dac/stx104.c b/drivers/iio/dac/stx104.c
> index 792a971..bebbd00 100644
> --- a/drivers/iio/dac/stx104.c
> +++ b/drivers/iio/dac/stx104.c
> @@ -65,6 +65,16 @@ struct stx104_gpio {
> unsigned int out_state;
> };
>
> +/**
> + * struct stx104_dev - STX104 device private data structure
> + * @indio_dev: IIO device
> + * @chip: instance of the gpio_chip
> + */
> +struct stx104_dev {
> + struct iio_dev *indio_dev;
> + struct gpio_chip *chip;
> +};
> +
> static int stx104_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan, int *val, int *val2, long mask)
> {
> @@ -107,6 +117,7 @@ static const struct iio_chan_spec stx104_channels[STX104_NUM_CHAN] = {
> static int stx104_gpio_get_direction(struct gpio_chip *chip,
> unsigned int offset)
> {
> + /* GPIO 0-3 are input only, while the rest are output only */
> if (offset < 4)
> return 1;
>
> @@ -169,6 +180,7 @@ static int stx104_probe(struct device *dev, unsigned int id)
> struct iio_dev *indio_dev;
> struct stx104_iio *priv;
> struct stx104_gpio *stx104gpio;
> + struct stx104_dev *stx104dev;
> int err;
>
> indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
> @@ -179,6 +191,10 @@ static int stx104_probe(struct device *dev, unsigned int id)
> if (!stx104gpio)
> return -ENOMEM;
>
> + stx104dev = devm_kzalloc(dev, sizeof(*stx104dev), GFP_KERNEL);
> + if (!stx104dev)
> + return -ENOMEM;
> +
> if (!devm_request_region(dev, base[id], STX104_EXTENT,
> dev_name(dev))) {
> dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
> @@ -199,12 +215,6 @@ static int stx104_probe(struct device *dev, unsigned int id)
> outw(0, base[id] + 4);
> outw(0, base[id] + 6);
>
> - err = devm_iio_device_register(dev, indio_dev);
> - if (err) {
> - dev_err(dev, "IIO device registering failed (%d)\n", err);
> - return err;
> - }
> -
> stx104gpio->chip.label = dev_name(dev);
> stx104gpio->chip.parent = dev;
> stx104gpio->chip.owner = THIS_MODULE;
> @@ -220,7 +230,9 @@ static int stx104_probe(struct device *dev, unsigned int id)
>
> spin_lock_init(&stx104gpio->lock);
>
> - dev_set_drvdata(dev, stx104gpio);
> + stx104dev->indio_dev = indio_dev;
> + stx104dev->chip = &stx104gpio->chip;
> + dev_set_drvdata(dev, stx104dev);
>
> err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
> if (err) {
> @@ -228,14 +240,22 @@ static int stx104_probe(struct device *dev, unsigned int id)
> return err;
> }
>
> + err = iio_device_register(indio_dev);
> + if (err) {
> + dev_err(dev, "IIO device registering failed (%d)\n", err);
> + gpiochip_remove(&stx104gpio->chip);
> + return err;
> + }
> +
> return 0;
> }
>
> static int stx104_remove(struct device *dev, unsigned int id)
> {
> - struct stx104_gpio *const stx104gpio = dev_get_drvdata(dev);
> + struct stx104_dev *const stx104dev = dev_get_drvdata(dev);
>
> - gpiochip_remove(&stx104gpio->chip);
> + iio_device_unregister(stx104dev->indio_dev);
> + gpiochip_remove(stx104dev->chip);
>
> return 0;
> }
>
next prev parent reply other threads:[~2016-07-24 13:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-19 16:24 [PATCH v2 0/3] iio: stx104: Add IIO support for the ADC channels William Breathitt Gray
2016-07-19 16:25 ` [PATCH v2 1/3] iio: stx104: Unregister IIO device on remove callback William Breathitt Gray
2016-07-24 13:20 ` Jonathan Cameron [this message]
2016-07-19 16:25 ` [PATCH v2 2/3] iio: stx104: Add IIO support for the ADC channels William Breathitt Gray
2016-07-24 13:18 ` Jonathan Cameron
2016-07-19 16:25 ` [PATCH v2 3/3] iio: stx104: Move the STX104 IIO driver to the ADC directory William Breathitt Gray
2016-07-24 13:22 ` 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=89591cf2-5219-5043-294e-0299bb9d2794@kernel.org \
--to=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=vilhelm.gray@gmail.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
Powered by JetHome