Skip to content

Commit fa283db

Browse files
musicakclinusw
authored andcommitted
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: Amitoj Kaur Chawla <amitoj1606@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 6dcfd72 commit fa283db

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

drivers/gpio/gpio-timberdale.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,6 @@ static int timbgpio_probe(struct platform_device *pdev)
237237
return -EINVAL;
238238
}
239239

240-
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
241-
if (!iomem) {
242-
dev_err(dev, "Unable to get resource\n");
243-
return -EINVAL;
244-
}
245-
246240
tgpio = devm_kzalloc(dev, sizeof(struct timbgpio), GFP_KERNEL);
247241
if (!tgpio) {
248242
dev_err(dev, "Memory alloc failed\n");
@@ -252,17 +246,10 @@ static int timbgpio_probe(struct platform_device *pdev)
252246

253247
spin_lock_init(&tgpio->lock);
254248

255-
if (!devm_request_mem_region(dev, iomem->start, resource_size(iomem),
256-
DRIVER_NAME)) {
257-
dev_err(dev, "Region already claimed\n");
258-
return -EBUSY;
259-
}
260-
261-
tgpio->membase = devm_ioremap(dev, iomem->start, resource_size(iomem));
262-
if (!tgpio->membase) {
263-
dev_err(dev, "Cannot ioremap\n");
264-
return -ENOMEM;
265-
}
249+
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250+
tgpio->membase = devm_ioremap_resource(dev, iomem);
251+
if (IS_ERR(tgpio->membase))
252+
return PTR_ERR(tgpio->membase);
266253

267254
gc = &tgpio->gpio;
268255

0 commit comments

Comments
 (0)