mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Fedor Pchelkin <pchelkin@ispras.ru>
Cc: Carlos Maiolino <cem@kernel.org>, Christoph Hellwig <hch@lst.de>,
	linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH v2 6/6] xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int()
Date: Wed, 2 Jul 2025 07:43:17 -0700	[thread overview]
Message-ID: <20250702144317.GT10009@frogsfrogsfrogs> (raw)
In-Reply-To: <20250702093935.123798-7-pchelkin@ispras.ru>

On Wed, Jul 02, 2025 at 12:39:33PM +0300, Fedor Pchelkin wrote:
> Use cmp_int() to yield the result of a three-way-comparison instead of
> performing subtractions with extra casts. Thus also rename the function
> to make its name clearer in purpose.
> 
> Found by Linux Verification Center (linuxtesting.org).
> 
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> ---
> 
> v2: rename the "diff_two_ptrs" part (Darrick)

Looks good now, thanks for the cmp_int cleanups!
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> 
>  fs/xfs/libxfs/xfs_btree.c | 8 ++++----
>  fs/xfs/libxfs/xfs_btree.h | 6 +++---
>  fs/xfs/scrub/btree.c      | 2 +-
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
> index d3591728998e..a61211d253f1 100644
> --- a/fs/xfs/libxfs/xfs_btree.c
> +++ b/fs/xfs/libxfs/xfs_btree.c
> @@ -5353,15 +5353,15 @@ xfs_btree_count_blocks(
>  }
>  
>  /* Compare two btree pointers. */
> -int64_t
> -xfs_btree_diff_two_ptrs(
> +int
> +xfs_btree_cmp_two_ptrs(
>  	struct xfs_btree_cur		*cur,
>  	const union xfs_btree_ptr	*a,
>  	const union xfs_btree_ptr	*b)
>  {
>  	if (cur->bc_ops->ptr_len == XFS_BTREE_LONG_PTR_LEN)
> -		return (int64_t)be64_to_cpu(a->l) - be64_to_cpu(b->l);
> -	return (int64_t)be32_to_cpu(a->s) - be32_to_cpu(b->s);
> +		return cmp_int(be64_to_cpu(a->l), be64_to_cpu(b->l));
> +	return cmp_int(be32_to_cpu(a->s), be32_to_cpu(b->s));
>  }
>  
>  struct xfs_btree_has_records {
> diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
> index 1bf20d509ac9..60e78572e725 100644
> --- a/fs/xfs/libxfs/xfs_btree.h
> +++ b/fs/xfs/libxfs/xfs_btree.h
> @@ -519,9 +519,9 @@ struct xfs_btree_block *xfs_btree_get_block(struct xfs_btree_cur *cur,
>  		int level, struct xfs_buf **bpp);
>  bool xfs_btree_ptr_is_null(struct xfs_btree_cur *cur,
>  		const union xfs_btree_ptr *ptr);
> -int64_t xfs_btree_diff_two_ptrs(struct xfs_btree_cur *cur,
> -				const union xfs_btree_ptr *a,
> -				const union xfs_btree_ptr *b);
> +int xfs_btree_cmp_two_ptrs(struct xfs_btree_cur *cur,
> +			   const union xfs_btree_ptr *a,
> +			   const union xfs_btree_ptr *b);
>  void xfs_btree_get_sibling(struct xfs_btree_cur *cur,
>  			   struct xfs_btree_block *block,
>  			   union xfs_btree_ptr *ptr, int lr);
> diff --git a/fs/xfs/scrub/btree.c b/fs/xfs/scrub/btree.c
> index fe678a0438bc..cd6f0ff382a7 100644
> --- a/fs/xfs/scrub/btree.c
> +++ b/fs/xfs/scrub/btree.c
> @@ -306,7 +306,7 @@ xchk_btree_block_check_sibling(
>  	if (pbp)
>  		xchk_buffer_recheck(bs->sc, pbp);
>  
> -	if (xfs_btree_diff_two_ptrs(cur, pp, sibling))
> +	if (xfs_btree_cmp_two_ptrs(cur, pp, sibling))
>  		xchk_btree_set_corrupt(bs->sc, cur, level);
>  out:
>  	xfs_btree_del_cursor(ncur, XFS_BTREE_ERROR);
> -- 
> 2.50.0
> 
> 

  reply	other threads:[~2025-07-02 14:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02  9:39 [PATCH v2 0/6] xfs: cleanup key comparing routines Fedor Pchelkin
2025-07-02  9:39 ` [PATCH v2 1/6] xfs: rename diff_two_keys routines Fedor Pchelkin
2025-07-02  9:39 ` [PATCH v2 2/6] xfs: rename key_diff routines Fedor Pchelkin
2025-07-02  9:39 ` [PATCH v2 3/6] xfs: refactor cmp_two_keys routines to take advantage of cmp_int() Fedor Pchelkin
2025-07-02  9:39 ` [PATCH v2 4/6] xfs: refactor cmp_key_with_cur " Fedor Pchelkin
2025-07-02  9:39 ` [PATCH v2 5/6] xfs: use a proper variable name and type for storing a comparison result Fedor Pchelkin
2025-07-02  9:39 ` [PATCH v2 6/6] xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int() Fedor Pchelkin
2025-07-02 14:43   ` Darrick J. Wong [this message]
2025-07-08 12:00 ` [PATCH v2 0/6] xfs: cleanup key comparing routines Carlos Maiolino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250702144317.GT10009@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=cem@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=pchelkin@ispras.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®