From: Alan Huang Date: Mon, 27 Jan 2025 09:12:41 +0000 (+0800) Subject: bcachefs: Fix subtraction underflow X-Git-Tag: v6.15-rc1~146^2~144 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7d8321a286de288778e175ea5b967dceaeed9c96;p=thirdparty%2Fkernel%2Flinux.git bcachefs: Fix subtraction underflow When ancestor is less than IS_ANCESTOR_BITMAP, we would get an incorrect result. Signed-off-by: Alan Huang Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c index c54091a289090..ede0b480e7d4b 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)