From: Jonathan Cameron <jic23@kernel.org>
To: Slawomir Stepien <sst@poczta.fm>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, knaack.h@gmx.de,
pmeerw@pmeerw.net, linux-iio@vger.kernel.org,
gregkh@linuxfoundation.org
Subject: Re: [PATCH v6 1/2] staging: iio: adc: ad7280a: power down the device on error in probe
Date: Sun, 11 Nov 2018 17:00:41 +0000 [thread overview]
Message-ID: <20181111170041.5b8bfcc6@archlinux> (raw)
In-Reply-To: <20181111155911.3604-2-sst@poczta.fm>
On Sun, 11 Nov 2018 16:59:10 +0100
Slawomir Stepien <sst@poczta.fm> wrote:
> Power down the device if anything goes wrong after the SPI has been
> setup correctly in the probe function.
>
> Existing code that toggles the AD7280A_CTRL_LB_SWRST bit inside
> ad7280_chain_setup function is responsible for powering up the device.
>
> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
Hi Slawomir,
Nearly perfect... But see inline...
> ---
> drivers/staging/iio/adc/ad7280a.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
> index 58420dcb406d..3ab06fd87675 100644
> --- a/drivers/staging/iio/adc/ad7280a.c
> +++ b/drivers/staging/iio/adc/ad7280a.c
> @@ -870,7 +870,7 @@ static int ad7280_probe(struct spi_device *spi)
>
> ret = ad7280_chain_setup(st);
> if (ret < 0)
> - return ret;
> + goto error_power_down;
The ideal is always for a function to unwind on error to the point where
it leaves no visible side effects. As such we should power down 'inside'
chain_setup on error (unfortunately there are a lot exit paths in that
function so the resulting patch will be larger than this :(
This may seem a pain to do this way, but it makes the code flow
more obvious generally making things cleaner.
Rather than go around again for such a trivial thing, I've
made the change and pushed out the updated patch to the togreg
branch of iio.git as testing for the autobuilders to see if
I messed it up!
Note this will move the resulting devm call as well. I'll do that for
patch 2.
Jonathan
>
> st->slave_num = ret;
> st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH;
> @@ -901,7 +901,7 @@ static int ad7280_probe(struct spi_device *spi)
>
> ret = ad7280_channel_init(st);
> if (ret < 0)
> - return ret;
> + goto error_power_down;
>
> indio_dev->num_channels = ret;
> indio_dev->channels = st->channels;
> @@ -950,6 +950,9 @@ static int ad7280_probe(struct spi_device *spi)
> error_free_channels:
> kfree(st->channels);
>
> +error_power_down:
> + ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1,
> + AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb);
> return ret;
> }
>
next prev parent reply other threads:[~2018-11-12 2:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-11 15:59 [PATCH v6 0/2] staging: iio: adc: ad7280a: use devm API when applicable Slawomir Stepien
2018-11-11 15:59 ` [PATCH v6 1/2] staging: iio: adc: ad7280a: power down the device on error in probe Slawomir Stepien
2018-11-11 17:00 ` Jonathan Cameron [this message]
2018-11-11 15:59 ` [PATCH v6 2/2] staging: iio: adc: ad7280a: use devm_* APIs Slawomir Stepien
2018-11-11 17:04 ` Jonathan Cameron
2018-11-11 20:23 ` Slawomir Stepien
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=20181111170041.5b8bfcc6@archlinux \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=gregkh@linuxfoundation.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=sst@poczta.fm \
/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).