public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: David Ellingsworth <david@identd.dyndns.org>
To: linux-media@vger.kernel.org, klimov.linux@gmail.com
Subject: [RFC/RFT 03/10] radio-mr800: simplify error paths in usb probe callback
Date: Sat, 12 Sep 2009 10:49:12 -0400	[thread overview]
Message-ID: <4AABB4E8.7030507@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2257 bytes --]

 From 0cdbd79a6e87a8a2862a6c1309c8fdf83c80ba61 Mon Sep 17 00:00:00 2001
From: David Ellingsworth <david@identd.dyndns.org>
Date: Sat, 12 Sep 2009 00:13:16 -0400
Subject: [PATCH 03/10] mr800: simplify error paths in usb probe callback

Signed-off-by: David Ellingsworth <david@identd.dyndns.org>
---
 drivers/media/radio/radio-mr800.c |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/media/radio/radio-mr800.c 
b/drivers/media/radio/radio-mr800.c
index 3129692..d01b96c 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -689,30 +689,29 @@ static int usb_amradio_probe(struct usb_interface 
*intf,
 {
     struct amradio_device *radio;
     struct v4l2_device *v4l2_dev;
-    int retval;
+    int retval = 0;
 
     radio = kzalloc(sizeof(struct amradio_device), GFP_KERNEL);
 
     if (!radio) {
         dev_err(&intf->dev, "kmalloc for amradio_device failed\n");
-        return -ENOMEM;
+        retval = -ENOMEM;
+        goto err;
     }
 
     radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
 
     if (!radio->buffer) {
         dev_err(&intf->dev, "kmalloc for radio->buffer failed\n");
-        kfree(radio);
-        return -ENOMEM;
+        retval = -ENOMEM;
+        goto err_nobuf;
     }
 
     v4l2_dev = &radio->v4l2_dev;
     retval = v4l2_device_register(&intf->dev, v4l2_dev);
     if (retval < 0) {
         dev_err(&intf->dev, "couldn't register v4l2_device\n");
-        kfree(radio->buffer);
-        kfree(radio);
-        return retval;
+        goto err_v4l2;
     }
 
     strlcpy(radio->videodev.name, v4l2_dev->name,
@@ -736,14 +735,20 @@ static int usb_amradio_probe(struct usb_interface 
*intf,
                     radio_nr);
     if (retval < 0) {
         dev_err(&intf->dev, "could not register video device\n");
-        v4l2_device_unregister(v4l2_dev);
-        kfree(radio->buffer);
-        kfree(radio);
-        return -EIO;
+        goto err_vdev;
     }
 
     usb_set_intfdata(intf, radio);
     return 0;
+
+err_vdev:
+    v4l2_device_unregister(v4l2_dev);
+err_v4l2:
+    kfree(radio->buffer);
+err_nobuf:
+    kfree(radio);
+err:
+    return retval;
 }
 
 static int __init amradio_init(void)
-- 
1.6.3.3


[-- Attachment #2: 0003-mr800-simplify-error-paths-in-usb-probe-callback.patch --]
[-- Type: text/x-diff, Size: 2050 bytes --]

>From 0cdbd79a6e87a8a2862a6c1309c8fdf83c80ba61 Mon Sep 17 00:00:00 2001
From: David Ellingsworth <david@identd.dyndns.org>
Date: Sat, 12 Sep 2009 00:13:16 -0400
Subject: [PATCH 03/10] mr800: simplify error paths in usb probe callback

Signed-off-by: David Ellingsworth <david@identd.dyndns.org>
---
 drivers/media/radio/radio-mr800.c |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index 3129692..d01b96c 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -689,30 +689,29 @@ static int usb_amradio_probe(struct usb_interface *intf,
 {
 	struct amradio_device *radio;
 	struct v4l2_device *v4l2_dev;
-	int retval;
+	int retval = 0;
 
 	radio = kzalloc(sizeof(struct amradio_device), GFP_KERNEL);
 
 	if (!radio) {
 		dev_err(&intf->dev, "kmalloc for amradio_device failed\n");
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto err;
 	}
 
 	radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
 
 	if (!radio->buffer) {
 		dev_err(&intf->dev, "kmalloc for radio->buffer failed\n");
-		kfree(radio);
-		return -ENOMEM;
+		retval = -ENOMEM;
+		goto err_nobuf;
 	}
 
 	v4l2_dev = &radio->v4l2_dev;
 	retval = v4l2_device_register(&intf->dev, v4l2_dev);
 	if (retval < 0) {
 		dev_err(&intf->dev, "couldn't register v4l2_device\n");
-		kfree(radio->buffer);
-		kfree(radio);
-		return retval;
+		goto err_v4l2;
 	}
 
 	strlcpy(radio->videodev.name, v4l2_dev->name,
@@ -736,14 +735,20 @@ static int usb_amradio_probe(struct usb_interface *intf,
 					radio_nr);
 	if (retval < 0) {
 		dev_err(&intf->dev, "could not register video device\n");
-		v4l2_device_unregister(v4l2_dev);
-		kfree(radio->buffer);
-		kfree(radio);
-		return -EIO;
+		goto err_vdev;
 	}
 
 	usb_set_intfdata(intf, radio);
 	return 0;
+
+err_vdev:
+	v4l2_device_unregister(v4l2_dev);
+err_v4l2:
+	kfree(radio->buffer);
+err_nobuf:
+	kfree(radio);
+err:
+	return retval;
 }
 
 static int __init amradio_init(void)
-- 
1.6.3.3


                 reply	other threads:[~2009-09-12 14:49 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=4AABB4E8.7030507@gmail.com \
    --to=david@identd.dyndns.org \
    --cc=klimov.linux@gmail.com \
    --cc=linux-media@vger.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