Skip to contentSkip to conversation

nfsd: Use common error handling code in svc_export_alloc()

PATCH In review Markus Elfring 2 participants 2 messages Jun 11

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

PATCH 1/1 nfsd: Use common error handling code in svc_export_alloc()

From: Markus Elfring <[email protected]>
Date: Thu, 11 Jun 2026 14:03:48 +0200

Use an additional label so that a bit of exception handling can be better reused at the end of an if branch.

This issue was detected by using the Coccinelle software.

---
 fs/nfsd/export.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfsd/export.c +3 -4
index eb020054f9a3..bb106733f3ec 100644
@@ -1589,13 +1589,12 @@ static struct cache_head *svc_export_alloc(void)
 		return NULL;
 
 	i->ex_stats = kmalloc_obj(*(i->ex_stats));
-	if (!i->ex_stats) {
-		kfree(i);
-		return NULL;
-	}
+	if (!i->ex_stats)
+		goto free_export;
 
 	if (export_stats_init(i->ex_stats)) {
 		kfree(i->ex_stats);
+free_export:
 		kfree(i);
 		return NULL;
 	}
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 24 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 11 Jun 2026 14:03:48 +0200

Use an additional label so that a bit of exception handling can be better reused at the end of an if branch.

This issue was detected by using the Coccinelle software.

---
 fs/nfsd/export.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfsd/export.c +0 -3
index eb020054f9a3..bb106733f3ec 100644
@@ -1589,13 +1589,12 @@ static struct cache_head *svc_export_alloc(void)
 		return NULL;
 
 	i->ex_stats = kmalloc_obj(*(i->ex_stats));
-	if (!i->ex_stats) {
-		kfree(i);
-		return NULL;

fs/nfsd/export.c static struct cache_head *svc_export_alloc(void) · line 1600

Quoted 10 lines
fs/nfsd/export.c +3 -1
-	}
+	if (!i->ex_stats)
+		goto free_export;
 
 	if (export_stats_init(i->ex_stats)) {
 		kfree(i->ex_stats);
+free_export:
 		kfree(i);
 		return NULL;
 	}

I'm not a fan of this patch. I mean, it's legal and all, but sticking a goto label in the middle of a if block makes for messy-looking and hard to reason about code.

Signature · 1 line
Jeff Layton <[email protected]>