Skip to contentSkip to conversation

ARM: mmp: Fine-tuning for sram_probe()

PATCH New SF Markus Elfring 1 participant 3 messages Dec 3, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ARM: mmp: Fine-tuning for sram_probe()

From: Markus Elfring <[email protected]>
Date: Sat, 3 Dec 2016 17:50:23 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Check return values from ioremap() and kstrdup() Delete an unnecessary variable initialisation

 arch/arm/mach-mmp/sram.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/2 ARM: mmp: Check return values from ioremap() and kstrdup() in sram_probe()

From: Markus Elfring <[email protected]>
Date: Sat, 3 Dec 2016 17:26:32 +0100

Two return values were not checked before their further use so far. This issue was detected by using the Coccinelle software.

* Add a bit of exception handling.

* Adjust tump targets.

Fixes 3c7241bd36e2a618fe20c91f6c69cc20f2d981f2 ("ARM: mmp: add sram allocator")
---
 arch/arm/mach-mmp/sram.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
arch/arm/mach-mmp/sram.c +14 -3
index bf5e64906e65..0fbfc2a42ab3 100644
@@ -88,14 +88,24 @@ static int sram_probe(struct platform_device *pdev)
 	info->sram_phys   = (phys_addr_t)res->start;
 	info->sram_size   = resource_size(res);
 	info->sram_virt   = ioremap(info->sram_phys, info->sram_size);
+	if (!info->sram_virt) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	info->pool_name	  = kstrdup(pdata->pool_name, GFP_KERNEL);
+	if (!info->pool_name) {
+		ret = -ENOMEM;
+		goto unmap_io;
+	}
+
 	info->granularity = pdata->granularity;
 
 	info->gpool = gen_pool_create(ilog2(info->granularity), -1);
 	if (!info->gpool) {
 		dev_err(&pdev->dev, "create pool failed\n");
 		ret = -ENOMEM;
-		goto create_pool_err;
+		goto free_name;
 	}
 
 	ret = gen_pool_add_virt(info->gpool, (unsigned long)info->sram_virt,
@@ -117,9 +127,10 @@ static int sram_probe(struct platform_device *pdev)
 
 add_chunk_err:
 	gen_pool_destroy(info->gpool);
-create_pool_err:
-	iounmap(info->sram_virt);
+free_name:
 	kfree(info->pool_name);
+unmap_io:
+	iounmap(info->sram_virt);
 out:
 	kfree(info);
 	return ret;
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/2 ARM: mmp: Delete an unnecessary variable initialisation in sram_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Dec 2016 17:38:21 +0100

The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 arch/arm/mach-mmp/sram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-mmp/sram.c +1 -1
index 0fbfc2a42ab3..260e8309dfd3 100644
@@ -66,7 +66,7 @@ static int sram_probe(struct platform_device *pdev)
 	struct sram_platdata *pdata = pdev->dev.platform_data;
 	struct sram_bank_info *info;
 	struct resource *res;
-	int ret = 0;
+	int ret;
 
 	if (!pdata || !pdata->pool_name)
 		return -ENODEV;
Signature · 1 line
2.11.0