summaryrefslogtreecommitdiff
path: root/fs/bcachefs/snapshot.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-03-21 20:16:23 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2024-03-31 20:36:11 -0400
commit63332394c7e1f4f26e8e5b1387212016aaa7eae2 (patch)
tree0edf5feb41cb95963f6b65f7f8abf7c14910a1df /fs/bcachefs/snapshot.h
parentaa6e130e3c2965a5c26a4033ff63b5dc9549bd76 (diff)
bcachefs: Move snapshot table size to struct snapshot_table
We need to add bounds checking for snapshot table accesses - it turns out there are cases where we do need to use the snapshots table before fsck checks have completed (and indeed, fsck may not have been run). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/snapshot.h')
-rw-r--r--fs/bcachefs/snapshot.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/bcachefs/snapshot.h b/fs/bcachefs/snapshot.h
index 7c66ffc06385..8538b7fddfed 100644
--- a/fs/bcachefs/snapshot.h
+++ b/fs/bcachefs/snapshot.h
@@ -33,7 +33,11 @@ int bch2_mark_snapshot(struct btree_trans *, enum btree_id, unsigned,
static inline struct snapshot_t *__snapshot_t(struct snapshot_table *t, u32 id)
{
- return &t->s[U32_MAX - id];
+ u32 idx = U32_MAX - id;
+
+ return likely(t && idx < t->nr)
+ ? &t->s[idx]
+ : NULL;
}
static inline const struct snapshot_t *snapshot_t(struct bch_fs *c, u32 id)