Messages in this thread Patch in this message | | | Date | Thu, 22 Jun 2006 13:02:54 -0600 | From | Jim Cromie <> | Subject | [ patch -mm1 11/11 ] gpio-patchset-fixups: series |
| |
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)
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |