* [PATCH] gpio: Switch to devm_ioremap_resource()
@ 2016-02-28 12:30 Amitoj Kaur Chawla
2016-03-08 8:57 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-28 12:30 UTC (permalink / raw)
To: linus.walleij, gnurou, linux-gpio, linux-kernel; +Cc: julia.lawall
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: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
drivers/gpio/gpio-timberdale.c | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index a6de10c..bd04328 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -237,12 +237,6 @@ static int timbgpio_probe(struct platform_device *pdev)
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);
if (!tgpio) {
dev_err(dev, "Memory alloc failed\n");
@@ -252,17 +246,10 @@ static int timbgpio_probe(struct platform_device *pdev)
spin_lock_init(&tgpio->lock);
- if (!devm_request_mem_region(dev, iomem->start, resource_size(iomem),
- DRIVER_NAME)) {
- dev_err(dev, "Region already claimed\n");
- return -EBUSY;
- }
-
- tgpio->membase = devm_ioremap(dev, iomem->start, resource_size(iomem));
- if (!tgpio->membase) {
- dev_err(dev, "Cannot ioremap\n");
- return -ENOMEM;
- }
+ iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ tgpio->membase = devm_ioremap_resource(dev, iomem);
+ if (IS_ERR(tgpio->membase))
+ return PTR_ERR(tgpio->membase);
gc = &tgpio->gpio;
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] gpio: Switch to devm_ioremap_resource()
2016-02-28 12:30 [PATCH] gpio: Switch to devm_ioremap_resource() Amitoj Kaur Chawla
@ 2016-03-08 8:57 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2016-03-08 8:57 UTC (permalink / raw)
To: Amitoj Kaur Chawla
Cc: Alexandre Courbot, linux-gpio, linux-kernel, Julia Lawall
On Sun, Feb 28, 2016 at 7:30 PM, Amitoj Kaur Chawla
<amitoj1606@gmail.com> wrote:
> Replace calls to devm_request_mem_region and devm_ioremap with a
> direct call to devm_ioremap_resource instead and modify error
> handling.
Patch applied, adding the timberdale: prefix.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-03-08 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-28 12:30 [PATCH] gpio: Switch to devm_ioremap_resource() Amitoj Kaur Chawla
2016-03-08 8:57 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).