gpio/omap: Use devm_ API and add request_mem_region
Replace the regular kzalloc and ioremap with the devm_ equivalent to simplify error handling. Add the missing devm_request_mem_region to reserve the region used by the driver. Signed-off-by: Benoit Cousson <b-cousson@ti.com> Cc: Tarun Kanti DebBarma <tarun.kanti@ti.com>
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/device.h>
|
||||||
#include <linux/pm_runtime.h>
|
#include <linux/pm_runtime.h>
|
||||||
#include <linux/pm.h>
|
#include <linux/pm.h>
|
||||||
|
|
||||||
@@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
|
|||||||
struct gpio_bank *bank;
|
struct gpio_bank *bank;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!dev->platform_data) {
|
if (!dev->platform_data)
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
|
bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
|
||||||
if (!bank) {
|
if (!bank) {
|
||||||
dev_err(dev, "Memory alloc failed\n");
|
dev_err(dev, "Memory alloc failed\n");
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
||||||
if (unlikely(!res)) {
|
if (unlikely(!res)) {
|
||||||
dev_err(dev, "Invalid IRQ resource\n");
|
dev_err(dev, "Invalid IRQ resource\n");
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bank->irq = res->start;
|
bank->irq = res->start;
|
||||||
@@ -1096,15 +1092,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
|
|||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (unlikely(!res)) {
|
if (unlikely(!res)) {
|
||||||
dev_err(dev, "Invalid mem resource\n");
|
dev_err(dev, "Invalid mem resource\n");
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bank->base = ioremap(res->start, resource_size(res));
|
if (!devm_request_mem_region(dev, res->start, resource_size(res),
|
||||||
|
pdev->name)) {
|
||||||
|
dev_err(dev, "Region already claimed\n");
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
bank->base = devm_ioremap(dev, res->start, resource_size(res));
|
||||||
if (!bank->base) {
|
if (!bank->base) {
|
||||||
dev_err(dev, "Could not ioremap\n");
|
dev_err(dev, "Could not ioremap\n");
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_free;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, bank);
|
platform_set_drvdata(pdev, bank);
|
||||||
@@ -1125,11 +1125,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
|
|||||||
list_add_tail(&bank->node, &omap_gpio_list);
|
list_add_tail(&bank->node, &omap_gpio_list);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
err_free:
|
|
||||||
kfree(bank);
|
|
||||||
err_exit:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_OMAP2PLUS
|
#ifdef CONFIG_ARCH_OMAP2PLUS
|
||||||
|
Reference in New Issue
Block a user