Skip to contentSkip to conversation

ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream()

PATCH In review Zqiang 2 participants 2 messages Sep 26, 2025 Library code

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream()

The kmalloc() maybe fail to allocate, causing sbuf to be null. this commit therefore free stats memory and exit function when the sbuf is null.

---
 lib/ref_tracker.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/ref_tracker.c +3 -1
index a9e6ffcff04b..a822de2b691e 100644
@@ -160,6 +160,8 @@ __ref_tracker_dir_pr_ostream(struct ref_tracker_dir *dir,
 	}
 
 	sbuf = kmalloc(STACK_BUF_SIZE, GFP_NOWAIT | __GFP_NOWARN);
+	if (!sbuf)
+		goto end;
 
 	for (i = 0, skipped = stats->total; i < stats->count; ++i) {
 		stack = stats->stacks[i].stack_handle;
@@ -176,7 +178,7 @@ __ref_tracker_dir_pr_ostream(struct ref_tracker_dir *dir,
 			   s->prefix, dir->class, dir, skipped, stats->total);
 
 	kfree(sbuf);
-
+end:
 	kfree(stats);
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Zqiang

The kmalloc() maybe fail to allocate, causing sbuf to be null. this commit therefore free stats memory and exit function when the sbuf is null.

I think you forgot a Fixes: tag ?

Anyway, current code handles this case just fine, so your patch would reduce the output of useful debug information.

Thank you.