mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-media@vger.kernel.org,
	Daniele Nicolodi <daniele@grinta.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Max Kellermann <max.kellermann@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] [media] bt8xx: Use common error handling code in two functions
Date: Mon, 25 Sep 2017 22:18:29 +0200	[thread overview]
Message-ID: <7ad78087-fdd4-b76b-d770-81b9a55aaabd@users.sourceforge.net> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 25 Sep 2017 22:10:17 +0200

Adjust 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>
---
 drivers/media/pci/bt8xx/dst.c    | 19 +++++++++++--------
 drivers/media/pci/bt8xx/dst_ca.c | 30 +++++++++++++++---------------
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/media/pci/bt8xx/dst.c b/drivers/media/pci/bt8xx/dst.c
index 7166d2279465..1290419aca0b 100644
--- a/drivers/media/pci/bt8xx/dst.c
+++ b/drivers/media/pci/bt8xx/dst.c
@@ -134,17 +134,20 @@ EXPORT_SYMBOL(rdc_reset_state);
 static int rdc_8820_reset(struct dst_state *state)
 {
 	dprintk(3, "Resetting DST\n");
-	if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
-		pr_err("dst_gpio_outb ERROR !\n");
-		return -1;
-	}
+	if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY)
+	    < 0)
+		goto report_failure;
+
 	udelay(1000);
-	if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
-		pr_err("dst_gpio_outb ERROR !\n");
-		return -1;
-	}
+	if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET,
+			  RDC_8820_RESET, DELAY) < 0)
+		goto report_failure;
 
 	return 0;
+
+report_failure:
+	pr_err("dst_gpio_outb ERROR !\n");
+	return -1;
 }
 
 static int dst_pio_enable(struct dst_state *state)
diff --git a/drivers/media/pci/bt8xx/dst_ca.c b/drivers/media/pci/bt8xx/dst_ca.c
index 90f4263452d3..5ea0a9c9a590 100644
--- a/drivers/media/pci/bt8xx/dst_ca.c
+++ b/drivers/media/pci/bt8xx/dst_ca.c
@@ -97,33 +97,33 @@ static int dst_ci_command(struct dst_state* state, u8 * data, u8 *ca_string, u8
 
 	if (write_dst(state, data, len)) {
 		dprintk(verbose, DST_CA_INFO, 1, " Write not successful, trying to recover");
-		dst_error_recovery(state);
-		goto error;
+		goto error_recovery;
 	}
 	if ((dst_pio_disable(state)) < 0) {
 		dprintk(verbose, DST_CA_ERROR, 1, " DST PIO disable failed.");
-		goto error;
-	}
-	if (read_dst(state, &reply, GET_ACK) < 0) {
-		dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
-		dst_error_recovery(state);
-		goto error;
+		goto unlock;
 	}
+	if (read_dst(state, &reply, GET_ACK) < 0)
+		goto report_read_failure;
+
 	if (read) {
 		if (! dst_wait_dst_ready(state, LONG_DELAY)) {
 			dprintk(verbose, DST_CA_NOTICE, 1, " 8820 not ready");
-			goto error;
-		}
-		if (read_dst(state, ca_string, 128) < 0) {	/*	Try to make this dynamic	*/
-			dprintk(verbose, DST_CA_INFO, 1, " Read not successful, trying to recover");
-			dst_error_recovery(state);
-			goto error;
+			goto unlock;
 		}
+		/* Try to make this dynamic */
+		if (read_dst(state, ca_string, 128) < 0)
+			goto report_read_failure;
 	}
 	mutex_unlock(&state->dst_mutex);
 	return 0;
 
-error:
+report_read_failure:
+	dprintk(verbose, DST_CA_INFO, 1,
+		" Read not successful, trying to recover");
+error_recovery:
+	dst_error_recovery(state);
+unlock:
 	mutex_unlock(&state->dst_mutex);
 	return -EIO;
 }
-- 
2.14.1

             reply	other threads:[~2017-09-25 20:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-25 20:18 SF Markus Elfring [this message]
2017-09-27  9:58 ` Dan Carpenter

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=7ad78087-fdd4-b76b-d770-81b9a55aaabd@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=daniele@grinta.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=max.kellermann@gmail.com \
    --cc=mchehab@kernel.org \
    /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®