mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] ALSA: i2c: Use common error handling code in two functions
Date: Sat, 11 Nov 2017 17:17:04 +0100	[thread overview]
Message-ID: <1af701eb-c379-336f-aa00-28c30cd33d51@users.sourceforge.net> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 17:10:24 +0100

Add jump targets so that a bit of exception handling can be better reused
at the end of these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/i2c/i2c.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/sound/i2c/i2c.c b/sound/i2c/i2c.c
index ef2a9afe9e19..9292aa60f3a2 100644
--- a/sound/i2c/i2c.c
+++ b/sound/i2c/i2c.c
@@ -282,20 +282,22 @@ static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device,
 		return -EIO;		/* not yet implemented */
 	snd_i2c_bit_start(bus);
 	err = snd_i2c_bit_sendbyte(bus, device->addr << 1);
-	if (err < 0) {
-		snd_i2c_bit_hw_stop(bus);
-		return err;
-	}
+	if (err < 0)
+		goto stop_bus;
+
 	while (count-- > 0) {
 		err = snd_i2c_bit_sendbyte(bus, *bytes++);
-		if (err < 0) {
-			snd_i2c_bit_hw_stop(bus);
-			return err;
-		}
+		if (err < 0)
+			goto stop_bus;
+
 		res++;
 	}
 	snd_i2c_bit_stop(bus);
 	return res;
+
+stop_bus:
+	snd_i2c_bit_hw_stop(bus);
+	return err;
 }
 
 static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
@@ -308,21 +310,23 @@ static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
 		return -EIO;		/* not yet implemented */
 	snd_i2c_bit_start(bus);
 	err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1);
-	if (err < 0) {
-		snd_i2c_bit_hw_stop(bus);
-		return err;
-	}
+	if (err < 0)
+		goto stop_bus;
+
 	while (count-- > 0) {
 		err = snd_i2c_bit_readbyte(bus, count == 0);
-		if (err < 0) {
-			snd_i2c_bit_hw_stop(bus);
-			return err;
-		}
+		if (err < 0)
+			goto stop_bus;
+
 		*bytes++ = (unsigned char)err;
 		res++;
 	}
 	snd_i2c_bit_stop(bus);
 	return res;
+
+stop_bus:
+	snd_i2c_bit_hw_stop(bus);
+	return err;
 }
 
 static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
-- 
2.15.0

                 reply	other threads:[~2017-11-11 16:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1af701eb-c379-336f-aa00-28c30cd33d51@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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