Skip to contentSkip to conversation

jz4740-battery module cleanup

PATCH In review Marcos Paulo de Souza 3 participants 5 messages Nov 6, 2012 – Nov 19, 2012

lore
Share & tools
lore
#0 lore raw

v3 cover jz4740-battery module cleanup

Hi guys!

This is the third version of the simple(simple..?) cleanup in the battery driver of jz4740. Just a tiny cleanup.

These patches were tested in Dingoo A320, without any problems.

Added Acked-bys of Lars.

Thanks since now!

Changelog:
From v2:
Remove the patch that touches the irq_request. We need to take a look at this later.

Remove the mem member of the struct jz_battery. Now this data is useless.

From v1:
Use devm_request_and_ioremap instead of devm_request and devm_ioremap_nocache.

Marcos Paulo de Souza (2):
drivers/power/jz4740-battery.c: Use devm_kzalloc drivers/power/jz4740-battery.c: Use devm_request_and_ioremap

 drivers/power/jz4740-battery.c |   41 ++++++++--------------------------------
 1 file changed, 8 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v3 1/2 drivers/power/jz4740-battery.c: Use devm_kzalloc

This is just a cleanup.

---
 drivers/power/jz4740-battery.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/power/jz4740-battery.c +4 -10
index 8dbc7bf..59900c6 100644
@@ -252,7 +252,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
 		return -ENXIO;
 	}
 
-	jz_battery = kzalloc(sizeof(*jz_battery), GFP_KERNEL);
+	jz_battery = devm_kzalloc(&pdev->dev, sizeof(*jz_battery), GFP_KERNEL);
 	if (!jz_battery) {
 		dev_err(&pdev->dev, "Failed to allocate driver structure\n");
 		return -ENOMEM;
@@ -262,24 +262,21 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
 
 	jz_battery->irq = platform_get_irq(pdev, 0);
 	if (jz_battery->irq < 0) {
-		ret = jz_battery->irq;
 		dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
-		goto err_free;
+		return jz_battery->irq;
 	}
 
 	jz_battery->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!jz_battery->mem) {
-		ret = -ENOENT;
 		dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
-		goto err_free;
+		return -ENOENT;
 	}
 
 	jz_battery->mem = request_mem_region(jz_battery->mem->start,
 				resource_size(jz_battery->mem),	pdev->name);
 	if (!jz_battery->mem) {
-		ret = -EBUSY;
 		dev_err(&pdev->dev, "Failed to request mmio memory region\n");
-		goto err_free;
+		return -EBUSY;
 	}
 
 	jz_battery->base = ioremap_nocache(jz_battery->mem->start,
@@ -373,8 +370,6 @@ err_iounmap:
 	iounmap(jz_battery->base);
 err_release_mem_region:
 	release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem));
-err_free:
-	kfree(jz_battery);
 	return ret;
 }
 
@@ -396,7 +391,6 @@ static int __devexit jz_battery_remove(struct platform_device *pdev)
 
 	iounmap(jz_battery->base);
 	release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem));
-	kfree(jz_battery);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v3 2/2 drivres/power/jz4740-battery.c: Use devm_request_and_ioremap

In reply to Marcos Paulo de Souza

No functional changes. Just a cleanup.

---
 drivers/power/jz4740-battery.c |   33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)
