1
0
Fork 0

staging: nvec: convert to devm_ functions

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>
hifive-unleashed-5.1
Marc Dietrich 2012-06-24 23:25:16 +02:00 committed by Greg Kroah-Hartman
parent 59d6a29e55
commit f5e3352e51
4 changed files with 28 additions and 40 deletions

View File

@ -719,10 +719,9 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
struct nvec_chip *nvec; struct nvec_chip *nvec;
struct nvec_msg *msg; struct nvec_msg *msg;
struct resource *res; struct resource *res;
struct resource *iomem;
void __iomem *base; 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) { if (nvec == NULL) {
dev_err(&pdev->dev, "failed to reserve memory\n"); dev_err(&pdev->dev, "failed to reserve memory\n");
return -ENOMEM; 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); nvec->gpio = of_get_named_gpio(nvec->dev->of_node, "request-gpios", 0);
if (nvec->gpio < 0) { if (nvec->gpio < 0) {
dev_err(&pdev->dev, "no gpio specified"); 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)) { if (of_property_read_u32(nvec->dev->of_node, "slave-addr", &nvec->i2c_addr)) {
dev_err(&pdev->dev, "no i2c address specified"); dev_err(&pdev->dev, "no i2c address specified");
goto failed; return -ENODEV;
} }
} else { } else {
dev_err(&pdev->dev, "no platform data\n"); dev_err(&pdev->dev, "no platform data\n");
goto failed; return -ENODEV;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@ -754,13 +753,7 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
iomem = request_mem_region(res->start, resource_size(res), pdev->name); base = devm_request_and_ioremap(&pdev->dev, res);
if (!iomem) {
dev_err(&pdev->dev, "I2C region already claimed\n");
return -EBUSY;
}
base = ioremap(iomem->start, resource_size(iomem));
if (!base) { if (!base) {
dev_err(&pdev->dev, "Can't ioremap I2C region\n"); dev_err(&pdev->dev, "Can't ioremap I2C region\n");
return -ENOMEM; return -ENOMEM;
@ -769,14 +762,13 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res) { if (!res) {
dev_err(&pdev->dev, "no irq resource?\n"); dev_err(&pdev->dev, "no irq resource?\n");
ret = -ENODEV; return -ENODEV;
goto err_iounmap;
} }
i2c_clk = clk_get_sys("tegra-i2c.2", NULL); i2c_clk = clk_get_sys("tegra-i2c.2", NULL);
if (IS_ERR(i2c_clk)) { if (IS_ERR(i2c_clk)) {
dev_err(nvec->dev, "failed to get controller clock\n"); dev_err(nvec->dev, "failed to get controller clock\n");
goto err_iounmap; return -ENODEV;
} }
nvec->base = base; 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); INIT_WORK(&nvec->tx_work, nvec_request_master);
nvec->wq = alloc_workqueue("nvec", WQ_NON_REENTRANT, 2); 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) { if (err < 0) {
dev_err(nvec->dev, "couldn't request gpio\n"); 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) { if (err) {
dev_err(nvec->dev, "couldn't request irq\n"); dev_err(nvec->dev, "couldn't request irq\n");
goto failed; destroy_workqueue(nvec->wq);
return -ENODEV;
} }
disable_irq(nvec->irq); 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); nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7);
return 0; return 0;
err_iounmap:
iounmap(base);
failed:
kfree(nvec);
return -ENOMEM;
} }
static int __devexit tegra_nvec_remove(struct platform_device *pdev) 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); nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3);
mfd_remove_devices(nvec->dev); mfd_remove_devices(nvec->dev);
free_irq(nvec->irq, &nvec_interrupt);
iounmap(nvec->base);
gpio_free(nvec->gpio);
destroy_workqueue(nvec->wq); destroy_workqueue(nvec->wq);
kfree(nvec);
return 0; return 0;
} }

View File

@ -49,7 +49,7 @@ static int __devinit nvec_led_probe(struct platform_device *pdev)
struct nvec_led *led; struct nvec_led *led;
int ret = 0; int ret = 0;
led = kzalloc(sizeof(*led), GFP_KERNEL); led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
if (led == NULL) if (led == NULL)
return -ENOMEM; return -ENOMEM;
@ -64,16 +64,12 @@ static int __devinit nvec_led_probe(struct platform_device *pdev)
ret = led_classdev_register(&pdev->dev, &led->cdev); ret = led_classdev_register(&pdev->dev, &led->cdev);
if (ret < 0) if (ret < 0)
goto err_led; return ret;
/* to expose the default value to userspace */ /* to expose the default value to userspace */
led->cdev.brightness = 0; led->cdev.brightness = 0;
return 0; return 0;
err_led:
kfree(led);
return ret;
} }
static int __devexit nvec_led_remove(struct platform_device *pdev) 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); struct nvec_led *led = platform_get_drvdata(pdev);
led_classdev_unregister(&led->cdev); led_classdev_unregister(&led->cdev);
kfree(led);
return 0; return 0;
} }

View File

@ -371,10 +371,13 @@ static void nvec_power_poll(struct work_struct *work)
static int __devinit nvec_power_probe(struct platform_device *pdev) static int __devinit nvec_power_probe(struct platform_device *pdev)
{ {
struct power_supply *psy; struct power_supply *psy;
struct nvec_power *power = struct nvec_power *power;
kzalloc(sizeof(struct nvec_power), GFP_NOWAIT);
struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 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); dev_set_drvdata(&pdev->dev, power);
power->nvec = nvec; 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; power->notifier.notifier_call = nvec_power_bat_notifier;
break; break;
default: default:
kfree(power);
return -ENODEV; return -ENODEV;
} }

View File

@ -96,7 +96,11 @@ static int nvec_ps2_notifier(struct notifier_block *nb,
static int __devinit nvec_mouse_probe(struct platform_device *pdev) static int __devinit nvec_mouse_probe(struct platform_device *pdev)
{ {
struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 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->id.type = SERIO_PS_PSTHRU;
ser_dev->write = ps2_sendcommand; ser_dev->write = ps2_sendcommand;