Skip to contentSkip to conversation

mm/slab_common: reduce an if statement in create_cache()

PATCH In review Zhen Lei 3 participants 3 messages Jun 6, 2023

Subsystems (2)
lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

PATCH 1/1 mm/slab_common: reduce an if statement in create_cache()

Move the 'out:' statement block out of the successful path to avoid redundant check on 'err'. The value of 'err' is always zero on success and negative on failure.

No functional changes, no performance improvements, just a little more readability.

---
 mm/slab_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/slab_common.c +2 -4
index 607249785c077e9..f6fe35105774944 100644
@@ -236,14 +236,12 @@ static struct kmem_cache *create_cache(const char *name,
 
 	s->refcount = 1;
 	list_add(&s->list, &slab_caches);
-out:
-	if (err)
-		return ERR_PTR(err);
 	return s;
 
 out_free_cache:
 	kmem_cache_free(kmem_cache, s);
-	goto out;
+out:
+	return ERR_PTR(err);
 }
 
 /**
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Zhen Lei

Move the 'out:' statement block out of the successful path to avoid redundant check on 'err'. The value of 'err' is always zero on success and negative on failure.

No functional changes, no performance improvements, just a little more readability.

---
 mm/slab_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/slab_common.c +0 -3
index 607249785c077e9..f6fe35105774944 100644
@@ -236,14 +236,12 @@ static struct kmem_cache *create_cache(const char *name,
 
 	s->refcount = 1;
 	list_add(&s->list, &slab_caches);
-out:
-	if (err)
-		return ERR_PTR(err);

mm/slab_common.c static struct kmem_cache *create_cache(const char *name, · line 247

Quoted 10 lines
mm/slab_common.c +2 -1
 	return s;
 
 out_free_cache:
 	kmem_cache_free(kmem_cache, s);
-	goto out;
+out:
+	return ERR_PTR(err);
 }
 
 /**

Hi Zhen,
nice cleanup!

Looks correct to me,

Quoted 3 lines
Signature · 1 line
2.25.1
Signature · 5 lines
Hyeonggon Yoo

Doing kernel stuff as a hobby
Undergraduate | Chungnam National University
Dept. Computer Science & Engineering
#2 lore raw
Quoted 33 lines · Hyeonggon Yoo
Quoted 32 lines · Zhen Lei

Move the 'out:' statement block out of the successful path to avoid redundant check on 'err'. The value of 'err' is always zero on success and negative on failure.

No functional changes, no performance improvements, just a little more readability.

---
 mm/slab_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/slab_common.c +2 -4
index 607249785c077e9..f6fe35105774944 100644
@@ -236,14 +236,12 @@ static struct kmem_cache *create_cache(const char *name,
 
 	s->refcount = 1;
 	list_add(&s->list, &slab_caches);
-out:
-	if (err)
-		return ERR_PTR(err);
 	return s;
 
 out_free_cache:
 	kmem_cache_free(kmem_cache, s);
-	goto out;
+out:
+	return ERR_PTR(err);
 }
 
Quoted 7 lines

mm/slab_common.c static struct kmem_cache *create_cache(const char *name, · line 247

Quoted 1 line
mm/slab_common.c +0 -0
 /**

Hi Zhen,
nice cleanup!

Looks correct to me,

Thanks, added to slab/for-6.5/cleanup

Quoted 4 lines
Quoted 3 lines
Signature · 1 line
2.25.1