mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream()
@ 2025-09-26  8:35 Zqiang
  2025-09-26  8:41 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Zqiang @ 2025-09-26  8:35 UTC (permalink / raw)
  To: edumazet, jlayton, akpm; +Cc: linux-kernel, qiang.zhang

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.

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 lib/ref_tracker.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index a9e6ffcff04b..a822de2b691e 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -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);
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream()
  2025-09-26  8:35 [PATCH] ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream() Zqiang
@ 2025-09-26  8:41 ` Eric Dumazet
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2025-09-26  8:41 UTC (permalink / raw)
  To: Zqiang; +Cc: jlayton, akpm, linux-kernel

On Fri, Sep 26, 2025 at 1:35 AM Zqiang <qiang.zhang@linux.dev> wrote:
>
> 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.
>
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-26  8:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-26  8:35 [PATCH] ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream() Zqiang
2025-09-26  8:41 ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®