Commit fa283db7 authored by Amitoj Kaur Chawla's avatar Amitoj Kaur Chawla Committed by Linus Walleij

gpio: timberdale: Switch to devm_ioremap_resource()

Replace calls to devm_request_mem_region and devm_ioremap with a
direct call to devm_ioremap_resource instead and modify error
handling.

Move the call to platform_get_resource adjacent to the call to
devm_ioremap_resource to make the connection between them more
clear.

A simplified version of the Coccinelle semantic patch that is used to
make this change is as follows:
//<smpl>
@nm@
expression myname;
identifier i;
@@

struct platform_driver i = { .driver = { .name = myname } };

@@
expression dev,res,size,e1,e;
expression nm.myname;
@@

-if (!devm_request_mem_region(dev, res->start, size,
-                              \(res->name\|dev_name(dev)\|myname\)))
                               {
-   ...
-   return ...;
-}
... when != res->start = e1
e =
-devm_ioremap(dev,res->start,size);
+devm_ioremap_resource(dev,res);

if
-(e == NULL)
+(IS_ERR(e))
{
 ...
-return ...;
+return PTR_ERR(e);
}
//</smpl>

Further, updated error handling by hand as devm_ioremap_resource
gives appropriate error messages, so remove unnecessary error
messages.
Signed-off-by: default avatarAmitoj Kaur Chawla <amitoj1606@gmail.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 6dcfd729
...@@ -237,12 +237,6 @@ static int timbgpio_probe(struct platform_device *pdev) ...@@ -237,12 +237,6 @@ static int timbgpio_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!iomem) {
dev_err(dev, "Unable to get resource\n");
return -EINVAL;
}
tgpio = devm_kzalloc(dev, sizeof(struct timbgpio), GFP_KERNEL); tgpio = devm_kzalloc(dev, sizeof(struct timbgpio), GFP_KERNEL);
if (!tgpio) { if (!tgpio) {
dev_err(dev, "Memory alloc failed\n"); dev_err(dev, "Memory alloc failed\n");
...@@ -252,17 +246,10 @@ static int timbgpio_probe(struct platform_device *pdev) ...@@ -252,17 +246,10 @@ static int timbgpio_probe(struct platform_device *pdev)
spin_lock_init(&tgpio->lock); spin_lock_init(&tgpio->lock);
if (!devm_request_mem_region(dev, iomem->start, resource_size(iomem), iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
DRIVER_NAME)) { tgpio->membase = devm_ioremap_resource(dev, iomem);
dev_err(dev, "Region already claimed\n"); if (IS_ERR(tgpio->membase))
return -EBUSY; return PTR_ERR(tgpio->membase);
}
tgpio->membase = devm_ioremap(dev, iomem->start, resource_size(iomem));
if (!tgpio->membase) {
dev_err(dev, "Cannot ioremap\n");
return -ENOMEM;
}
gc = &tgpio->gpio; gc = &tgpio->gpio;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment