Skip to contentSkip to conversation

leds: use devm_platform_ioremap_resource_byname()

PATCH In review [email protected] 2 participants 3 messages Feb 14, 2020 – Feb 26, 2020 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: use devm_platform_ioremap_resource_byname()

From: chenqiwu <[email protected]>

Use devm_platform_ioremap_resource_byname() instead of calling platform_get_resource_byname() and devm_ioremap_resource() separately.

---
 drivers/leds/leds-cobalt-qube.c | 12 +++---------
 drivers/leds/leds-cobalt-raq.c  | 12 ++++--------
 2 files changed, 7 insertions(+), 17 deletions(-)
drivers/leds/leds-cobalt-qube.c +3 -9
index ef22e1e..76af9d8 100644
@@ -36,15 +36,9 @@ static void qube_front_led_set(struct led_classdev *led_cdev,
 
 static int cobalt_qube_led_probe(struct platform_device *pdev)
 {
-	struct resource *res;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EBUSY;
-
-	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!led_port)
-		return -ENOMEM;
+	led_port = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(led_port))
+		return PTR_ERR(led_port);
 
 	led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
 	writeb(led_value, led_port);
drivers/leds/leds-cobalt-raq.c +4 -8
index 045c239..8b1317d 100644
@@ -65,16 +65,11 @@ static void raq_power_off_led_set(struct led_classdev *led_cdev,
 
 static int cobalt_raq_led_probe(struct platform_device *pdev)
 {
-	struct resource *res;
 	int retval;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EBUSY;
-
-	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!led_port)
-		return -ENOMEM;
+	led_port = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(led_port))
+		return PTR_ERR(led_port);
 
 	retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
 	if (retval)
@@ -90,6 +85,7 @@ static int cobalt_raq_led_probe(struct platform_device *pdev)
 	led_classdev_unregister(&raq_power_off_led);
 
 err_null:
+	devm_ioremap_release(&pdev->dev, led_port);
 	led_port = NULL;
 
 	return retval;
Signature · 1 line
1.9.1
#1 lore raw

Hi!

Quoted 6 lines

From: chenqiwu <[email protected]>

Use devm_platform_ioremap_resource_byname() instead of calling platform_get_resource_byname() and devm_ioremap_resource() separately.

Was this tested? Can you cc driver authors to get it tested?

Quoted 47 lines

index ef22e1e..76af9d8 100644

drivers/leds/leds-cobalt-qube.c +3 -9
@@ -36,15 +36,9 @@ static void qube_front_led_set(struct led_classdev *led_cdev,
 
 static int cobalt_qube_led_probe(struct platform_device *pdev)
 {
-	struct resource *res;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EBUSY;
-
-	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!led_port)
-		return -ENOMEM;
+	led_port = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(led_port))
+		return PTR_ERR(led_port);
 
 	led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
 	writeb(led_value, led_port);
drivers/leds/leds-cobalt-raq.c +3 -8
index 045c239..8b1317d 100644
@@ -65,16 +65,11 @@ static void raq_power_off_led_set(struct led_classdev *led_cdev,
 
 static int cobalt_raq_led_probe(struct platform_device *pdev)
 {
-	struct resource *res;
 	int retval;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EBUSY;
-
-	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!led_port)
-		return -ENOMEM;
+	led_port = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(led_port))
+		return PTR_ERR(led_port);
 
 	retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
 	if (retval)

drivers/leds/leds-cobalt-raq.c static int cobalt_raq_led_probe(struct platform_device *pdev) · line 91

Quoted 7 lines
drivers/leds/leds-cobalt-raq.c +1 -0
@@ -90,6 +85,7 @@ static int cobalt_raq_led_probe(struct platform_device *pdev)
 	led_classdev_unregister(&raq_power_off_led);
 
 err_null:
+	devm_ioremap_release(&pdev->dev, led_port);
 	led_port = NULL;
 
 	return retval;

How is it that manual devm_ioremap_release() is neccessary here but not in the other driver?

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#2 lore raw

Hi, Pavel,

Quoted 9 lines
Quoted 7 lines

From: chenqiwu <[email protected]>

Use devm_platform_ioremap_resource_byname() instead of calling platform_get_resource_byname() and devm_ioremap_resource() separately.

Was this tested? Can you cc driver authors to get it tested?

I will resend this patch cc driver authors to get it tested.

Quoted 49 lines
Quoted 49 lines

index ef22e1e..76af9d8 100644

drivers/leds/leds-cobalt-qube.c +3 -9
@@ -36,15 +36,9 @@ static void qube_front_led_set(struct led_classdev *led_cdev,
 
 static int cobalt_qube_led_probe(struct platform_device *pdev)
 {
-	struct resource *res;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EBUSY;
-
-	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!led_port)
-		return -ENOMEM;
+	led_port = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(led_port))
+		return PTR_ERR(led_port);
 
 	led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
 	writeb(led_value, led_port);
drivers/leds/leds-cobalt-raq.c +3 -8
index 045c239..8b1317d 100644
@@ -65,16 +65,11 @@ static void raq_power_off_led_set(struct led_classdev *led_cdev,
 
 static int cobalt_raq_led_probe(struct platform_device *pdev)
 {
-	struct resource *res;
 	int retval;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -EBUSY;
-
-	led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
-	if (!led_port)
-		return -ENOMEM;
+	led_port = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(led_port))
+		return PTR_ERR(led_port);
 
 	retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
 	if (retval)
@@ -90,6 +85,7 @@ static int cobalt_raq_led_probe(struct platform_device *pdev)
 	led_classdev_unregister(&raq_power_off_led);
 
Quoted 8 lines

drivers/leds/leds-cobalt-raq.c static int cobalt_raq_led_probe(struct platform_device *pdev) · line 91

Quoted 5 lines
drivers/leds/leds-cobalt-raq.c +1 -0
 err_null:
+	devm_ioremap_release(&pdev->dev, led_port);
 	led_port = NULL;
 
 	return retval;

How is it that manual devm_ioremap_release() is neccessary here but not in the other driver?

Thanks for your remind! This is neccessary for leds-cobalt-qube driver to apply, too.

BRs,
Qiwu