public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Linux kernel <linux-kernel@vger.kernel.org>
Subject: [ patch -mm1 11/11 ] gpio-patchset-fixups: series
Date: Thu, 22 Jun 2006 13:02:54 -0600	[thread overview]
Message-ID: <449AE95E.2010604@gmail.com> (raw)


diff.19-fix-pc8736x-modinit-err-undos

Rework the module-init function to properly undo initialization steps on 
failures.


Signed-off-by:   Jim Cromie <jim.cromie@gmail.com>

---

diff -ruNp -X dontdiff -X exclude-diffs ab-1/drivers/char/pc8736x_gpio.c ab-2/drivers/char/pc8736x_gpio.c
--- ab-1/drivers/char/pc8736x_gpio.c	2006-06-21 11:45:23.000000000 -0600
+++ ab-2/drivers/char/pc8736x_gpio.c	2006-06-21 12:23:01.000000000 -0600
@@ -257,7 +257,7 @@ static void __init pc8736x_init_shadow(v
 
 static int __init pc8736x_gpio_init(void)
 {
-	int r, rc;
+	int rc = 0;
 
 	pdev = platform_device_alloc(DEVNAME, 0);
 	if (!pdev)
@@ -265,15 +265,15 @@ static int __init pc8736x_gpio_init(void
 
 	rc = platform_device_add(pdev);
 	if (rc) {
-		platform_device_put(pdev);
-		return -ENODEV;
+		rc = -ENODEV;
+		goto undo_platform_dev_alloc;
 	}
 	dev_info(&pdev->dev, "NatSemi pc8736x GPIO Driver Initializing\n");
 
 	if (!pc8736x_superio_present()) {
+		rc = -ENODEV;
 		dev_err(&pdev->dev, "no device found\n");
-		platform_device_put(pdev);
-		return -ENODEV;
+		goto undo_platform_dev_add;
 	}
 	pc8736x_access.dev = &pdev->dev;
 
@@ -282,13 +282,15 @@ static int __init pc8736x_gpio_init(void
 	 */
 	rc = superio_inb(SIO_CF1);
 	if (!(rc & 0x01)) {
+		rc = -ENODEV;
 		dev_err(&pdev->dev, "device not enabled\n");
-		return -ENODEV;
+		goto undo_platform_dev_add;
 	}
 	device_select(SIO_GPIO_UNIT);
 	if (!superio_inb(SIO_UNIT_ACT)) {
+		rc = -ENODEV;
 		dev_err(&pdev->dev, "GPIO unit not enabled\n");
-		return -ENODEV;
+		goto undo_platform_dev_add;
 	}
 
 	/* read the GPIO unit base addr that chip responds to */
@@ -296,24 +298,31 @@ static int __init pc8736x_gpio_init(void
 			     | superio_inb(SIO_BASE_LADDR));
 
 	if (!request_region(pc8736x_gpio_base, 16, DEVNAME)) {
+		rc = -ENODEV;
 		dev_err(&pdev->dev, "GPIO ioport %x busy\n",
 			pc8736x_gpio_base);
-		return -ENODEV;
+		goto undo_platform_dev_add;
 	}
 	dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base);
 
-	r = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops);
-	if (r < 0) {
-		dev_err(&pdev->dev, "unable to register character device\n");
-		return r;
+	rc = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops);
+	if (rc < 0) {
+		dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc);
+		goto undo_platform_dev_add;
 	}
 	if (!major) {
-		major = r;
+		major = rc;
 		dev_dbg(&pdev->dev, "got dynamic major %d\n", major);
 	}
 
 	pc8736x_init_shadow();
 	return 0;
+
+undo_platform_dev_add:
+	platform_device_put(pdev);
+undo_platform_dev_alloc:
+	kfree(pdev);
+	return rc;
 }
 
 static void __exit pc8736x_gpio_cleanup(void)



                 reply	other threads:[~2006-06-22 19:03 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=449AE95E.2010604@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@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