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, Bhumika Goyal <bhumirks@gmail.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Johan Hovold <johan@kernel.org>,
	Julia Lawall <Julia.Lawall@lip6.fr>,
	Matthias Schwarzott <zzam@gentoo.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Oleh Kravchenko <oleg@kaa.org.ua>, Peter Rosin <peda@axentia.se>,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 8/8] [media] cx231xx: Use common error handling code in cx231xx_load_firmware()
Date: Sun, 17 Sep 2017 22:24:16 +0200	[thread overview]
Message-ID: <57f0d209-1b87-690c-589a-bff8e0ffe24f@users.sourceforge.net> (raw)
In-Reply-To: <f2c1ca56-ecdc-318c-f18f-9bef6c670ffb@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 17 Sep 2017 21:07:39 +0200

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

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cx231xx/cx231xx-417.c | 61 ++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 32 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index d43345593172..88aac129b678 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -954,16 +954,13 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
 
 	p_current_fw = vmalloc(1884180 * 4);
 	p_fw = p_current_fw;
-	if (!p_current_fw) {
-		dprintk(2, "FAIL!!!\n");
-		return -ENOMEM;
-	}
+	if (!p_current_fw)
+		goto e_nomem;
 
 	p_buffer = vmalloc(4096);
 	if (!p_buffer) {
-		dprintk(2, "FAIL!!!\n");
 		vfree(p_current_fw);
-		return -ENOMEM;
+		goto e_nomem;
 	}
 
 	dprintk(2, "%s()\n", __func__);
@@ -986,9 +983,7 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
 	if (retval != 0) {
 		dev_err(dev->dev,
 			"%s: Error with mc417_register_write\n", __func__);
-		vfree(p_current_fw);
-		vfree(p_buffer);
-		return retval;
+		goto free_fw;
 	}
 
 	retval = request_firmware(&firmware, CX231xx_FIRM_IMAGE_NAME,
@@ -1000,28 +995,20 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
 			CX231xx_FIRM_IMAGE_NAME);
 		dev_err(dev->dev,
 			"Please fix your hotplug setup, the board will not work without firmware loaded!\n");
-		vfree(p_current_fw);
-		vfree(p_buffer);
-		return retval;
+		goto free_fw;
 	}
 
 	if (firmware->size != CX231xx_FIRM_IMAGE_SIZE) {
 		dev_err(dev->dev,
 			"ERROR: Firmware size mismatch (have %zd, expected %d)\n",
 			firmware->size, CX231xx_FIRM_IMAGE_SIZE);
-		release_firmware(firmware);
-		vfree(p_current_fw);
-		vfree(p_buffer);
-		return -EINVAL;
+		goto e_inval;
 	}
 
 	if (0 != memcmp(firmware->data, magic, 8)) {
 		dev_err(dev->dev,
 			"ERROR: Firmware magic mismatch, wrong file?\n");
-		release_firmware(firmware);
-		vfree(p_current_fw);
-		vfree(p_buffer);
-		return -EINVAL;
+		goto e_inval;
 	}
 
 	initGPIO(dev);
@@ -1065,26 +1052,36 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
 
 	retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS,
 		IVTV_CMD_HW_BLOCKS_RST);
-	if (retval < 0) {
-		dev_err(dev->dev,
-			"%s: Error with mc417_register_write\n",
-			__func__);
-		return retval;
-	}
+	if (retval < 0)
+		goto report_write_failure;
+
 	/* F/W power up disturbs the GPIOs, restore state */
 	retval |= mc417_register_write(dev, 0x9020, gpio_output);
 	retval |= mc417_register_write(dev, 0x900C, value);
 
 	retval |= mc417_register_read(dev, IVTV_REG_VPU, &value);
 	retval |= mc417_register_write(dev, IVTV_REG_VPU, value & 0xFFFFFFE8);
+	if (retval < 0)
+		goto report_write_failure;
 
-	if (retval < 0) {
-		dev_err(dev->dev,
-			"%s: Error with mc417_register_write\n",
-			__func__);
-		return retval;
-	}
 	return 0;
+
+e_nomem:
+	dprintk(2, "FAIL!!!\n");
+	return -ENOMEM;
+
+e_inval:
+	retval = -EINVAL;
+	release_firmware(firmware);
+
+free_fw:
+	vfree(p_current_fw);
+	vfree(p_buffer);
+	return retval;
+
+report_write_failure:
+	dev_err(dev->dev, "%s: Error with mc417_register_write\n", __func__);
+	return retval;
 }
 
 static void cx231xx_417_check_encoder(struct cx231xx *dev)
-- 
2.14.1

      parent reply	other threads:[~2017-09-17 20:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-17 20:15 [PATCH 0/8] [media] Cx231xx: Adjustments for several function implementations SF Markus Elfring
2017-09-17 20:16 ` [PATCH 1/8] [media] cx231xx: Delete eight error messages for a failed memory allocation SF Markus Elfring
2017-09-17 20:17 ` [PATCH 2/8] [media] cx231xx: Adjust 56 checks for null pointers SF Markus Elfring
2017-09-17 20:18 ` [PATCH 3/8] [media] cx231xx: Improve six size determinations SF Markus Elfring
2017-09-17 20:19 ` [PATCH 4/8] [media] cx231xx: Delete an unnecessary variable initialisation in dvb_init() SF Markus Elfring
2017-09-17 20:21 ` [PATCH 5/8] [media] cx231xx: Use common error handling code " SF Markus Elfring
2017-09-17 20:22 ` [PATCH 6/8] [media] cx231xx: Use common error handling code in read_eeprom() SF Markus Elfring
2017-09-17 20:23 ` [PATCH 7/8] [media] cx231xx: Delete an unnecessary variable initialisation " SF Markus Elfring
2017-09-17 20:24 ` SF Markus Elfring [this message]

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=57f0d209-1b87-690c-589a-bff8e0ffe24f@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=Julia.Lawall@lip6.fr \
    --cc=bhumirks@gmail.com \
    --cc=hans.verkuil@cisco.com \
    --cc=johan@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=oleg@kaa.org.ua \
    --cc=peda@axentia.se \
    --cc=sakari.ailus@linux.intel.com \
    --cc=zzam@gentoo.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®