linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-iio@vger.kernel.org,
	Crestez Dan Leonard <leonard.crestez@intel.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read()
Date: Thu, 26 Oct 2017 15:45:43 +0200	[thread overview]
Message-ID: <bbe04556-c62c-6074-d663-884a702614f4@users.sourceforge.net> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 26 Oct 2017 15:34:46 +0200

Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
Replace two calls of the function "dev_err" by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/iio/pressure/hp206c.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
index c38c19678cf6..978338f2a6e5 100644
--- a/drivers/iio/pressure/hp206c.c
+++ b/drivers/iio/pressure/hp206c.c
@@ -176,10 +176,8 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
 	struct i2c_client *client = data->client;
 
 	ret = hp206c_wait_dev_rdy(indio_dev);
-	if (ret < 0) {
-		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	ret = i2c_smbus_write_byte(client, conv_cmd);
 	if (ret < 0) {
@@ -190,16 +188,18 @@ static int hp206c_conv_and_read(struct iio_dev *indio_dev,
 	usleep_range(sleep_us, sleep_us * 3 / 2);
 
 	ret = hp206c_wait_dev_rdy(indio_dev);
-	if (ret < 0) {
-		dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
-		return ret;
-	}
+	if (ret < 0)
+		goto report_failure;
 
 	ret = hp206c_read_20bit(client, read_cmd);
 	if (ret < 0)
 		dev_err(&indio_dev->dev, "Failed read: %d\n", ret);
 
 	return ret;
+
+report_failure:
+	dev_err(&indio_dev->dev, "Device not ready: %d\n", ret);
+	return ret;
 }
 
 static int hp206c_read_raw(struct iio_dev *indio_dev,
-- 
2.14.3


             reply	other threads:[~2017-10-26 13:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-26 13:45 SF Markus Elfring [this message]
2017-10-26 16:23 ` [PATCH] iio/pressure/hp206c: Use common error handling code in hp206c_conv_and_read() Jonathan Cameron
2017-10-26 16:38   ` SF Markus Elfring
2017-10-26 16:44     ` 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=bbe04556-c62c-6074-d663-884a702614f4@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=jic23@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=leonard.crestez@intel.com \
    --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;
as well as URLs for NNTP newsgroup(s).