mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zqiang <qiang.zhang@linux.dev>
To: edumazet@google.com, jlayton@kernel.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, qiang.zhang@linux.dev
Subject: [PATCH] ref_tracker: Handling kmalloc() allocation failure in __ref_tracker_dir_pr_ostream()
Date: Fri, 26 Sep 2025 16:35:25 +0800	[thread overview]
Message-ID: <20250926083525.13500-1-qiang.zhang@linux.dev> (raw)

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


             reply	other threads:[~2025-09-26  8:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26  8:35 Zqiang [this message]
2025-09-26  8:41 ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250926083525.13500-1-qiang.zhang@linux.dev \
    --to=qiang.zhang@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=edumazet@google.com \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®