Skip to contentSkip to conversation

cma: adjust goto branch in function cma_create_area()

PATCH In review Xishi Qiu 2 participants 2 messages Aug 5, 2013

Subsystems (2)
lore
Share & tools
lore

Xishi Qiu

author
#0 lore raw

PATCH 2/2 cma: adjust goto branch in function cma_create_area()

Adjust the function structure, one for the success path, the other for the failure path.

---
 drivers/base/dma-contiguous.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/base/dma-contiguous.c +9 -7
index 1bcfaed..aa72f93 100644
@@ -167,26 +167,28 @@ static __init struct cma *cma_create_area(unsigned long base_pfn,
 
 	cma = kmalloc(sizeof *cma, GFP_KERNEL);
 	if (!cma)
-		return ERR_PTR(-ENOMEM);
+		goto err;
 
 	cma->base_pfn = base_pfn;
 	cma->count = count;
 	cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
 
 	if (!cma->bitmap)
-		goto no_mem;
+		goto err;
 
 	ret = cma_activate_area(base_pfn, count);
 	if (ret)
-		goto error;
+		goto err;
 
 	pr_debug("%s: returned %p\n", __func__, (void *)cma);
 	return cma;
 
-error:
-	kfree(cma->bitmap);
-no_mem:
-	kfree(cma);
+err:
+	if (cma) {
+		if (cma->bitmap)
+			kfree(cma->bitmap);
+		kfree(cma);
+	}
 	return ERR_PTR(ret);
 }
 
Signature · 7 lines
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 7 lines · Xishi Qiu

Adjust the function structure, one for the success path, the other for the failure path.

---
 drivers/base/dma-contiguous.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

Ick, no, you just added 2 lines for no reason, and made the code harder to follow.

Quoted 27 lines
drivers/base/dma-contiguous.c +3 -3
index 1bcfaed..aa72f93 100644
@@ -167,26 +167,28 @@ static __init struct cma *cma_create_area(unsigned long base_pfn,
 
 	cma = kmalloc(sizeof *cma, GFP_KERNEL);
 	if (!cma)
-		return ERR_PTR(-ENOMEM);
+		goto err;
 
 	cma->base_pfn = base_pfn;
 	cma->count = count;
 	cma->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
 
 	if (!cma->bitmap)
-		goto no_mem;
+		goto err;
 
 	ret = cma_activate_area(base_pfn, count);
 	if (ret)
-		goto error;
+		goto err;
 
 	pr_debug("%s: returned %p\n", __func__, (void *)cma);
 	return cma;
 

drivers/base/dma-contiguous.c static __init struct cma *cma_create_area(unsigned long base_pfn, · line 191

Quoted 10 lines
drivers/base/dma-contiguous.c +6 -4
-error:
-	kfree(cma->bitmap);
-no_mem:
-	kfree(cma);
+err:
+	if (cma) {
+		if (cma->bitmap)
+			kfree(cma->bitmap);
+		kfree(cma);
+	}

kfree() can accept NULL just fine. I think the code looks acceptable as-is, so this isn't needed.

sorry,

greg k-h

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>