From: Karim Eshapa <karim.eshapa@gmail.com>
To: lars@metafoo.de
Cc: Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de,
pmeerw@pmeerw.net, gregkh@linuxfoundation.org,
linux-iio@vger.kernel.org, devel@driverdev.osuosl.org,
linux-kernel@vger.kernel.org,
Karim Eshapa <karim.eshapa@gmail.com>
Subject: [PATCH] staging:iio:adc:ad7816: Backward resources cleanups in probe
Date: Tue, 19 Jun 2018 01:38:51 +0200 [thread overview]
Message-ID: <20180618233851.7992-1-karim.eshapa@gmail.com> (raw)
Backward cleanups for all resources allocated in probing
in case of failure at any regestering or allocation step.
Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>
---
drivers/staging/iio/adc/ad7816.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index bf76a8620bdb..5ff14c830451 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -373,7 +373,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
if (ret) {
dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
chip->rdwr_pin);
- return ret;
+ goto device_free;
}
gpio_direction_input(chip->rdwr_pin);
ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin,
@@ -381,7 +381,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
if (ret) {
dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n",
chip->convert_pin);
- return ret;
+ goto free_rdwr_pin;
}
gpio_direction_input(chip->convert_pin);
ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin,
@@ -389,7 +389,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
if (ret) {
dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n",
chip->busy_pin);
- return ret;
+ goto free_convert_pin;
}
gpio_direction_input(chip->busy_pin);
@@ -407,17 +407,29 @@ static int ad7816_probe(struct spi_device *spi_dev)
indio_dev->name,
indio_dev);
if (ret)
- return ret;
+ goto free_busy_pin;
}
ret = devm_iio_device_register(&spi_dev->dev, indio_dev);
if (ret)
- return ret;
+ goto free_dev_irq;
dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
indio_dev->name);
return 0;
+free_dev_irq:
+ devm_free_irq(&spi_dev->dev, spi_dev->irq, indio_dev);
+free_busy_pin:
+ devm_gpio_free(&spi_dev->dev, chip->busy_pin);
+free_convert_pin:
+ devm_gpio_free(&spi_dev->dev, chip->convert_pin);
+free_rdwr_pin:
+ devm_gpio_free(&spi_dev->dev, chip->rdwr_pin);
+device_free:
+ devm_iio_device_free(&spi_dev->dev, indio_dev);
+
+ return ret;
}
static const struct spi_device_id ad7816_id[] = {
--
2.17.1
next reply other threads:[~2018-06-18 23:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-18 23:38 Karim Eshapa [this message]
2018-06-19 5:59 ` Lars-Peter Clausen
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=20180618233851.7992-1-karim.eshapa@gmail.com \
--to=karim.eshapa@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=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 \
/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
all inboxes | Powered by JetHome®