summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-05-19 19:16:22 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2024-05-20 05:37:26 -0400
commit6d48e61364aedd774d688f28b5a6c9b5f7f0018c (patch)
treef9d4d55e80bbaf89f5600be8a64bfaac429c3beb
parent6ce26ad376bdc65c2bc6d4ef7b8a939bf1bd19dc (diff)
bcachefs: Add missing guard in bch2_snapshot_has_children()
We additionally need to be going inconsistent if passed an invalid snapshot ID; that patch will need more thorough testing. Reported-by: syzbot+1c9fca23fe478633b305@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/snapshot.h7
1 files changed, 2 insertions, 5 deletions
diff --git a/fs/bcachefs/snapshot.h b/fs/bcachefs/snapshot.h
index bd5d74269d15..ab13d8f4b41e 100644
--- a/fs/bcachefs/snapshot.h
+++ b/fs/bcachefs/snapshot.h
@@ -176,12 +176,9 @@ static inline bool bch2_snapshot_is_ancestor(struct bch_fs *c, u32 id, u32 ances
static inline bool bch2_snapshot_has_children(struct bch_fs *c, u32 id)
{
- const struct snapshot_t *t;
- bool ret;
-
rcu_read_lock();
- t = snapshot_t(c, id);
- ret = (t->children[0]|t->children[1]) != 0;
+ const struct snapshot_t *t = snapshot_t(c, id);
+ bool ret = t && (t->children[0]|t->children[1]) != 0;
rcu_read_unlock();
return ret;