diff mbox

[1/4,media] cpia2: Use common error handling code in cpia2_usb_probe()

Message ID a5c38437-f79b-e92e-b571-dd240090ca2b@users.sourceforge.net (mailing list archive)
State New, archived
Headers show

Commit Message

SF Markus Elfring Sept. 17, 2017, 1:31 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 17 Sep 2017 12:40:14 +0200
Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/usb/cpia2/cpia2_usb.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/drivers/media/usb/cpia2/cpia2_usb.c b/drivers/media/usb/cpia2/cpia2_usb.c
index 6089036049d9..c6be2786a66f 100644
--- a/drivers/media/usb/cpia2/cpia2_usb.c
+++ b/drivers/media/usb/cpia2/cpia2_usb.c
@@ -849,13 +849,11 @@  static int cpia2_usb_probe(struct usb_interface *intf,
 	if (ret < 0) {
 		ERR("%s: usb_set_interface error (ret = %d)\n", __func__, ret);
-		kfree(cam);
-		return ret;
+		goto free_data;
 	}
 
 
 	if((ret = cpia2_init_camera(cam)) < 0) {
 		ERR("%s: failed to initialize cpia2 camera (ret = %d)\n", __func__, ret);
-		kfree(cam);
-		return ret;
+		goto free_data;
 	}
 	LOG("  CPiA Version: %d.%02d (%d.%d)\n",
@@ -877,9 +875,12 @@  static int cpia2_usb_probe(struct usb_interface *intf,
 	if (ret < 0) {
 		ERR("%s: Failed to register cpia2 camera (ret = %d)\n", __func__, ret);
-		kfree(cam);
-		return ret;
+		goto free_data;
 	}
 
 	return 0;
+
+free_data:
+	kfree(cam);
+	return ret;
 }