staging: nvec: convert to devm_ functions
authorMarc Dietrich <marvin24@gmx.de>
Sun, 24 Jun 2012 21:25:16 +0000 (23:25 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Jun 2012 17:55:37 +0000 (10:55 -0700)
This patch cleanups the nvec and its childs by replacing calls to
resource allocations by their devm_* equivalents.

Signed-off-by: Marc Dietrich <marvin24@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/nvec/nvec.c
drivers/staging/nvec/nvec_leds.c
drivers/staging/nvec/nvec_power.c
drivers/staging/nvec/nvec_ps2.c

index 3c60088871e0b137dbc0632c634fc86b6aabaf4f..47ffdb834203d8979f8c7fc98b686ef12bb6c0d1 100644 (file)
@@ -719,10 +719,9 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
        struct nvec_chip *nvec;
        struct nvec_msg *msg;
        struct resource *res;
-       struct resource *iomem;
        void __iomem *base;
 
-       nvec = kzalloc(sizeof(struct nvec_chip), GFP_KERNEL);
+       nvec = devm_kzalloc(&pdev->dev, sizeof(struct nvec_chip), GFP_KERNEL);
        if (nvec == NULL) {
                dev_err(&pdev->dev, "failed to reserve memory\n");
                return -ENOMEM;
@@ -737,15 +736,15 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
                nvec->gpio = of_get_named_gpio(nvec->dev->of_node, "request-gpios", 0);
                if (nvec->gpio < 0) {
                        dev_err(&pdev->dev, "no gpio specified");
-                       goto failed;
+                       return -ENODEV;
                }
                if (of_property_read_u32(nvec->dev->of_node, "slave-addr", &nvec->i2c_addr)) {
                        dev_err(&pdev->dev, "no i2c address specified");
-                       goto failed;
+                       return -ENODEV;
                }
        } else {
                dev_err(&pdev->dev, "no platform data\n");
-               goto failed;
+               return -ENODEV;
        }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -754,13 +753,7 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
                return -ENODEV;
        }
 
-       iomem = request_mem_region(res->start, resource_size(res), pdev->name);
-       if (!iomem) {
-               dev_err(&pdev->dev, "I2C region already claimed\n");
-               return -EBUSY;
-       }
-
-       base = ioremap(iomem->start, resource_size(iomem));
+       base = devm_request_and_ioremap(&pdev->dev, res);
        if (!base) {
                dev_err(&pdev->dev, "Can't ioremap I2C region\n");
                return -ENOMEM;
@@ -769,14 +762,13 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (!res) {
                dev_err(&pdev->dev, "no irq resource?\n");
-               ret = -ENODEV;
-               goto err_iounmap;
+               return -ENODEV;
        }
 
        i2c_clk = clk_get_sys("tegra-i2c.2", NULL);
        if (IS_ERR(i2c_clk)) {
                dev_err(nvec->dev, "failed to get controller clock\n");
-               goto err_iounmap;
+               return -ENODEV;
        }
 
        nvec->base = base;
@@ -797,16 +789,20 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
        INIT_WORK(&nvec->tx_work, nvec_request_master);
        nvec->wq = alloc_workqueue("nvec", WQ_NON_REENTRANT, 2);
 
-       err = gpio_request_one(nvec->gpio, GPIOF_OUT_INIT_HIGH, "nvec gpio");
+       err = devm_gpio_request_one(&pdev->dev, nvec->gpio, GPIOF_OUT_INIT_HIGH,
+                                       "nvec gpio");
        if (err < 0) {
                dev_err(nvec->dev, "couldn't request gpio\n");
-               goto failed;
+               destroy_workqueue(nvec->wq);
+               return -ENODEV;
        }
 
-       err = request_irq(nvec->irq, nvec_interrupt, 0, "nvec", nvec);
+       err = devm_request_irq(&pdev->dev, nvec->irq, nvec_interrupt, 0,
+                               "nvec", nvec);
        if (err) {
                dev_err(nvec->dev, "couldn't request irq\n");
-               goto failed;
+               destroy_workqueue(nvec->wq);
+               return -ENODEV;
        }
        disable_irq(nvec->irq);
 
@@ -851,12 +847,6 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
        nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7);
 
        return 0;
