Skip to contentSkip to conversation

hwmon: (jz4740) Use devm_ioremap_resource()

PATCH Applied Jingoo Han 3 participants 3 messages Feb 11, 2014 Hardware monitoring

lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH 1/1 hwmon: (jz4740) Use devm_ioremap_resource()

Use devm_ioremap_resource() in order to make the code simpler, and move 'struct resource *mem' from 'struct jz4740_hwmon' to jz4740_hwmon_probe() because the 'mem' variable is used only in jz4740_hwmon_probe(). Also the redundant return value check of platform_get_resource() is removed, because the value is checked by devm_ioremap_resource().

---
 drivers/hwmon/jz4740-hwmon.c |   25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)
drivers/hwmon/jz4740-hwmon.c +5 -20
index a183e48..7488e36 100644
@@ -28,7 +28,6 @@
 #include <linux/hwmon.h>
 
 struct jz4740_hwmon {
-	struct resource *mem;
 	void __iomem *base;
 
 	int irq;
@@ -106,6 +105,7 @@ static int jz4740_hwmon_probe(struct platform_device *pdev)
 {
 	int ret;
 	struct jz4740_hwmon *hwmon;
+	struct resource *mem;
 
 	hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL);
 	if (!hwmon)
@@ -120,25 +120,10 @@ static int jz4740_hwmon_probe(struct platform_device *pdev)
 		return hwmon->irq;
 	}
 
-	hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!hwmon->mem) {
-		dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
-		return -ENOENT;
-	}
-
-	hwmon->mem = devm_request_mem_region(&pdev->dev, hwmon->mem->start,
-			resource_size(hwmon->mem), pdev->name);
-	if (!hwmon->mem) {
-		dev_err(&pdev->dev, "Failed to request mmio memory region\n");
-		return -EBUSY;
-	}
-
-	hwmon->base = devm_ioremap_nocache(&pdev->dev, hwmon->mem->start,
-					   resource_size(hwmon->mem));
-	if (!hwmon->base) {
-		dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
-		return -EBUSY;
-	}
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	hwmon->base = devm_ioremap_resource(&pdev->dev, mem);
+	if (IS_ERR(hwmon->base))
+		return PTR_ERR(hwmon->base);
 
 	init_completion(&hwmon->read_completion);
 	mutex_init(&hwmon->lock);
Signature · 8 lines
1.7.10.4



_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jingoo Han

Use devm_ioremap_resource() in order to make the code simpler, and move 'struct resource *mem' from 'struct jz4740_hwmon' to jz4740_hwmon_probe() because the 'mem' variable is used only in jz4740_hwmon_probe(). Also the redundant return value check of platform_get_resource() is removed, because the value is checked by devm_ioremap_resource().

Quoted 45 lines
---
  drivers/hwmon/jz4740-hwmon.c |   25 +++++--------------------
  1 file changed, 5 insertions(+), 20 deletions(-)
drivers/hwmon/jz4740-hwmon.c +1 -17
index a183e48..7488e36 100644
@@ -28,7 +28,6 @@
  #include <linux/hwmon.h>
 
  struct jz4740_hwmon {
-	struct resource *mem;
  	void __iomem *base;
 
  	int irq;
@@ -106,6 +105,7 @@ static int jz4740_hwmon_probe(struct platform_device *pdev)
  {
  	int ret;
  	struct jz4740_hwmon *hwmon;
+	struct resource *mem;
 
  	hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL);
  	if (!hwmon)
@@ -120,25 +120,10 @@ static int jz4740_hwmon_probe(struct platform_device *pdev)
  		return hwmon->irq;
  	}
 
-	hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!hwmon->mem) {
-		dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
-		return -ENOENT;
-	}
-
-	hwmon->mem = devm_request_mem_region(&pdev->dev, hwmon->mem->start,
-			resource_size(hwmon->mem), pdev->name);
-	if (!hwmon->mem) {
-		dev_err(&pdev->dev, "Failed to request mmio memory region\n");
-		return -EBUSY;
-	}
-
-	hwmon->base = devm_ioremap_nocache(&pdev->dev, hwmon->mem->start,
-					   resource_size(hwmon->mem));
-	if (!hwmon->base) {

drivers/hwmon/jz4740-hwmon.c static int jz4740_hwmon_probe(struct platform_device *pdev) · line 129

Quoted 10 lines
drivers/hwmon/jz4740-hwmon.c +4 -3
-		dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
-		return -EBUSY;
-	}
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	hwmon->base = devm_ioremap_resource(&pdev->dev, mem);
+	if (IS_ERR(hwmon->base))
+		return PTR_ERR(hwmon->base);
 
  	init_completion(&hwmon->read_completion);
  	mutex_init(&hwmon->lock);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

maintainer Applied
#2 lore raw
In reply to Jingoo Han
Quoted 8 lines · Jingoo Han

Use devm_ioremap_resource() in order to make the code simpler, and move 'struct resource *mem' from 'struct jz4740_hwmon' to jz4740_hwmon_probe() because the 'mem' variable is used only in jz4740_hwmon_probe(). Also the redundant return value check of platform_get_resource() is removed, because the value is checked by devm_ioremap_resource().

Applied to -next.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors