Skip to contentSkip to conversation

Thermal: spear_thermal: convert to devm_ioremap_resource

PATCH Applied Zhang Rui 2 participants 5 messages May 16, 2013 – May 20, 2013

Subsystems (2)
lore
Share & tools
lore

Zhang Rui

author reviewer
#0 lore raw

PATCH 1/2 Thermal: spear_thermal: convert to devm_ioremap_resource

Use the newly introduced devm_ioremap_resource().

devm_ioremap_resource() provides its own error messages; so all explicit error messages can be removed from the failure code paths.

CC Vincenzo Frascino <[email protected]>
---
 drivers/thermal/spear_thermal.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/thermal/spear_thermal.c +10 -10
index 1a14eaa..1b652ab 100644
@@ -104,7 +104,7 @@ static int spear_thermal_probe(struct platform_device *pdev)
 	struct thermal_zone_device *spear_thermal = NULL;
 	struct spear_thermal_dev *stdev;
 	struct device_node *np = pdev->dev.of_node;
-	struct resource *stres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	struct resource *res;
 	int ret = 0, val;
 
 	if (!np || !of_property_read_u32(np, "st,thermal-flags", &val)) {
@@ -112,23 +112,23 @@ static int spear_thermal_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	if (!stres) {
-		dev_err(&pdev->dev, "memory resource missing\n");
-		return -ENODEV;
-	}
-
 	stdev = devm_kzalloc(&pdev->dev, sizeof(*stdev), GFP_KERNEL);
 	if (!stdev) {
 		dev_err(&pdev->dev, "kzalloc fail\n");
 		return -ENOMEM;
 	}
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "memory resource missing\n");
+		return -ENODEV;
+	}
+
 	/* Enable thermal sensor */
-	stdev->thermal_base = devm_ioremap(&pdev->dev, stres->start,
-			resource_size(stres));
-	if (!stdev->thermal_base) {
+	stdev->thermal_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(stdev->thermal_base)) {
 		dev_err(&pdev->dev, "ioremap failed\n");
-		return -ENOMEM;
+		return PTR_ERR(stdev->thermal_base);
 	}
 
 	stdev->clk = devm_clk_get(&pdev->dev, NULL);
Signature · 1 line
1.7.9.5
author reviewer
#1 lore raw

PATCH 2/2 Thermal: don't check resource with devm_ioremap_resource

devm_ioremap_resource does sanity checks on the given resource. No need to duplicate this in the driver.

CC Ezequiel Garcia <[email protected]>
CC Vincenzo Frascino <[email protected]>
---
 drivers/thermal/armada_thermal.c |   10 ----------
 drivers/thermal/spear_thermal.c  |    7 +------
 2 files changed, 1 insertion(+), 16 deletions(-)
drivers/thermal/armada_thermal.c +0 -10
index 0d02d4e..0491465 100644
@@ -169,21 +169,11 @@ static int armada_thermal_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "Failed to get platform resource\n");
-		return -ENODEV;
-	}
-
 	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(priv->sensor))
 		return PTR_ERR(priv->sensor);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (!res) {
-		dev_err(&pdev->dev, "Failed to get platform resource\n");
-		return -ENODEV;
-	}
-
 	priv->control = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(priv->control))
 		return PTR_ERR(priv->control);
drivers/thermal/spear_thermal.c +1 -6
index 1b652ab..fa30918 100644
@@ -118,13 +118,8 @@ static int spear_thermal_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "memory resource missing\n");
-		return -ENODEV;
-	}
-
 	/* Enable thermal sensor */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	stdev->thermal_base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(stdev->thermal_base)) {
 		dev_err(&pdev->dev, "ioremap failed\n");
Signature · 1 line
1.7.9.5
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] Thermal: don't check resource with devm_ioremap_resource

Quoted 6 lines · Zhang Rui

devm_ioremap_resource does sanity checks on the given resource. No need to duplicate this in the driver.

CC Ezequiel Garcia <[email protected]>
CC Vincenzo Frascino <[email protected]>

Thanks,

Signature · 3 lines
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
author reviewer Applied
#3 lore raw

RE: [PATCH 2/2] Thermal: don't check resource with devm_ioremap_resource

In reply to Zhang Rui
Quoted 12 lines

-----Original Message-----
From: Zhang, Rui
Sent: Thursday, May 16, 2013 10:16 AM
To: [email protected]
Cc: [email protected]; Zhang, Rui; Ezequiel Garcia; Vincenzo Frascino
Subject: [PATCH 2/2] Thermal: don't check resource with devm_ioremap_resource
Importance: High

