# \[PATCH 0/29\] simplify use of devm\_ioremap\_resource

- Subsystems: INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN) DRIVERS, ARM PRIMECELL BUS SUPPORT, ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES, BROADCOM BCM6348/BCM6358 SPI controller DRIVER, CPU IDLE TIME MANAGEMENT FRAMEWORK, DESIGNWARE USB3 DRD IP DRIVER, DMA GENERIC OFFLOAD ENGINE SUBSYSTEM, DRM DRIVERS, DRM DRIVERS FOR NVIDIA TEGRA, FRAMEBUFFER LAYER, GPIO SUBSYSTEM, HARDWARE RANDOM NUMBER GENERATOR CORE, I2C SUBSYSTEM, I2C SUBSYSTEM HOST DRIVERS, IOMMU SUBSYSTEM, LIBATA SUBSYSTEM (Serial and Parallel ATA drivers), MEDIA INPUT INFRASTRUCTURE (V4L/DVB), MEMORY CONTROLLER DRIVERS, MEMORY TECHNOLOGY DEVICES (MTD), NAND FLASH SUBSYSTEM, OMAP USB SUPPORT, OPENCORES I2C BUS DRIVER, PIN CONTROL SUBSYSTEM, PWM SUBSYSTEM, REAL TIME CLOCK (RTC) SUBSYSTEM, REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM, RENESAS R-CAR SATA DRIVER, SAMSUNG AUDIO (ASoC) DRIVERS, SCSI SUBSYSTEM, SOUND, SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEMENT (ASoC), SPI SUBSYSTEM, TEGRA IOMMU DRIVERS, TEGRA KBC DRIVER, THE REST, TTY LAYER AND SERIAL DRIVERS, USB SUBSYSTEM, WATCHDOG DEVICE DRIVERS
- Maintainers: Dmitry Torokhov, Russell King, Krzysztof Kozlowski, Peter Griffin, Jonas Gorski, "Rafael J. Wysocki", Daniel Lezcano, Thinh Nguyen, Vinod Koul, David Airlie, Simona Vetter, Thierry Reding, Mikko Perttunen, Helge Deller, Linus Walleij, Bartosz Golaszewski, Olivia Mackall, Herbert Xu, Andi Shyti, Joerg Roedel, Will Deacon, Damien Le Moal, Niklas Cassel, Mauro Carvalho Chehab, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Peter Korsgaard, Andrew Lunn, Uwe Kleine-König, Alexandre Belloni, Bjorn Andersson, Mathieu Poirier, Geert Uytterhoeven, Sylwester Nawrocki, "James E.J. Bottomley", "Martin K. Petersen", Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown, Laxman Dewangan, Linus Torvalds, Greg Kroah-Hartman, Jiri Slaby, Wim Van Sebroeck, Guenter Roeck
- Series: 28 patches touching 39 files, +21/-196
- List: linux-input
- 2 messages, 1 author
- Page: https://ratatoskr.run/linux-input/2013/08/4100536/t

## \[PATCH 0/29\] simplify use of devm\_ioremap\_resource

- From: Julia Lawall \<hidden\>
- Date: 2013-08-14 09:18:54 
- Message: https://ratatoskr.run/linux-input/2013/08/4100536.md

```text
devm_ioremap_resource often uses the result of a call to
platform_get_resource as its last argument.  devm_ioremap_resource does
appropriate error handling on this argument, so error handling can be
removed from the call site.  To make the connection between the call to
platform_get_resource and the call to devm_ioremap_resource more clear, the
former is also moved down to be adjacent to the latter.

In many cases, this patch changes the specific error value that is
returned on failure of platform_get_resource.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression pdev,res,n,e,e1;
expression ret != 0;
identifier l;
@@

(
  res = platform_get_resource(pdev, IORESOURCE_MEM, n);
- if (res == NULL) { ... \(goto l;\|return ret;\) }
  e = devm_ioremap_resource(e1, res);
|
- res = platform_get_resource(pdev, IORESOURCE_MEM, n);
  ... when != res
- if (res == NULL) { ... \(goto l;\|return ret;\) }
  ... when != res
+ res = platform_get_resource(pdev, IORESOURCE_MEM, n);
  e = devm_ioremap_resource(e1, res);
)
// </smpl>
```

## \[PATCH 13/29\] drivers/input/keyboard/tegra-kbc.c: simplify use of devm\_ioremap\_resource

- From: Julia Lawall \<hidden\>
- Date: 2013-08-14 09:15:41 
- Message: https://ratatoskr.run/linux-input/2013/08/4100523.md

```text
From: Julia Lawall <redacted>

Remove unneeded error handling on the result of a call to
platform_get_resource when the value is passed to devm_ioremap_resource.

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 semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression pdev,res,n,e,e1;
expression ret != 0;
identifier l;
@@

- res = platform_get_resource(pdev, IORESOURCE_MEM, n);
  ... when != res
- if (res == NULL) { ... \(goto l;\|return ret;\) }
  ... when != res
+ res = platform_get_resource(pdev, IORESOURCE_MEM, n);
  e = devm_ioremap_resource(e1, res);
// </smpl>

Signed-off-by: Julia Lawall <redacted>

---
 drivers/input/keyboard/tegra-kbc.c |    7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c
index b46142f..9cd20e6 100644
--- a/drivers/input/keyboard/tegra-kbc.c
+++ b/drivers/input/keyboard/tegra-kbc.c
@@ -638,12 +638,6 @@ static int tegra_kbc_probe(struct platform_device *pdev)
 	if (!tegra_kbc_check_pin_cfg(kbc, &num_rows))
 		return -EINVAL;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "failed to get I/O memory\n");
-		return -ENXIO;
-	}
-
 	kbc->irq = platform_get_irq(pdev, 0);
 	if (kbc->irq < 0) {
 		dev_err(&pdev->dev, "failed to get keyboard IRQ\n");
@@ -658,6 +652,7 @@ static int tegra_kbc_probe(struct platform_device *pdev)
 
 	setup_timer(&kbc->timer, tegra_kbc_keypress_timer, (unsigned long)kbc);
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	kbc->mmio = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(kbc->mmio))
 		return PTR_ERR(kbc->mmio);

```
