summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/snapshot.c
diff options
context:
space:
mode:
authorAlan Huang <mmpgouride@gmail.com>2025-01-27 17:12:41 +0800
committerKent Overstreet <kent.overstreet@linux.dev>2025-03-14 21:02:12 -0400
commit7d8321a286de288778e175ea5b967dceaeed9c96 (patch)
treec3fc8fd1e5521e4f5414c3101cb1698574354b8e /fs/bcachefs/snapshot.c
parentbcachefs: Scrub (diff)
downloadlinux-7d8321a286de288778e175ea5b967dceaeed9c96.tar.gz
linux-7d8321a286de288778e175ea5b967dceaeed9c96.zip
bcachefs: Fix subtraction underflow
When ancestor is less than IS_ANCESTOR_BITMAP, we would get an incorrect result. Signed-off-by: Alan Huang <mmpgouride@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/snapshot.c')
-rw-r--r--fs/bcachefs/snapshot.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c
index c54091a28909..ede0b480e7d4 100644
--- a/fs/bcachefs/snapshot.c
+++ b/fs/bcachefs/snapshot.c
@@ -146,8 +146,9 @@ bool __bch2_snapshot_is_ancestor(struct bch_fs *c, u32 id, u32 ancestor)
goto out;
}
- while (id && id < ancestor - IS_ANCESTOR_BITMAP)
- id = get_ancestor_below(t, id, ancestor);
+ if (likely(ancestor >= IS_ANCESTOR_BITMAP))
+ while (id && id < ancestor - IS_ANCESTOR_BITMAP)
+ id = get_ancestor_below(t, id, ancestor);
ret = id && id < ancestor
? test_ancestor_bitmap(t, id, ancestor)