drivers/power/jz4740-battery.c +7 -26
index 59900c6..e4ec7eb 100644
@@ -33,7 +33,6 @@ struct jz_battery {
 	struct jz_battery_platform_data *pdata;
 	struct platform_device *pdev;
 
-	struct resource *mem;
 	void __iomem *base;
 
 	int irq;
@@ -246,6 +245,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
 	struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data;
 	struct jz_battery *jz_battery;
 	struct power_supply *battery;
+	struct resource *mem;
 
 	if (!pdata) {
 		dev_err(&pdev->dev, "No platform_data supplied\n");
@@ -266,25 +266,12 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
 		return jz_battery->irq;
 	}
 
-	jz_battery->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!jz_battery->mem) {
-		dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
-		return -ENOENT;
-	}
-
-	jz_battery->mem = request_mem_region(jz_battery->mem->start,
-				resource_size(jz_battery->mem),	pdev->name);
-	if (!jz_battery->mem) {
-		dev_err(&pdev->dev, "Failed to request mmio memory region\n");
-		return -EBUSY;
-	}
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-	jz_battery->base = ioremap_nocache(jz_battery->mem->start,
-				resource_size(jz_battery->mem));
+	jz_battery->base = devm_request_and_ioremap(&pdev->dev, mem);
 	if (!jz_battery->base) {
-		ret = -EBUSY;
-		dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
-		goto err_release_mem_region;
+		dev_err(&pdev->dev, "Failed to request/ioremap mmio memory\n");
+		return -EBUSY;
 	}
 
 	battery = &jz_battery->battery;
@@ -308,7 +295,7 @@ static int __devinit jz_battery_probe(struct platform_device *pdev)
 			jz_battery);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to request irq %d\n", ret);
-		goto err_iounmap;
+		goto err;
 	}
 	disable_irq(jz_battery->irq);
 
@@ -365,11 +352,8 @@ err_free_gpio:
 		gpio_free(jz_battery->pdata->gpio_charge);
 err_free_irq:
 	free_irq(jz_battery->irq, jz_battery);
-err_iounmap:
+err:
 	platform_set_drvdata(pdev, NULL);
-	iounmap(jz_battery->base);
-err_release_mem_region:
-	release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem));
 	return ret;
 }
 
@@ -389,9 +373,6 @@ static int __devexit jz_battery_remove(struct platform_device *pdev)
 
 	free_irq(jz_battery->irq, jz_battery);
 
-	iounmap(jz_battery->base);
-	release_mem_region(jz_battery->mem->start, resource_size(jz_battery->mem));
-
 	return 0;
 }
 
Signature · 1 line
1.7.9.5
Acked-by on v3 2/2
#3 lore raw

Re: [PATCH 2/2] drivres/power/jz4740-battery.c: Use devm_request_and_ioremap

Quoted 3 lines · Marcos Paulo de Souza

No functional changes. Just a cleanup.

Looks good to me:

One minor comment though:

Quoted 8 lines
---
 drivers/power/jz4740-battery.c |   33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)
drivers/power/jz4740-battery.c +0 -0
index 59900c6..e4ec7eb 100644

drivers/power/jz4740-battery.c static int __devinit jz_battery_probe(struct platform_device *pdev) · line 273

Quoted 9 lines
drivers/power/jz4740-battery.c +2 -5
[...]
-	jz_battery->base = ioremap_nocache(jz_battery->mem->start,
-				resource_size(jz_battery->mem));
+	jz_battery->base = devm_request_and_ioremap(&pdev->dev, mem);
 	if (!jz_battery->base) {
-		ret = -EBUSY;
-		dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
-		goto err_release_mem_region;
+		dev_err(&pdev->dev, "Failed to request/ioremap mmio memory\n");

devm_request_and_ioremap will print its own error messages if it fails, so strictly speaking this is not necessary, but I don't think it is worth doing resend just for this.

Anton, maybe you can just remove the line when applying the patch.

Thanks,
- Lars

Quoted 3 lines
drivers/power/jz4740-battery.c +1 -0
+		return -EBUSY;
 	}

[...]

#4 lore raw

Re: [PATCH 2/2] drivres/power/jz4740-battery.c: Use devm_request_and_ioremap

Quoted 8 lines · Lars-Peter Clausen
Quoted 3 lines · Marcos Paulo de Souza

No functional changes. Just a cleanup.

Looks good to me:

Thanks for the patches and for the reviews!

Quoted 1 line

One minor comment though:

[...]

Quoted 5 lines

devm_request_and_ioremap will print its own error messages if it fails, so strictly speaking this is not necessary, but I don't think it is worth doing resend just for this.

Anton, maybe you can just remove the line when applying the patch.

Sure, I fixed it up and applied.

Anton.