Skip to contentSkip to conversation

zpool: Adjustments for zpool_create_pool()

PATCH In review SF Markus Elfring 2 participants 5 messages Aug 14, 2017 – Aug 16, 2017

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

cover zpool: Adjustments for zpool_create_pool()

From: Markus Elfring <[email protected]>
Date: Mon, 14 Aug 2017 13:12:34 +0200

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

Markus Elfring (2):
Delete an error message for a failed memory allocation Use common error handling code

 mm/zpool.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
Signature · 1 line
2.14.0
#1 lore raw

PATCH 1/2 zpool: Delete an error message for a failed memory allocation in zpool_create_pool()

From: Markus Elfring <[email protected]>
Date: Mon, 14 Aug 2017 12:57:16 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 mm/zpool.c | 1 -
 1 file changed, 1 deletion(-)
mm/zpool.c +0 -1
index fd3ff719c32c..fe1943f7d844 100644
@@ -172,7 +172,6 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp,
 
 	zpool = kmalloc(sizeof(*zpool), gfp);
 	if (!zpool) {
-		pr_err("couldn't create zpool - out of memory\n");
 		zpool_put_driver(driver);
 		return NULL;
 	}
Signature · 1 line
2.14.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] zpool: Delete an error message for a failed memory allocation in zpool_create_pool()

Quoted 8 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 14 Aug 2017 12:57:16 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Quoted 19 lines
---
 mm/zpool.c | 1 -
 1 file changed, 1 deletion(-)
mm/zpool.c +0 -2
index fd3ff719c32c..fe1943f7d844 100644
@@ -172,7 +172,6 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp,
 
        zpool = kmalloc(sizeof(*zpool), gfp);
        if (!zpool) {
-               pr_err("couldn't create zpool - out of memory\n");
                zpool_put_driver(driver);
                return NULL;
        }
--

2.14.0

#3 lore raw

PATCH 2/2 zpool: Use common error handling code in zpool_create_pool()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 14 Aug 2017 13:04:33 +0200

Add a jump target so that a bit of exception handling can be better reused in this function.

---
 mm/zpool.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/zpool.c +4 -5
index fe1943f7d844..e4634edef86d 100644
@@ -171,10 +171,8 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp,
 	}
 
 	zpool = kmalloc(sizeof(*zpool), gfp);
-	if (!zpool) {
-		zpool_put_driver(driver);
-		return NULL;
-	}
+	if (!zpool)
+		goto put_driver;
 
 	zpool->driver = driver;
 	zpool->pool = driver->create(name, gfp, ops, zpool);
@@ -182,8 +180,9 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp,
 
 	if (!zpool->pool) {
 		pr_err("couldn't create %s pool\n", type);
-		zpool_put_driver(driver);
 		kfree(zpool);
+put_driver:
+		zpool_put_driver(driver);
 		return NULL;
 	}
 
Signature · 1 line
2.14.0
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] zpool: Use common error handling code in zpool_create_pool()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 14 Aug 2017 13:04:33 +0200

Add a jump target so that a bit of exception handling can be better reused in this function.

Quoted 35 lines
---
 mm/zpool.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
mm/zpool.c +4 -6
index fe1943f7d844..e4634edef86d 100644
@@ -171,10 +171,8 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp,
        }
 
        zpool = kmalloc(sizeof(*zpool), gfp);
-       if (!zpool) {
-               zpool_put_driver(driver);
-               return NULL;
-       }
+       if (!zpool)
+               goto put_driver;
 
        zpool->driver = driver;
        zpool->pool = driver->create(name, gfp, ops, zpool);
@@ -182,8 +180,9 @@ struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t gfp,
 
        if (!zpool->pool) {
                pr_err("couldn't create %s pool\n", type);
-               zpool_put_driver(driver);
                kfree(zpool);
+put_driver:
+               zpool_put_driver(driver);
                return NULL;
        }
 
--

2.14.0