-
-err_iounmap:
-       iounmap(base);
-failed:
-       kfree(nvec);
-       return -ENOMEM;
 }
 
 static int __devexit tegra_nvec_remove(struct platform_device *pdev)
@@ -865,11 +855,7 @@ static int __devexit tegra_nvec_remove(struct platform_device *pdev)
 
        nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3);
        mfd_remove_devices(nvec->dev);
-       free_irq(nvec->irq, &nvec_interrupt);
-       iounmap(nvec->base);
-       gpio_free(nvec->gpio);
        destroy_workqueue(nvec->wq);
-       kfree(nvec);
 
        return 0;
 }
index f4cbcd6250014ce87a7976ffddd82ab52702d1dd..91947fb860679e3233c3d741806ea82847072413 100644 (file)
@@ -49,7 +49,7 @@ static int __devinit nvec_led_probe(struct platform_device *pdev)
        struct nvec_led *led;
        int ret = 0;
 
-       led = kzalloc(sizeof(*led), GFP_KERNEL);
+       led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
        if (led == NULL)
                return -ENOMEM;
 
@@ -64,16 +64,12 @@ static int __devinit nvec_led_probe(struct platform_device *pdev)
 
        ret = led_classdev_register(&pdev->dev, &led->cdev);
        if (ret < 0)
-               goto err_led;
+               return ret;
 
        /* to expose the default value to userspace */
        led->cdev.brightness = 0;
 
        return 0;
-
-err_led:
-       kfree(led);
-       return ret;
 }
 
 static int __devexit nvec_led_remove(struct platform_device *pdev)
@@ -81,7 +77,7 @@ static int __devexit nvec_led_remove(struct platform_device *pdev)
        struct nvec_led *led = platform_get_drvdata(pdev);
 
        led_classdev_unregister(&led->cdev);
-       kfree(led);
+
        return 0;
 }
 
index dfa966f6189d0744ab16bf0b80333b76833b93c4..a23e5485c2793284ff987018ea4b617d1ce89ced 100644 (file)
@@ -371,10 +371,13 @@ static void nvec_power_poll(struct work_struct *work)
 static int __devinit nvec_power_probe(struct platform_device *pdev)
 {
        struct power_supply *psy;
-       struct nvec_power *power =
-           kzalloc(sizeof(struct nvec_power), GFP_NOWAIT);
+       struct nvec_power *power;
        struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
 
+       power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_NOWAIT);
+       if (power == NULL)
+               return -ENOMEM;
+
        dev_set_drvdata(&pdev->dev, power);
        power->nvec = nvec;
 
@@ -393,7 +396,6 @@ static int __devinit nvec_power_probe(struct platform_device *pdev)
                power->notifier.notifier_call = nvec_power_bat_notifier;
                break;
        default:
-               kfree(power);
                return -ENODEV;
        }
 
index 14a6f687cf751f9e5297b6ccf431b641c7afcf9c..d6ceff93d8b649a62e054673ced407f0bd29851c 100644 (file)
@@ -96,7 +96,11 @@ static int nvec_ps2_notifier(struct notifier_block *nb,
 static int __devinit nvec_mouse_probe(struct platform_device *pdev)
 {
        struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
-       struct serio *ser_dev = kzalloc(sizeof(struct serio), GFP_KERNEL);
+       struct serio *ser_dev;
+
+       ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL);
+       if (ser_dev == NULL)
+               return -ENOMEM;
 
        ser_dev->id.type = SERIO_PS_PSTHRU;
        ser_dev->write = ps2_sendcommand;