Skip to contentSkip to conversation

gpio: tb10x: Fix checking return value of devm_ioremap_resource

PATCH In review Axel Lin 3 participants 6 messages Oct 31, 2013 – Nov 12, 2013 GPIO

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 gpio: tb10x: Fix checking return value of devm_ioremap_resource

Also move platform_get_resource() call close to devm_ioremap_resource(). The implementation of devm_ioremap_resource() will also check mem parameter and emit proper error.

---
 drivers/gpio/gpio-tb10x.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/gpio/gpio-tb10x.c +3 -11
index 833d0f4..45bfed1 100644
@@ -194,23 +194,16 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
 	if (of_property_read_u32(dn, "abilis,ngpio", &ngpio))
 		return -EINVAL;
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!mem) {
-		dev_err(&pdev->dev, "No memory resource defined.\n");
-		return -EINVAL;
-	}
-
 	tb10x_gpio = devm_kzalloc(&pdev->dev, sizeof(*tb10x_gpio), GFP_KERNEL);
 	if (tb10x_gpio == NULL)
 		return -ENOMEM;
 
 	spin_lock_init(&tb10x_gpio->spinlock);
 
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	tb10x_gpio->base = devm_ioremap_resource(&pdev->dev, mem);
-	if (!tb10x_gpio->base) {
-		dev_err(&pdev->dev, "Could not remap reg space.\n");
-		goto fail_ioremap;
-	}
+	if (IS_ERR(tb10x_gpio->base))
+		return PTR_ERR(tb10x_gpio->base);
 
 	tb10x_gpio->gc.label		= of_node_full_name(dn);
 	tb10x_gpio->gc.dev		= &pdev->dev;
@@ -285,7 +278,6 @@ fail_request_irq:
 fail_get_irq:
 	gpiochip_remove(&tb10x_gpio->gc);
 fail_gpiochip_registration:
-fail_ioremap:
 	return ret;
 }
 
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 2/2 gpio: tb10x: Convert to use module_platform_driver

Use module_platform_driver to simplify the code.
In additional, this is a DT only driver, thus also remove of_match_ptr.

---
 drivers/gpio/gpio-tb10x.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/gpio/gpio-tb10x.c +2 -12
index 45bfed1..a0391bc 100644
@@ -311,23 +311,13 @@ static struct platform_driver tb10x_gpio_driver = {
 	.remove		= tb10x_gpio_remove,
 	.driver = {
 		.name	= "tb10x-gpio",
-		.of_match_table = of_match_ptr(tb10x_gpio_dt_ids),
+		.of_match_table = tb10x_gpio_dt_ids,
 		.owner	= THIS_MODULE,
 	}
 };
 
-static int __init ab_gpio_init(void)
-{
-	return platform_driver_register(&tb10x_gpio_driver);
-}
-
-static void __exit ab_gpio_exit(void)
-{
-	platform_driver_unregister(&tb10x_gpio_driver);
-}
+module_platform_driver(tb10x_gpio_driver);
 
-module_init(ab_gpio_init);
-module_exit(ab_gpio_exit);
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("tb10x gpio.");
 MODULE_VERSION("0.0.1");
Signature · 1 line
1.8.1.2
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] gpio: tb10x: Convert to use module_platform_driver

Quoted 4 lines · Axel Lin

Use module_platform_driver to simplify the code.
In additional, this is a DT only driver, thus also remove of_match_ptr.

Quoted 39 lines
---
 drivers/gpio/gpio-tb10x.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/gpio/gpio-tb10x.c +2 -12
index 45bfed1..a0391bc 100644
@@ -311,23 +311,13 @@ static struct platform_driver tb10x_gpio_driver = {
 	.remove		= tb10x_gpio_remove,
 	.driver = {
 		.name	= "tb10x-gpio",
-		.of_match_table = of_match_ptr(tb10x_gpio_dt_ids),
+		.of_match_table = tb10x_gpio_dt_ids,
 		.owner	= THIS_MODULE,
 	}
 };
 
-static int __init ab_gpio_init(void)
-{
-	return platform_driver_register(&tb10x_gpio_driver);
-}
-
-static void __exit ab_gpio_exit(void)
-{
-	platform_driver_unregister(&tb10x_gpio_driver);
-}
+module_platform_driver(tb10x_gpio_driver);
 
-module_init(ab_gpio_init);
-module_exit(ab_gpio_exit);
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("tb10x gpio.");
 MODULE_VERSION("0.0.1");
Signature · 1 line
1.8.1.2
#3 lore raw

Re: [PATCH 2/2] gpio: tb10x: Convert to use module_platform_driver

In reply to Axel Lin
Quoted 4 lines · Axel Lin

Use module_platform_driver to simplify the code.
In additional, this is a DT only driver, thus also remove of_match_ptr.

I've already merged a patch like this from Wei Yongjun, but thanks anyway!

Yours,
Linus Walleij

Acked-by on v1 1/2
#4 lore raw
In reply to Axel Lin
Quoted 5 lines · Axel Lin

Also move platform_get_resource() call close to devm_ioremap_resource(). The implementation of devm_ioremap_resource() will also check mem parameter and emit proper error.

Quoted 48 lines
---
 drivers/gpio/gpio-tb10x.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/gpio/gpio-tb10x.c +3 -11
index 833d0f4..45bfed1 100644
@@ -194,23 +194,16 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
 	if (of_property_read_u32(dn, "abilis,ngpio", &ngpio))
 		return -EINVAL;
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!mem) {
-		dev_err(&pdev->dev, "No memory resource defined.\n");
-		return -EINVAL;
-	}
-
 	tb10x_gpio = devm_kzalloc(&pdev->dev, sizeof(*tb10x_gpio), GFP_KERNEL);
 	if (tb10x_gpio == NULL)
 		return -ENOMEM;
 
 	spin_lock_init(&tb10x_gpio->spinlock);
 
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	tb10x_gpio->base = devm_ioremap_resource(&pdev->dev, mem);
-	if (!tb10x_gpio->base) {
-		dev_err(&pdev->dev, "Could not remap reg space.\n");
-		goto fail_ioremap;
-	}
+	if (IS_ERR(tb10x_gpio->base))
+		return PTR_ERR(tb10x_gpio->base);
 
 	tb10x_gpio->gc.label		= of_node_full_name(dn);
 	tb10x_gpio->gc.dev		= &pdev->dev;
@@ -285,7 +278,6 @@ fail_request_irq:
 fail_get_irq:
 	gpiochip_remove(&tb10x_gpio->gc);
 fail_gpiochip_registration:
-fail_ioremap:
 	return ret;
 }
 
Signature · 1 line
1.8.1.2
author
#5 lore raw

2013/10/31 Christian Ruppert <[email protected]>:

Quoted 6 lines · Axel Lin
Quoted 5 lines

Also move platform_get_resource() call close to devm_ioremap_resource(). The implementation of devm_ioremap_resource() will also check mem parameter and emit proper error.

Hi Linus,
I just found similar patches already merged in today's linux-next tree. So you can ignore these 2 patches.

Regards,
Axel