linux-bcachefs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bcachefs: Fix subtraction underflow
@ 2025-01-27  9:12 Alan Huang
  2025-01-28  0:00 ` Kent Overstreet
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Huang @ 2025-01-27  9:12 UTC (permalink / raw)
  To: kent.overstreet; +Cc: linux-bcachefs, Alan Huang

When ancestor is less than IS_ANCESTOR_BITMAP, we would get an incorrect
result.

Signed-off-by: Alan Huang <mmpgouride@gmail.com>
---
 fs/bcachefs/snapshot.c | 5 +++--
 1 file 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)
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bcachefs: Fix subtraction underflow
  2025-01-27  9:12 [PATCH] bcachefs: Fix subtraction underflow Alan Huang
@ 2025-01-28  0:00 ` Kent Overstreet
  0 siblings, 0 replies; 2+ messages in thread
From: Kent Overstreet @ 2025-01-28  0:00 UTC (permalink / raw)
  To: Alan Huang; +Cc: linux-bcachefs

On Mon, Jan 27, 2025 at 05:12:41PM +0800, Alan Huang wrote:
> When ancestor is less than IS_ANCESTOR_BITMAP, we would get an incorrect
> result.
> 
> Signed-off-by: Alan Huang <mmpgouride@gmail.com>
> ---
>  fs/bcachefs/snapshot.c | 5 +++--
>  1 file 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);

That's not right, if ancestor < IS_ANCESTOR_BITMAP the bitmap would
still need to be initialized.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-28  0:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-27  9:12 [PATCH] bcachefs: Fix subtraction underflow Alan Huang
2025-01-28  0:00 ` Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).