]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Fix subtraction underflow
authorAlan Huang <mmpgouride@gmail.com>
Mon, 27 Jan 2025 09:12:41 +0000 (17:12 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:12 +0000 (21:02 -0400)
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>
fs/bcachefs/snapshot.c

index c54091a2890905c5612d37ba21f516db80357419..ede0b480e7d4b36342c01b6e6dc69a2901b967d9 100644 (file)
@@ -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)