Quoted 6 lines

devm_ioremap_resource does sanity checks on the given resource. No need to duplicate this in the driver.

CC Ezequiel Garcia <[email protected]>
CC Vincenzo Frascino <[email protected]>

Applied to thermal -next.

Thanks,
rui

Quoted 55 lines
---
 drivers/thermal/armada_thermal.c |   10 ----------
 drivers/thermal/spear_thermal.c  |    7 +------
 2 files changed, 1 insertion(+), 16 deletions(-)
drivers/thermal/armada_thermal.c +0 -10
index 0d02d4e..0491465 100644
@@ -169,21 +169,11 @@ static int armada_thermal_probe(struct
 platform_device *pdev)
 		return -ENOMEM;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "Failed to get platform resource\n");
-		return -ENODEV;
-	}
-
 	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(priv->sensor))
 		return PTR_ERR(priv->sensor);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-	if (!res) {
-		dev_err(&pdev->dev, "Failed to get platform resource\n");
-		return -ENODEV;
-	}
-
 	priv->control = devm_ioremap_resource(&pdev->dev, res);
 	if (IS_ERR(priv->control))
drivers/thermal/armada_thermal.c +0 -0
 		return PTR_ERR(priv->control);
(quoted diff) +0 -0

b/drivers/thermal/spear_thermal.c index 1b652ab..fa30918 100644

drivers/thermal/spear_thermal.c +1 -6
@@ -118,13 +118,8 @@ static int spear_thermal_probe(struct
 platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(&pdev->dev, "memory resource missing\n");
-		return -ENODEV;
-	}
-
 	/* Enable thermal sensor */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	stdev->thermal_base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(stdev->thermal_base)) {

dev_err(&pdev->dev, "ioremap failed\n");
--
1.7.9.5

author reviewer Applied
#4 lore raw
In reply to Zhang Rui
Quoted 11 lines

-----Original Message-----
From: Zhang, Rui
Sent: Thursday, May 16, 2013 10:16 AM
To: [email protected]
Cc: [email protected]; Zhang, Rui; Vincenzo Frascino
Subject: [PATCH 1/2] Thermal: spear_thermal: convert to devm_ioremap_resource
Importance: High

Quoted 7 lines

Use the newly introduced devm_ioremap_resource().

devm_ioremap_resource() provides its own error messages; so all explicit error messages can be removed from the failure code paths.

CC Vincenzo Frascino <[email protected]>

Applied to thermal -next.

Thanks,
rui

Quoted 55 lines
---
 drivers/thermal/spear_thermal.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/thermal/spear_thermal.c index 1a14eaa..1b652ab 100644

drivers/thermal/spear_thermal.c +1 -1
@@ -104,7 +104,7 @@ static int spear_thermal_probe(struct
 platform_device *pdev)
 	struct thermal_zone_device *spear_thermal = NULL;
 	struct spear_thermal_dev *stdev;
 	struct device_node *np = pdev->dev.of_node;
-	struct resource *stres = platform_get_resource(pdev,
 IORESOURCE_MEM, 0);
+	struct resource *res;
 	int ret = 0, val;

if (!np || !of_property_read_u32(np, "st,thermal-flags", &val))
{ @@ -112,23 +112,23 @@ static int spear_thermal_probe(struct platform_device *pdev)

drivers/thermal/spear_thermal.c +9 -10
 		return -EINVAL;
 	}
 
-	if (!stres) {
-		dev_err(&pdev->dev, "memory resource missing\n");
-		return -ENODEV;
-	}
-
 	stdev = devm_kzalloc(&pdev->dev, sizeof(*stdev), GFP_KERNEL);
 	if (!stdev) {
 		dev_err(&pdev->dev, "kzalloc fail\n");
 		return -ENOMEM;
 	}
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "memory resource missing\n");
+		return -ENODEV;
+	}
+
 	/* Enable thermal sensor */
-	stdev->thermal_base = devm_ioremap(&pdev->dev, stres->start,
-			resource_size(stres));
-	if (!stdev->thermal_base) {
+	stdev->thermal_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(stdev->thermal_base)) {
 		dev_err(&pdev->dev, "ioremap failed\n");
-		return -ENOMEM;
+		return PTR_ERR(stdev->thermal_base);
 	}
 
 	stdev->clk = devm_clk_get(&pdev->dev, NULL);
--

1.7.9.5