From: Jiasheng Jiang <jiashengjiangcool@gmail.com>
To: Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiasheng Jiang <jiashengjiangcool@gmail.com>
Subject: [PATCH] btrfs: add missing ASSERT for system space_info in reserve_chunk_space
Date: Thu, 8 Jan 2026 19:45:02 +0000 [thread overview]
Message-ID: <20260108194502.653-1-jiashengjiangcool@gmail.com> (raw)
In reserve_chunk_space(), btrfs_find_space_info() is called to retrieve
the space_info for the SYSTEM block group. However, the returned pointer
is immediately dereferenced by spin_lock(&info->lock) without validation.
While the SYSTEM space_info is expected to be present during normal
operations, direct dereference without checking creates a risk of a
null pointer dereference. This deviates from the coding pattern seen
in peer functions like btrfs_chunk_alloc() where such returns are
validated with an ASSERT.
Add an ASSERT() to ensure the pointer is valid before access, improving
code robustness and consistency with the rest of the block-group logic.
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
fs/btrfs/block-group.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 08b14449fabe..f4229ee4f573 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -4313,6 +4313,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
lockdep_assert_held(&fs_info->chunk_mutex);
info = btrfs_find_space_info(fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
+ ASSERT(info);
spin_lock(&info->lock);
left = info->total_bytes - btrfs_space_info_used(info, true);
spin_unlock(&info->lock);
--
2.25.1
next reply other threads:[~2026-01-08 19:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 19:45 Jiasheng Jiang [this message]
2026-01-08 23:32 ` Qu Wenruo
2026-01-09 15:17 ` David Sterba
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=20260108194502.653-1-jiashengjiangcool@gmail.com \
--to=jiashengjiangcool@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.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®