[ patch -mm1 11/11 ] gpio-patchset-fixups: series

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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

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


Signed-off-by:   Jim Cromie <[email protected]>

---

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)


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux