From nobody Wed Oct 8 04:22:00 2025 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C82D24A04D; Wed, 2 Jul 2025 09:40:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449224; cv=none; b=pVSGDuk0sdHQnlgq7dlKnELIksdsF5PN8X5F6WL+RuQSa6o7sed6cmOM5D88H5YfbsnSvHYFTA+wrPzQiYs5A5nDgIS9xRy36ABFZS59bkJScJLYldwVr/YWS4+YYYxcVE5iVI+SNONMJ4MoXVms6k4XcHrbHgI/M/1a0BizD38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449224; c=relaxed/simple; bh=NEQRU1HNdk+BRaM9VqI+A4+vP1bKeiT2h4K41Rwd/xI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QkYdXPo/X7WeaQ+vUuxUcsfKb11rL94U8E18qVTpOHmTTQq25y79LldWR23WCxBjzAZG9Lg7XDLGEsslQWYebR+9rEDtMsvdTOmvW/tPRrPq8SVXGeWXdOry2V13Am9w+X1stNsa7FztkcFn6JD+scb72OnSXunV884t1m5FJnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=R7eRzvhL; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="R7eRzvhL" Received: from fedora.intra.ispras.ru (unknown [10.10.165.14]) by mail.ispras.ru (Postfix) with ESMTPSA id 0B2B0552F55E; Wed, 2 Jul 2025 09:40:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 0B2B0552F55E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1751449212; bh=zaA8i10jGiaBbRQKYVw1Sac6jOXXDz9a1VAy5vivblw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R7eRzvhLOD3JuuKjMvnGHXiu6v8PXe57tAR1eFPA7UaqukFUmJWV69P1cJLisfCYu AHowDc5J/57oFmPe4nkTO224BvIfSAkvg3Mc5eQqvwgTV9yReApXIkkyzUCIiqUsjB osLmF4zj5Q/CSnUACe6ir4Re0jFVlDYBVCw5gE2o= From: Fedor Pchelkin To: Carlos Maiolino , "Darrick J. Wong" Cc: Fedor Pchelkin , Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2 1/6] xfs: rename diff_two_keys routines Date: Wed, 2 Jul 2025 12:39:28 +0300 Message-ID: <20250702093935.123798-2-pchelkin@ispras.ru> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702093935.123798-1-pchelkin@ispras.ru> References: <20250702093935.123798-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" One may think that diff_two_keys routines are used to compute the actual difference between the arguments but they return a result of a three-way-comparison of the passed operands. So it looks more appropriate to denote them as cmp_two_keys. Found by Linux Verification Center (linuxtesting.org). Signed-off-by: Fedor Pchelkin Reviewed-by: "Darrick J. Wong" --- v2: add R-b fs/xfs/libxfs/xfs_alloc_btree.c | 8 ++++---- fs/xfs/libxfs/xfs_bmap_btree.c | 4 ++-- fs/xfs/libxfs/xfs_btree.c | 2 +- fs/xfs/libxfs/xfs_btree.h | 26 +++++++++++++------------- fs/xfs/libxfs/xfs_ialloc_btree.c | 6 +++--- fs/xfs/libxfs/xfs_refcount_btree.c | 4 ++-- fs/xfs/libxfs/xfs_rmap_btree.c | 6 +++--- fs/xfs/libxfs/xfs_rtrefcount_btree.c | 4 ++-- fs/xfs/libxfs/xfs_rtrmap_btree.c | 6 +++--- fs/xfs/scrub/rcbag_btree.c | 4 ++-- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btre= e.c index a4ac37ba5d51..42e4b8105e47 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.c +++ b/fs/xfs/libxfs/xfs_alloc_btree.c @@ -214,7 +214,7 @@ xfs_cntbt_key_diff( } =20 STATIC int64_t -xfs_bnobt_diff_two_keys( +xfs_bnobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -227,7 +227,7 @@ xfs_bnobt_diff_two_keys( } =20 STATIC int64_t -xfs_cntbt_diff_two_keys( +xfs_cntbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -440,7 +440,7 @@ const struct xfs_btree_ops xfs_bnobt_ops =3D { .init_ptr_from_cur =3D xfs_allocbt_init_ptr_from_cur, .key_diff =3D xfs_bnobt_key_diff, .buf_ops =3D &xfs_bnobt_buf_ops, - .diff_two_keys =3D xfs_bnobt_diff_two_keys, + .cmp_two_keys =3D xfs_bnobt_cmp_two_keys, .keys_inorder =3D xfs_bnobt_keys_inorder, .recs_inorder =3D xfs_bnobt_recs_inorder, .keys_contiguous =3D xfs_allocbt_keys_contiguous, @@ -470,7 +470,7 @@ const struct xfs_btree_ops xfs_cntbt_ops =3D { .init_ptr_from_cur =3D xfs_allocbt_init_ptr_from_cur, .key_diff =3D xfs_cntbt_key_diff, .buf_ops =3D &xfs_cntbt_buf_ops, - .diff_two_keys =3D xfs_cntbt_diff_two_keys, + .cmp_two_keys =3D xfs_cntbt_cmp_two_keys, .keys_inorder =3D xfs_cntbt_keys_inorder, .recs_inorder =3D xfs_cntbt_recs_inorder, .keys_contiguous =3D NULL, /* not needed right now */ diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c index 908d7b050e9c..1cee9c2a3dc8 100644 --- a/fs/xfs/libxfs/xfs_bmap_btree.c +++ b/fs/xfs/libxfs/xfs_bmap_btree.c @@ -379,7 +379,7 @@ xfs_bmbt_key_diff( } =20 STATIC int64_t -xfs_bmbt_diff_two_keys( +xfs_bmbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -648,7 +648,7 @@ const struct xfs_btree_ops xfs_bmbt_ops =3D { .init_high_key_from_rec =3D xfs_bmbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_bmbt_init_rec_from_cur, .key_diff =3D xfs_bmbt_key_diff, - .diff_two_keys =3D xfs_bmbt_diff_two_keys, + .cmp_two_keys =3D xfs_bmbt_cmp_two_keys, .buf_ops =3D &xfs_bmbt_buf_ops, .keys_inorder =3D xfs_bmbt_keys_inorder, .recs_inorder =3D xfs_bmbt_recs_inorder, diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 299ce7fd11b0..c8164c194841 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -5058,7 +5058,7 @@ xfs_btree_simple_query_range( int error; =20 ASSERT(cur->bc_ops->init_high_key_from_rec); - ASSERT(cur->bc_ops->diff_two_keys); + ASSERT(cur->bc_ops->cmp_two_keys); =20 /* * Find the leftmost record. The btree cursor must be set diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 355b304696e6..1046bbf3839a 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -176,15 +176,15 @@ struct xfs_btree_ops { const union xfs_btree_key *key); =20 /* - * Difference between key2 and key1 -- positive if key1 > key2, - * negative if key1 < key2, and zero if equal. If the @mask parameter - * is non NULL, each key field to be used in the comparison must - * contain a nonzero value. + * Compare key1 and key2 -- positive if key1 > key2, negative if + * key1 < key2, and zero if equal. If the @mask parameter is non NULL, + * each key field to be used in the comparison must contain a nonzero + * value. */ - int64_t (*diff_two_keys)(struct xfs_btree_cur *cur, - const union xfs_btree_key *key1, - const union xfs_btree_key *key2, - const union xfs_btree_key *mask); + int64_t (*cmp_two_keys)(struct xfs_btree_cur *cur, + const union xfs_btree_key *key1, + const union xfs_btree_key *key2, + const union xfs_btree_key *mask); =20 const struct xfs_buf_ops *buf_ops; =20 @@ -546,7 +546,7 @@ xfs_btree_keycmp_lt( const union xfs_btree_key *key1, const union xfs_btree_key *key2) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, NULL) < 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, NULL) < 0; } =20 static inline bool @@ -555,7 +555,7 @@ xfs_btree_keycmp_gt( const union xfs_btree_key *key1, const union xfs_btree_key *key2) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, NULL) > 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, NULL) > 0; } =20 static inline bool @@ -564,7 +564,7 @@ xfs_btree_keycmp_eq( const union xfs_btree_key *key1, const union xfs_btree_key *key2) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, NULL) =3D=3D 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, NULL) =3D=3D 0; } =20 static inline bool @@ -602,7 +602,7 @@ xfs_btree_masked_keycmp_lt( const union xfs_btree_key *key2, const union xfs_btree_key *mask) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, mask) < 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, mask) < 0; } =20 static inline bool @@ -612,7 +612,7 @@ xfs_btree_masked_keycmp_gt( const union xfs_btree_key *key2, const union xfs_btree_key *mask) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, mask) > 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, mask) > 0; } =20 static inline bool diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_bt= ree.c index 6f270d8f4270..307734dbb5c7 100644 --- a/fs/xfs/libxfs/xfs_ialloc_btree.c +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c @@ -275,7 +275,7 @@ xfs_inobt_key_diff( } =20 STATIC int64_t -xfs_inobt_diff_two_keys( +xfs_inobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -432,7 +432,7 @@ const struct xfs_btree_ops xfs_inobt_ops =3D { .init_ptr_from_cur =3D xfs_inobt_init_ptr_from_cur, .key_diff =3D xfs_inobt_key_diff, .buf_ops =3D &xfs_inobt_buf_ops, - .diff_two_keys =3D xfs_inobt_diff_two_keys, + .cmp_two_keys =3D xfs_inobt_cmp_two_keys, .keys_inorder =3D xfs_inobt_keys_inorder, .recs_inorder =3D xfs_inobt_recs_inorder, .keys_contiguous =3D xfs_inobt_keys_contiguous, @@ -462,7 +462,7 @@ const struct xfs_btree_ops xfs_finobt_ops =3D { .init_ptr_from_cur =3D xfs_finobt_init_ptr_from_cur, .key_diff =3D xfs_inobt_key_diff, .buf_ops =3D &xfs_finobt_buf_ops, - .diff_two_keys =3D xfs_inobt_diff_two_keys, + .cmp_two_keys =3D xfs_inobt_cmp_two_keys, .keys_inorder =3D xfs_inobt_keys_inorder, .recs_inorder =3D xfs_inobt_recs_inorder, .keys_contiguous =3D xfs_inobt_keys_contiguous, diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcoun= t_btree.c index 54505fee1852..83f7758dc6dc 100644 --- a/fs/xfs/libxfs/xfs_refcount_btree.c +++ b/fs/xfs/libxfs/xfs_refcount_btree.c @@ -189,7 +189,7 @@ xfs_refcountbt_key_diff( } =20 STATIC int64_t -xfs_refcountbt_diff_two_keys( +xfs_refcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -341,7 +341,7 @@ const struct xfs_btree_ops xfs_refcountbt_ops =3D { .init_ptr_from_cur =3D xfs_refcountbt_init_ptr_from_cur, .key_diff =3D xfs_refcountbt_key_diff, .buf_ops =3D &xfs_refcountbt_buf_ops, - .diff_two_keys =3D xfs_refcountbt_diff_two_keys, + .cmp_two_keys =3D xfs_refcountbt_cmp_two_keys, .keys_inorder =3D xfs_refcountbt_keys_inorder, .recs_inorder =3D xfs_refcountbt_recs_inorder, .keys_contiguous =3D xfs_refcountbt_keys_contiguous, diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c index 2cab694ac58a..77f586844730 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -274,7 +274,7 @@ xfs_rmapbt_key_diff( } =20 STATIC int64_t -xfs_rmapbt_diff_two_keys( +xfs_rmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -517,7 +517,7 @@ const struct xfs_btree_ops xfs_rmapbt_ops =3D { .init_ptr_from_cur =3D xfs_rmapbt_init_ptr_from_cur, .key_diff =3D xfs_rmapbt_key_diff, .buf_ops =3D &xfs_rmapbt_buf_ops, - .diff_two_keys =3D xfs_rmapbt_diff_two_keys, + .cmp_two_keys =3D xfs_rmapbt_cmp_two_keys, .keys_inorder =3D xfs_rmapbt_keys_inorder, .recs_inorder =3D xfs_rmapbt_recs_inorder, .keys_contiguous =3D xfs_rmapbt_keys_contiguous, @@ -634,7 +634,7 @@ const struct xfs_btree_ops xfs_rmapbt_mem_ops =3D { .init_ptr_from_cur =3D xfbtree_init_ptr_from_cur, .key_diff =3D xfs_rmapbt_key_diff, .buf_ops =3D &xfs_rmapbt_mem_buf_ops, - .diff_two_keys =3D xfs_rmapbt_diff_two_keys, + .cmp_two_keys =3D xfs_rmapbt_cmp_two_keys, .keys_inorder =3D xfs_rmapbt_keys_inorder, .recs_inorder =3D xfs_rmapbt_recs_inorder, .keys_contiguous =3D xfs_rmapbt_keys_contiguous, diff --git a/fs/xfs/libxfs/xfs_rtrefcount_btree.c b/fs/xfs/libxfs/xfs_rtref= count_btree.c index 3db5e7a4a945..3ef29477877e 100644 --- a/fs/xfs/libxfs/xfs_rtrefcount_btree.c +++ b/fs/xfs/libxfs/xfs_rtrefcount_btree.c @@ -171,7 +171,7 @@ xfs_rtrefcountbt_key_diff( } =20 STATIC int64_t -xfs_rtrefcountbt_diff_two_keys( +xfs_rtrefcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -389,7 +389,7 @@ const struct xfs_btree_ops xfs_rtrefcountbt_ops =3D { .init_ptr_from_cur =3D xfs_rtrefcountbt_init_ptr_from_cur, .key_diff =3D xfs_rtrefcountbt_key_diff, .buf_ops =3D &xfs_rtrefcountbt_buf_ops, - .diff_two_keys =3D xfs_rtrefcountbt_diff_two_keys, + .cmp_two_keys =3D xfs_rtrefcountbt_cmp_two_keys, .keys_inorder =3D xfs_rtrefcountbt_keys_inorder, .recs_inorder =3D xfs_rtrefcountbt_recs_inorder, .keys_contiguous =3D xfs_rtrefcountbt_keys_contiguous, diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_bt= ree.c index 9bdc2cbfc113..6325502005c4 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -216,7 +216,7 @@ xfs_rtrmapbt_key_diff( } =20 STATIC int64_t -xfs_rtrmapbt_diff_two_keys( +xfs_rtrmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -513,7 +513,7 @@ const struct xfs_btree_ops xfs_rtrmapbt_ops =3D { .init_ptr_from_cur =3D xfs_rtrmapbt_init_ptr_from_cur, .key_diff =3D xfs_rtrmapbt_key_diff, .buf_ops =3D &xfs_rtrmapbt_buf_ops, - .diff_two_keys =3D xfs_rtrmapbt_diff_two_keys, + .cmp_two_keys =3D xfs_rtrmapbt_cmp_two_keys, .keys_inorder =3D xfs_rtrmapbt_keys_inorder, .recs_inorder =3D xfs_rtrmapbt_recs_inorder, .keys_contiguous =3D xfs_rtrmapbt_keys_contiguous, @@ -622,7 +622,7 @@ const struct xfs_btree_ops xfs_rtrmapbt_mem_ops =3D { .init_ptr_from_cur =3D xfbtree_init_ptr_from_cur, .key_diff =3D xfs_rtrmapbt_key_diff, .buf_ops =3D &xfs_rtrmapbt_mem_buf_ops, - .diff_two_keys =3D xfs_rtrmapbt_diff_two_keys, + .cmp_two_keys =3D xfs_rtrmapbt_cmp_two_keys, .keys_inorder =3D xfs_rtrmapbt_keys_inorder, .recs_inorder =3D xfs_rtrmapbt_recs_inorder, .keys_contiguous =3D xfs_rtrmapbt_keys_contiguous, diff --git a/fs/xfs/scrub/rcbag_btree.c b/fs/xfs/scrub/rcbag_btree.c index 709356dc6256..c3c7025ca336 100644 --- a/fs/xfs/scrub/rcbag_btree.c +++ b/fs/xfs/scrub/rcbag_btree.c @@ -69,7 +69,7 @@ rcbagbt_key_diff( } =20 STATIC int64_t -rcbagbt_diff_two_keys( +rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, @@ -203,7 +203,7 @@ static const struct xfs_btree_ops rcbagbt_mem_ops =3D { .init_ptr_from_cur =3D xfbtree_init_ptr_from_cur, .key_diff =3D rcbagbt_key_diff, .buf_ops =3D &rcbagbt_mem_buf_ops, - .diff_two_keys =3D rcbagbt_diff_two_keys, + .cmp_two_keys =3D rcbagbt_cmp_two_keys, .keys_inorder =3D rcbagbt_keys_inorder, .recs_inorder =3D rcbagbt_recs_inorder, }; --=20 2.50.0 From nobody Wed Oct 8 04:22:00 2025 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC5F024A078; Wed, 2 Jul 2025 09:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449223; cv=none; b=Kh4SnmXmqOIPtNAlslQ/I4HWbX582sbzHIFrToI+zKX6At5F8GhKQ05BPqW2h8Pox6uxsyYcr28yyMxhRqk4I9x+MGuaYKr8IpN2ihCiJu6v6fTXIghmTK0q5PIU0v3ZGdAZv9HaL0R0BpStzDjCsDPIqubdRndqeQzBi7arAwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449223; c=relaxed/simple; bh=GylIRNfb1DJ+poHhJYxJknehRWetqyLz0LxoQBNv9QI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gA8X/aE1AjMIq4WuGV2tMVpMIzRjtOgnrbVgty+mXpMGGy8VuVgDIoIR5EAUNJDE+J4vfIt48MjirghqMNj/DetdOaqz77wlj1Ua8g7sDzYsklCn4PsgBKUkFKDq5OHUt00Mn/cTSIgERmLMo9MxLQqYSzys3TH8AbUF33WY+8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=RL2SZpaT; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="RL2SZpaT" Received: from fedora.intra.ispras.ru (unknown [10.10.165.14]) by mail.ispras.ru (Postfix) with ESMTPSA id B081A4076181; Wed, 2 Jul 2025 09:40:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru B081A4076181 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1751449212; bh=N4msFhygMbbp7h3726x1edWXL6atLyITcwcNFsbu3tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RL2SZpaTRZmrXObaG/Xx9b9/EU16OIuZA/cGwEPQPIQWWRRnfKxfmXqlEPKjwkL3y uy6ahu5ikFUydBFS94kxd5SlR/k4ZSQa9Iga7JFA8pM8qa1IcWAsnJai/Yyv3VR6yZ G0+N93Erxj4J0lnRLRdNeoPKFJjG+730GQ1eCZrc= From: Fedor Pchelkin To: Carlos Maiolino , "Darrick J. Wong" Cc: Fedor Pchelkin , Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2 2/6] xfs: rename key_diff routines Date: Wed, 2 Jul 2025 12:39:29 +0300 Message-ID: <20250702093935.123798-3-pchelkin@ispras.ru> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702093935.123798-1-pchelkin@ispras.ru> References: <20250702093935.123798-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" key_diff routines compare a key value with a cursor value. Make the naming to be a bit more self-descriptive. Found by Linux Verification Center (linuxtesting.org). Signed-off-by: Fedor Pchelkin Reviewed-by: "Darrick J. Wong" --- v2: add R-b fs/xfs/libxfs/xfs_alloc_btree.c | 8 ++++---- fs/xfs/libxfs/xfs_bmap_btree.c | 4 ++-- fs/xfs/libxfs/xfs_btree.c | 2 +- fs/xfs/libxfs/xfs_btree.h | 9 ++++++--- fs/xfs/libxfs/xfs_ialloc_btree.c | 6 +++--- fs/xfs/libxfs/xfs_refcount_btree.c | 4 ++-- fs/xfs/libxfs/xfs_rmap_btree.c | 6 +++--- fs/xfs/libxfs/xfs_rtrefcount_btree.c | 4 ++-- fs/xfs/libxfs/xfs_rtrmap_btree.c | 6 +++--- fs/xfs/scrub/rcbag_btree.c | 4 ++-- 10 files changed, 28 insertions(+), 25 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btre= e.c index 42e4b8105e47..d01807e0c4d4 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.c +++ b/fs/xfs/libxfs/xfs_alloc_btree.c @@ -187,7 +187,7 @@ xfs_allocbt_init_ptr_from_cur( } =20 STATIC int64_t -xfs_bnobt_key_diff( +xfs_bnobt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -198,7 +198,7 @@ xfs_bnobt_key_diff( } =20 STATIC int64_t -xfs_cntbt_key_diff( +xfs_cntbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -438,7 +438,7 @@ const struct xfs_btree_ops xfs_bnobt_ops =3D { .init_high_key_from_rec =3D xfs_bnobt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_allocbt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_allocbt_init_ptr_from_cur, - .key_diff =3D xfs_bnobt_key_diff, + .cmp_key_with_cur =3D xfs_bnobt_cmp_key_with_cur, .buf_ops =3D &xfs_bnobt_buf_ops, .cmp_two_keys =3D xfs_bnobt_cmp_two_keys, .keys_inorder =3D xfs_bnobt_keys_inorder, @@ -468,7 +468,7 @@ const struct xfs_btree_ops xfs_cntbt_ops =3D { .init_high_key_from_rec =3D xfs_cntbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_allocbt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_allocbt_init_ptr_from_cur, - .key_diff =3D xfs_cntbt_key_diff, + .cmp_key_with_cur =3D xfs_cntbt_cmp_key_with_cur, .buf_ops =3D &xfs_cntbt_buf_ops, .cmp_two_keys =3D xfs_cntbt_cmp_two_keys, .keys_inorder =3D xfs_cntbt_keys_inorder, diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c index 1cee9c2a3dc8..0c5dba21d94a 100644 --- a/fs/xfs/libxfs/xfs_bmap_btree.c +++ b/fs/xfs/libxfs/xfs_bmap_btree.c @@ -370,7 +370,7 @@ xfs_bmbt_init_rec_from_cur( } =20 STATIC int64_t -xfs_bmbt_key_diff( +xfs_bmbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -647,7 +647,7 @@ const struct xfs_btree_ops xfs_bmbt_ops =3D { .init_key_from_rec =3D xfs_bmbt_init_key_from_rec, .init_high_key_from_rec =3D xfs_bmbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_bmbt_init_rec_from_cur, - .key_diff =3D xfs_bmbt_key_diff, + .cmp_key_with_cur =3D xfs_bmbt_cmp_key_with_cur, .cmp_two_keys =3D xfs_bmbt_cmp_two_keys, .buf_ops =3D &xfs_bmbt_buf_ops, .keys_inorder =3D xfs_bmbt_keys_inorder, diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index c8164c194841..99a63a178f25 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -2070,7 +2070,7 @@ xfs_btree_lookup( * - greater than, move left * - equal, we're done */ - diff =3D cur->bc_ops->key_diff(cur, kp); + diff =3D cur->bc_ops->cmp_key_with_cur(cur, kp); if (diff < 0) low =3D keyno + 1; else if (diff > 0) diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 1046bbf3839a..e72a10ba7ee6 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -171,9 +171,12 @@ struct xfs_btree_ops { void (*init_high_key_from_rec)(union xfs_btree_key *key, const union xfs_btree_rec *rec); =20 - /* difference between key value and cursor value */ - int64_t (*key_diff)(struct xfs_btree_cur *cur, - const union xfs_btree_key *key); + /* + * Compare key value and cursor value -- positive if key > cur, + * negative if key < cur, and zero if equal. + */ + int64_t (*cmp_key_with_cur)(struct xfs_btree_cur *cur, + const union xfs_btree_key *key); =20 /* * Compare key1 and key2 -- positive if key1 > key2, negative if diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_bt= ree.c index 307734dbb5c7..0d0c6534259a 100644 --- a/fs/xfs/libxfs/xfs_ialloc_btree.c +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c @@ -266,7 +266,7 @@ xfs_finobt_init_ptr_from_cur( } =20 STATIC int64_t -xfs_inobt_key_diff( +xfs_inobt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -430,7 +430,7 @@ const struct xfs_btree_ops xfs_inobt_ops =3D { .init_high_key_from_rec =3D xfs_inobt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_inobt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_inobt_init_ptr_from_cur, - .key_diff =3D xfs_inobt_key_diff, + .cmp_key_with_cur =3D xfs_inobt_cmp_key_with_cur, .buf_ops =3D &xfs_inobt_buf_ops, .cmp_two_keys =3D xfs_inobt_cmp_two_keys, .keys_inorder =3D xfs_inobt_keys_inorder, @@ -460,7 +460,7 @@ const struct xfs_btree_ops xfs_finobt_ops =3D { .init_high_key_from_rec =3D xfs_inobt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_inobt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_finobt_init_ptr_from_cur, - .key_diff =3D xfs_inobt_key_diff, + .cmp_key_with_cur =3D xfs_inobt_cmp_key_with_cur, .buf_ops =3D &xfs_finobt_buf_ops, .cmp_two_keys =3D xfs_inobt_cmp_two_keys, .keys_inorder =3D xfs_inobt_keys_inorder, diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcoun= t_btree.c index 83f7758dc6dc..885fc3a0a304 100644 --- a/fs/xfs/libxfs/xfs_refcount_btree.c +++ b/fs/xfs/libxfs/xfs_refcount_btree.c @@ -175,7 +175,7 @@ xfs_refcountbt_init_ptr_from_cur( } =20 STATIC int64_t -xfs_refcountbt_key_diff( +xfs_refcountbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -339,7 +339,7 @@ const struct xfs_btree_ops xfs_refcountbt_ops =3D { .init_high_key_from_rec =3D xfs_refcountbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_refcountbt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_refcountbt_init_ptr_from_cur, - .key_diff =3D xfs_refcountbt_key_diff, + .cmp_key_with_cur =3D xfs_refcountbt_cmp_key_with_cur, .buf_ops =3D &xfs_refcountbt_buf_ops, .cmp_two_keys =3D xfs_refcountbt_cmp_two_keys, .keys_inorder =3D xfs_refcountbt_keys_inorder, diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c index 77f586844730..74288d311b68 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -244,7 +244,7 @@ static inline uint64_t offset_keymask(uint64_t offset) } =20 STATIC int64_t -xfs_rmapbt_key_diff( +xfs_rmapbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -515,7 +515,7 @@ const struct xfs_btree_ops xfs_rmapbt_ops =3D { .init_high_key_from_rec =3D xfs_rmapbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_rmapbt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_rmapbt_init_ptr_from_cur, - .key_diff =3D xfs_rmapbt_key_diff, + .cmp_key_with_cur =3D xfs_rmapbt_cmp_key_with_cur, .buf_ops =3D &xfs_rmapbt_buf_ops, .cmp_two_keys =3D xfs_rmapbt_cmp_two_keys, .keys_inorder =3D xfs_rmapbt_keys_inorder, @@ -632,7 +632,7 @@ const struct xfs_btree_ops xfs_rmapbt_mem_ops =3D { .init_high_key_from_rec =3D xfs_rmapbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_rmapbt_init_rec_from_cur, .init_ptr_from_cur =3D xfbtree_init_ptr_from_cur, - .key_diff =3D xfs_rmapbt_key_diff, + .cmp_key_with_cur =3D xfs_rmapbt_cmp_key_with_cur, .buf_ops =3D &xfs_rmapbt_mem_buf_ops, .cmp_two_keys =3D xfs_rmapbt_cmp_two_keys, .keys_inorder =3D xfs_rmapbt_keys_inorder, diff --git a/fs/xfs/libxfs/xfs_rtrefcount_btree.c b/fs/xfs/libxfs/xfs_rtref= count_btree.c index 3ef29477877e..864c3aa664d7 100644 --- a/fs/xfs/libxfs/xfs_rtrefcount_btree.c +++ b/fs/xfs/libxfs/xfs_rtrefcount_btree.c @@ -157,7 +157,7 @@ xfs_rtrefcountbt_init_ptr_from_cur( } =20 STATIC int64_t -xfs_rtrefcountbt_key_diff( +xfs_rtrefcountbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -387,7 +387,7 @@ const struct xfs_btree_ops xfs_rtrefcountbt_ops =3D { .init_high_key_from_rec =3D xfs_rtrefcountbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_rtrefcountbt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_rtrefcountbt_init_ptr_from_cur, - .key_diff =3D xfs_rtrefcountbt_key_diff, + .cmp_key_with_cur =3D xfs_rtrefcountbt_cmp_key_with_cur, .buf_ops =3D &xfs_rtrefcountbt_buf_ops, .cmp_two_keys =3D xfs_rtrefcountbt_cmp_two_keys, .keys_inorder =3D xfs_rtrefcountbt_keys_inorder, diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_bt= ree.c index 6325502005c4..b48336086ca7 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -186,7 +186,7 @@ static inline uint64_t offset_keymask(uint64_t offset) } =20 STATIC int64_t -xfs_rtrmapbt_key_diff( +xfs_rtrmapbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -511,7 +511,7 @@ const struct xfs_btree_ops xfs_rtrmapbt_ops =3D { .init_high_key_from_rec =3D xfs_rtrmapbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_rtrmapbt_init_rec_from_cur, .init_ptr_from_cur =3D xfs_rtrmapbt_init_ptr_from_cur, - .key_diff =3D xfs_rtrmapbt_key_diff, + .cmp_key_with_cur =3D xfs_rtrmapbt_cmp_key_with_cur, .buf_ops =3D &xfs_rtrmapbt_buf_ops, .cmp_two_keys =3D xfs_rtrmapbt_cmp_two_keys, .keys_inorder =3D xfs_rtrmapbt_keys_inorder, @@ -620,7 +620,7 @@ const struct xfs_btree_ops xfs_rtrmapbt_mem_ops =3D { .init_high_key_from_rec =3D xfs_rtrmapbt_init_high_key_from_rec, .init_rec_from_cur =3D xfs_rtrmapbt_init_rec_from_cur, .init_ptr_from_cur =3D xfbtree_init_ptr_from_cur, - .key_diff =3D xfs_rtrmapbt_key_diff, + .cmp_key_with_cur =3D xfs_rtrmapbt_cmp_key_with_cur, .buf_ops =3D &xfs_rtrmapbt_mem_buf_ops, .cmp_two_keys =3D xfs_rtrmapbt_cmp_two_keys, .keys_inorder =3D xfs_rtrmapbt_keys_inorder, diff --git a/fs/xfs/scrub/rcbag_btree.c b/fs/xfs/scrub/rcbag_btree.c index c3c7025ca336..523ffd0da77a 100644 --- a/fs/xfs/scrub/rcbag_btree.c +++ b/fs/xfs/scrub/rcbag_btree.c @@ -48,7 +48,7 @@ rcbagbt_init_rec_from_cur( } =20 STATIC int64_t -rcbagbt_key_diff( +rcbagbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { @@ -201,7 +201,7 @@ static const struct xfs_btree_ops rcbagbt_mem_ops =3D { .init_key_from_rec =3D rcbagbt_init_key_from_rec, .init_rec_from_cur =3D rcbagbt_init_rec_from_cur, .init_ptr_from_cur =3D xfbtree_init_ptr_from_cur, - .key_diff =3D rcbagbt_key_diff, + .cmp_key_with_cur =3D rcbagbt_cmp_key_with_cur, .buf_ops =3D &rcbagbt_mem_buf_ops, .cmp_two_keys =3D rcbagbt_cmp_two_keys, .keys_inorder =3D rcbagbt_keys_inorder, --=20 2.50.0 From nobody Wed Oct 8 04:22:00 2025 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC67D2512FF; Wed, 2 Jul 2025 09:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449223; cv=none; b=n+lw9LlUoDVFbbV9+jSI4VTGgOGyVCG07VhZUHHe4NCmzbdOY4fDxndhqHSU+AVF3iik8PMgaoXeBfd11ZuFU6isn4jw/MhqUlXu1XhAiD6iYeHbhck3LYKF1czGYtyY8TmIvTKM/HwC7xa3yJWJ2mBpWbH3QQlVc+Gpi7Z3qTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449223; c=relaxed/simple; bh=PKtduxNHLaG/iyvNy/09gNTUMS1xS68Wdkb3lsnsgM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BgNwadRfvzaNAFN6ZFU2nKWyt6O1pCTc2AT1u71NWEuvMlsOMblOfut7nBGcBdl/9cognvLCPn+ZuObueajgYvNDdGcaBXzX3WlmcgbBob4IvaoXJiFe9Il/u2OA6+9bUtzYEYxdCraeIjMoIvGsqkaklXiBcA84IgFYS50tsEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=p5cIqzGX; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="p5cIqzGX" Received: from fedora.intra.ispras.ru (unknown [10.10.165.14]) by mail.ispras.ru (Postfix) with ESMTPSA id 4901F40737DC; Wed, 2 Jul 2025 09:40:13 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 4901F40737DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1751449213; bh=RE+PudlIQdKtoBJ6OWbQXVmGrwcTEPVrgu1koayZCik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p5cIqzGXxr0MrJbz73aQ3zaT+L346NCzdqj9u/qrghpWT0bhxwS1AmeV4xOHGpbG5 bAEqqPhSqwEy/7DZxYneFTj5w7GwRCi6ziRGIGK7Fvt3+jkszb/W6DKn3eJNwabBvp 5g/7bv40I86QJstBCRjER227KX+qv4kCdWnh01lk= From: Fedor Pchelkin To: Carlos Maiolino , "Darrick J. Wong" Cc: Fedor Pchelkin , Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2 3/6] xfs: refactor cmp_two_keys routines to take advantage of cmp_int() Date: Wed, 2 Jul 2025 12:39:30 +0300 Message-ID: <20250702093935.123798-4-pchelkin@ispras.ru> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702093935.123798-1-pchelkin@ispras.ru> References: <20250702093935.123798-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The net value of these functions is to determine the result of a three-way-comparison between operands of the same type. Simplify the code using cmp_int() to eliminate potential errors with opencoded casts and subtractions. This also means we can change the return value type of cmp_two_keys routines from int64_t to int and make the interface a bit clearer. Found by Linux Verification Center (linuxtesting.org). Suggested-by: "Darrick J. Wong" Signed-off-by: Fedor Pchelkin Reviewed-by: "Darrick J. Wong" --- v2: add R-b fs/xfs/libxfs/xfs_alloc_btree.c | 21 ++++++++------------ fs/xfs/libxfs/xfs_bmap_btree.c | 18 +++-------------- fs/xfs/libxfs/xfs_btree.h | 2 +- fs/xfs/libxfs/xfs_ialloc_btree.c | 6 +++--- fs/xfs/libxfs/xfs_refcount_btree.c | 6 +++--- fs/xfs/libxfs/xfs_rmap_btree.c | 29 ++++++++++++---------------- fs/xfs/libxfs/xfs_rtrefcount_btree.c | 6 +++--- fs/xfs/libxfs/xfs_rtrmap_btree.c | 29 ++++++++++++---------------- fs/xfs/scrub/rcbag_btree.c | 15 +++----------- 9 files changed, 48 insertions(+), 84 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btre= e.c index d01807e0c4d4..f371f1b32cfb 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.c +++ b/fs/xfs/libxfs/xfs_alloc_btree.c @@ -213,7 +213,7 @@ xfs_cntbt_cmp_key_with_cur( return (int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock; } =20 -STATIC int64_t +STATIC int xfs_bnobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -222,29 +222,24 @@ xfs_bnobt_cmp_two_keys( { ASSERT(!mask || mask->alloc.ar_startblock); =20 - return (int64_t)be32_to_cpu(k1->alloc.ar_startblock) - - be32_to_cpu(k2->alloc.ar_startblock); + return cmp_int(be32_to_cpu(k1->alloc.ar_startblock), + be32_to_cpu(k2->alloc.ar_startblock)); } =20 -STATIC int64_t +STATIC int xfs_cntbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, const union xfs_btree_key *mask) { - int64_t diff; - ASSERT(!mask || (mask->alloc.ar_blockcount && mask->alloc.ar_startblock)); =20 - diff =3D be32_to_cpu(k1->alloc.ar_blockcount) - - be32_to_cpu(k2->alloc.ar_blockcount); - if (diff) - return diff; - - return be32_to_cpu(k1->alloc.ar_startblock) - - be32_to_cpu(k2->alloc.ar_startblock); + return cmp_int(be32_to_cpu(k1->alloc.ar_blockcount), + be32_to_cpu(k2->alloc.ar_blockcount)) ?: + cmp_int(be32_to_cpu(k1->alloc.ar_startblock), + be32_to_cpu(k2->alloc.ar_startblock)); } =20 static xfs_failaddr_t diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c index 0c5dba21d94a..bfe67e5d4d11 100644 --- a/fs/xfs/libxfs/xfs_bmap_btree.c +++ b/fs/xfs/libxfs/xfs_bmap_btree.c @@ -378,29 +378,17 @@ xfs_bmbt_cmp_key_with_cur( cur->bc_rec.b.br_startoff; } =20 -STATIC int64_t +STATIC int xfs_bmbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2, const union xfs_btree_key *mask) { - uint64_t a =3D be64_to_cpu(k1->bmbt.br_startoff); - uint64_t b =3D be64_to_cpu(k2->bmbt.br_startoff); - ASSERT(!mask || mask->bmbt.br_startoff); =20 - /* - * Note: This routine previously casted a and b to int64 and subtracted - * them to generate a result. This lead to problems if b was the - * "maximum" key value (all ones) being signed incorrectly, hence this - * somewhat less efficient version. - */ - if (a > b) - return 1; - if (b > a) - return -1; - return 0; + return cmp_int(be64_to_cpu(k1->bmbt.br_startoff), + be64_to_cpu(k2->bmbt.br_startoff)); } =20 static xfs_failaddr_t diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index e72a10ba7ee6..fecd9f0b9398 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -184,7 +184,7 @@ struct xfs_btree_ops { * each key field to be used in the comparison must contain a nonzero * value. */ - int64_t (*cmp_two_keys)(struct xfs_btree_cur *cur, + int (*cmp_two_keys)(struct xfs_btree_cur *cur, const union xfs_btree_key *key1, const union xfs_btree_key *key2, const union xfs_btree_key *mask); diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_bt= ree.c index 0d0c6534259a..ab9fce20b083 100644 --- a/fs/xfs/libxfs/xfs_ialloc_btree.c +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c @@ -274,7 +274,7 @@ xfs_inobt_cmp_key_with_cur( cur->bc_rec.i.ir_startino; } =20 -STATIC int64_t +STATIC int xfs_inobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -283,8 +283,8 @@ xfs_inobt_cmp_two_keys( { ASSERT(!mask || mask->inobt.ir_startino); =20 - return (int64_t)be32_to_cpu(k1->inobt.ir_startino) - - be32_to_cpu(k2->inobt.ir_startino); + return cmp_int(be32_to_cpu(k1->inobt.ir_startino), + be32_to_cpu(k2->inobt.ir_startino)); } =20 static xfs_failaddr_t diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcoun= t_btree.c index 885fc3a0a304..1c3996b11563 100644 --- a/fs/xfs/libxfs/xfs_refcount_btree.c +++ b/fs/xfs/libxfs/xfs_refcount_btree.c @@ -188,7 +188,7 @@ xfs_refcountbt_cmp_key_with_cur( return (int64_t)be32_to_cpu(kp->rc_startblock) - start; } =20 -STATIC int64_t +STATIC int xfs_refcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -197,8 +197,8 @@ xfs_refcountbt_cmp_two_keys( { ASSERT(!mask || mask->refc.rc_startblock); =20 - return (int64_t)be32_to_cpu(k1->refc.rc_startblock) - - be32_to_cpu(k2->refc.rc_startblock); + return cmp_int(be32_to_cpu(k1->refc.rc_startblock), + be32_to_cpu(k2->refc.rc_startblock)); } =20 STATIC xfs_failaddr_t diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c index 74288d311b68..3cccdb0d0418 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -273,7 +273,7 @@ xfs_rmapbt_cmp_key_with_cur( return 0; } =20 -STATIC int64_t +STATIC int xfs_rmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -282,36 +282,31 @@ xfs_rmapbt_cmp_two_keys( { const struct xfs_rmap_key *kp1 =3D &k1->rmap; const struct xfs_rmap_key *kp2 =3D &k2->rmap; - int64_t d; - __u64 x, y; + int d; =20 /* Doesn't make sense to mask off the physical space part */ ASSERT(!mask || mask->rmap.rm_startblock); =20 - d =3D (int64_t)be32_to_cpu(kp1->rm_startblock) - - be32_to_cpu(kp2->rm_startblock); + d =3D cmp_int(be32_to_cpu(kp1->rm_startblock), + be32_to_cpu(kp2->rm_startblock)); if (d) return d; =20 if (!mask || mask->rmap.rm_owner) { - x =3D be64_to_cpu(kp1->rm_owner); - y =3D be64_to_cpu(kp2->rm_owner); - if (x > y) - return 1; - else if (y > x) - return -1; + d =3D cmp_int(be64_to_cpu(kp1->rm_owner), + be64_to_cpu(kp2->rm_owner)); + if (d) + return d; } =20 if (!mask || mask->rmap.rm_offset) { /* Doesn't make sense to allow offset but not owner */ ASSERT(!mask || mask->rmap.rm_owner); =20 - x =3D offset_keymask(be64_to_cpu(kp1->rm_offset)); - y =3D offset_keymask(be64_to_cpu(kp2->rm_offset)); - if (x > y) - return 1; - else if (y > x) - return -1; + d =3D cmp_int(offset_keymask(be64_to_cpu(kp1->rm_offset)), + offset_keymask(be64_to_cpu(kp2->rm_offset))); + if (d) + return d; } =20 return 0; diff --git a/fs/xfs/libxfs/xfs_rtrefcount_btree.c b/fs/xfs/libxfs/xfs_rtref= count_btree.c index 864c3aa664d7..d9f79ae579c6 100644 --- a/fs/xfs/libxfs/xfs_rtrefcount_btree.c +++ b/fs/xfs/libxfs/xfs_rtrefcount_btree.c @@ -170,7 +170,7 @@ xfs_rtrefcountbt_cmp_key_with_cur( return (int64_t)be32_to_cpu(kp->rc_startblock) - start; } =20 -STATIC int64_t +STATIC int xfs_rtrefcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -179,8 +179,8 @@ xfs_rtrefcountbt_cmp_two_keys( { ASSERT(!mask || mask->refc.rc_startblock); =20 - return (int64_t)be32_to_cpu(k1->refc.rc_startblock) - - be32_to_cpu(k2->refc.rc_startblock); + return cmp_int(be32_to_cpu(k1->refc.rc_startblock), + be32_to_cpu(k2->refc.rc_startblock)); } =20 static xfs_failaddr_t diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_bt= ree.c index b48336086ca7..231a189ea2fe 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -215,7 +215,7 @@ xfs_rtrmapbt_cmp_key_with_cur( return 0; } =20 -STATIC int64_t +STATIC int xfs_rtrmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -224,36 +224,31 @@ xfs_rtrmapbt_cmp_two_keys( { const struct xfs_rmap_key *kp1 =3D &k1->rmap; const struct xfs_rmap_key *kp2 =3D &k2->rmap; - int64_t d; - __u64 x, y; + int d; =20 /* Doesn't make sense to mask off the physical space part */ ASSERT(!mask || mask->rmap.rm_startblock); =20 - d =3D (int64_t)be32_to_cpu(kp1->rm_startblock) - - be32_to_cpu(kp2->rm_startblock); + d =3D cmp_int(be32_to_cpu(kp1->rm_startblock), + be32_to_cpu(kp2->rm_startblock)); if (d) return d; =20 if (!mask || mask->rmap.rm_owner) { - x =3D be64_to_cpu(kp1->rm_owner); - y =3D be64_to_cpu(kp2->rm_owner); - if (x > y) - return 1; - else if (y > x) - return -1; + d =3D cmp_int(be64_to_cpu(kp1->rm_owner), + be64_to_cpu(kp2->rm_owner)); + if (d) + return d; } =20 if (!mask || mask->rmap.rm_offset) { /* Doesn't make sense to allow offset but not owner */ ASSERT(!mask || mask->rmap.rm_owner); =20 - x =3D offset_keymask(be64_to_cpu(kp1->rm_offset)); - y =3D offset_keymask(be64_to_cpu(kp2->rm_offset)); - if (x > y) - return 1; - else if (y > x) - return -1; + d =3D cmp_int(offset_keymask(be64_to_cpu(kp1->rm_offset)), + offset_keymask(be64_to_cpu(kp2->rm_offset))); + if (d) + return d; } =20 return 0; diff --git a/fs/xfs/scrub/rcbag_btree.c b/fs/xfs/scrub/rcbag_btree.c index 523ffd0da77a..46598817b239 100644 --- a/fs/xfs/scrub/rcbag_btree.c +++ b/fs/xfs/scrub/rcbag_btree.c @@ -68,7 +68,7 @@ rcbagbt_cmp_key_with_cur( return 0; } =20 -STATIC int64_t +STATIC int rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, @@ -80,17 +80,8 @@ rcbagbt_cmp_two_keys( =20 ASSERT(mask =3D=3D NULL); =20 - if (kp1->rbg_startblock > kp2->rbg_startblock) - return 1; - if (kp1->rbg_startblock < kp2->rbg_startblock) - return -1; - - if (kp1->rbg_blockcount > kp2->rbg_blockcount) - return 1; - if (kp1->rbg_blockcount < kp2->rbg_blockcount) - return -1; - - return 0; + return cmp_int(kp1->rbg_startblock, kp2->rbg_startblock) ?: + cmp_int(kp1->rbg_blockcount, kp2->rbg_blockcount); } =20 STATIC int --=20 2.50.0 From nobody Wed Oct 8 04:22:00 2025 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EB4D248864; Wed, 2 Jul 2025 09:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449224; cv=none; b=ktPTs2MJV25dgkbpm+VZD5gZDWLuKL1vxLwbdzA12wvhIse3S0PyVk2w/bzoH3yQN748LldVgctSKzTEeP6Mm+zF+IXdkBSNmMoIljThrdmQPLEiOgROhz+xTHkC1AiNKyBgzZBVx8G29XqEE2qm+4lTQqY634sTc7EFRLJKDxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449224; c=relaxed/simple; bh=ZgHnMl9NWn5mCArVqk+Ru79mRa6zWCslA6f+9+nPR4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJxaBDSGP+/FaLxne+noxv3dsP3I21yowfXvMN0NmV63HU+/cUNEx8JVS6dUfOWMvkJLuw5iN5Fi5YMR9ZlotWe/5PXvkVq8rnhDrfrqRgxDBjVGz0V1GVxwa35Bs14ySN0WvQP1S1p8gqG6p8rbRNNmxazo/qslH4N+AKlIZaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=QHVsQ+gu; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="QHVsQ+gu" Received: from fedora.intra.ispras.ru (unknown [10.10.165.14]) by mail.ispras.ru (Postfix) with ESMTPSA id C77AC4076182; Wed, 2 Jul 2025 09:40:13 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru C77AC4076182 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1751449213; bh=yuxyEw3gYXfXhUx8APguVkeIxay7jBrsKTT8l2pYXNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QHVsQ+guVNTwzd/s3GI6k253XvzNMj8ZSbuw4IF/UnkG0mwAZAcAQKjz8l97mXVxb pPx+9RMlAnLKesUaSOvR2Ash+F6lml9MPkmM9dyYNyAPiYjLIOBa+/+bsuYUK6PcGL Pi0Us9cnNEnO99DW4LeXIwG1iQU1n7q8Fk3pwyIs= From: Fedor Pchelkin To: Carlos Maiolino , "Darrick J. Wong" Cc: Fedor Pchelkin , Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2 4/6] xfs: refactor cmp_key_with_cur routines to take advantage of cmp_int() Date: Wed, 2 Jul 2025 12:39:31 +0300 Message-ID: <20250702093935.123798-5-pchelkin@ispras.ru> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702093935.123798-1-pchelkin@ispras.ru> References: <20250702093935.123798-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The net value of these functions is to determine the result of a three-way-comparison between operands of the same type. Simplify the code using cmp_int() to eliminate potential errors with opencoded casts and subtractions. This also means we can change the return value type of cmp_key_with_cur routines from int64_t to int and make the interface a bit clearer. Found by Linux Verification Center (linuxtesting.org). Suggested-by: "Darrick J. Wong" Signed-off-by: Fedor Pchelkin Reviewed-by: "Darrick J. Wong" --- v2: add R-b fs/xfs/libxfs/xfs_alloc_btree.c | 15 ++++++--------- fs/xfs/libxfs/xfs_bmap_btree.c | 6 +++--- fs/xfs/libxfs/xfs_btree.h | 2 +- fs/xfs/libxfs/xfs_ialloc_btree.c | 6 +++--- fs/xfs/libxfs/xfs_refcount_btree.c | 4 ++-- fs/xfs/libxfs/xfs_rmap_btree.c | 26 +++++--------------------- fs/xfs/libxfs/xfs_rtrefcount_btree.c | 4 ++-- fs/xfs/libxfs/xfs_rtrmap_btree.c | 26 +++++--------------------- fs/xfs/scrub/rcbag_btree.c | 15 +++------------ 9 files changed, 30 insertions(+), 74 deletions(-) diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btre= e.c index f371f1b32cfb..fa1f03c1331e 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.c +++ b/fs/xfs/libxfs/xfs_alloc_btree.c @@ -186,7 +186,7 @@ xfs_allocbt_init_ptr_from_cur( ptr->s =3D agf->agf_cnt_root; } =20 -STATIC int64_t +STATIC int xfs_bnobt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) @@ -194,23 +194,20 @@ xfs_bnobt_cmp_key_with_cur( struct xfs_alloc_rec_incore *rec =3D &cur->bc_rec.a; const struct xfs_alloc_rec *kp =3D &key->alloc; =20 - return (int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock; + return cmp_int(be32_to_cpu(kp->ar_startblock), + rec->ar_startblock); } =20 -STATIC int64_t +STATIC int xfs_cntbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { struct xfs_alloc_rec_incore *rec =3D &cur->bc_rec.a; const struct xfs_alloc_rec *kp =3D &key->alloc; - int64_t diff; - - diff =3D (int64_t)be32_to_cpu(kp->ar_blockcount) - rec->ar_blockcount; - if (diff) - return diff; =20 - return (int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock; + return cmp_int(be32_to_cpu(kp->ar_blockcount), rec->ar_blockcount) ?: + cmp_int(be32_to_cpu(kp->ar_startblock), rec->ar_startblock); } =20 STATIC int diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c index bfe67e5d4d11..188feac04b60 100644 --- a/fs/xfs/libxfs/xfs_bmap_btree.c +++ b/fs/xfs/libxfs/xfs_bmap_btree.c @@ -369,13 +369,13 @@ xfs_bmbt_init_rec_from_cur( xfs_bmbt_disk_set_all(&rec->bmbt, &cur->bc_rec.b); } =20 -STATIC int64_t +STATIC int xfs_bmbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { - return (int64_t)be64_to_cpu(key->bmbt.br_startoff) - - cur->bc_rec.b.br_startoff; + return cmp_int(be64_to_cpu(key->bmbt.br_startoff), + cur->bc_rec.b.br_startoff); } =20 STATIC int diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index fecd9f0b9398..1bf20d509ac9 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -175,7 +175,7 @@ struct xfs_btree_ops { * Compare key value and cursor value -- positive if key > cur, * negative if key < cur, and zero if equal. */ - int64_t (*cmp_key_with_cur)(struct xfs_btree_cur *cur, + int (*cmp_key_with_cur)(struct xfs_btree_cur *cur, const union xfs_btree_key *key); =20 /* diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_bt= ree.c index ab9fce20b083..100afdd66cdd 100644 --- a/fs/xfs/libxfs/xfs_ialloc_btree.c +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c @@ -265,13 +265,13 @@ xfs_finobt_init_ptr_from_cur( ptr->s =3D agi->agi_free_root; } =20 -STATIC int64_t +STATIC int xfs_inobt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { - return (int64_t)be32_to_cpu(key->inobt.ir_startino) - - cur->bc_rec.i.ir_startino; + return cmp_int(be32_to_cpu(key->inobt.ir_startino), + cur->bc_rec.i.ir_startino); } =20 STATIC int diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c b/fs/xfs/libxfs/xfs_refcoun= t_btree.c index 1c3996b11563..06da3ca14727 100644 --- a/fs/xfs/libxfs/xfs_refcount_btree.c +++ b/fs/xfs/libxfs/xfs_refcount_btree.c @@ -174,7 +174,7 @@ xfs_refcountbt_init_ptr_from_cur( ptr->s =3D agf->agf_refcount_root; } =20 -STATIC int64_t +STATIC int xfs_refcountbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) @@ -185,7 +185,7 @@ xfs_refcountbt_cmp_key_with_cur( =20 start =3D xfs_refcount_encode_startblock(irec->rc_startblock, irec->rc_domain); - return (int64_t)be32_to_cpu(kp->rc_startblock) - start; + return cmp_int(be32_to_cpu(kp->rc_startblock), start); } =20 STATIC int diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c index 3cccdb0d0418..bf16aee50d73 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -243,34 +243,18 @@ static inline uint64_t offset_keymask(uint64_t offset) return offset & ~XFS_RMAP_OFF_UNWRITTEN; } =20 -STATIC int64_t +STATIC int xfs_rmapbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { struct xfs_rmap_irec *rec =3D &cur->bc_rec.r; const struct xfs_rmap_key *kp =3D &key->rmap; - __u64 x, y; - int64_t d; - - d =3D (int64_t)be32_to_cpu(kp->rm_startblock) - rec->rm_startblock; - if (d) - return d; =20 - x =3D be64_to_cpu(kp->rm_owner); - y =3D rec->rm_owner; - if (x > y) - return 1; - else if (y > x) - return -1; - - x =3D offset_keymask(be64_to_cpu(kp->rm_offset)); - y =3D offset_keymask(xfs_rmap_irec_offset_pack(rec)); - if (x > y) - return 1; - else if (y > x) - return -1; - return 0; + return cmp_int(be32_to_cpu(kp->rm_startblock), rec->rm_startblock) ?: + cmp_int(be64_to_cpu(kp->rm_owner), rec->rm_owner) ?: + cmp_int(offset_keymask(be64_to_cpu(kp->rm_offset)), + offset_keymask(xfs_rmap_irec_offset_pack(rec))); } =20 STATIC int diff --git a/fs/xfs/libxfs/xfs_rtrefcount_btree.c b/fs/xfs/libxfs/xfs_rtref= count_btree.c index d9f79ae579c6..ac11e94b42ae 100644 --- a/fs/xfs/libxfs/xfs_rtrefcount_btree.c +++ b/fs/xfs/libxfs/xfs_rtrefcount_btree.c @@ -156,7 +156,7 @@ xfs_rtrefcountbt_init_ptr_from_cur( ptr->l =3D 0; } =20 -STATIC int64_t +STATIC int xfs_rtrefcountbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) @@ -167,7 +167,7 @@ xfs_rtrefcountbt_cmp_key_with_cur( =20 start =3D xfs_refcount_encode_startblock(irec->rc_startblock, irec->rc_domain); - return (int64_t)be32_to_cpu(kp->rc_startblock) - start; + return cmp_int(be32_to_cpu(kp->rc_startblock), start); } =20 STATIC int diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_bt= ree.c index 231a189ea2fe..55f903165769 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -185,34 +185,18 @@ static inline uint64_t offset_keymask(uint64_t offset) return offset & ~XFS_RMAP_OFF_UNWRITTEN; } =20 -STATIC int64_t +STATIC int xfs_rtrmapbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { struct xfs_rmap_irec *rec =3D &cur->bc_rec.r; const struct xfs_rmap_key *kp =3D &key->rmap; - __u64 x, y; - int64_t d; - - d =3D (int64_t)be32_to_cpu(kp->rm_startblock) - rec->rm_startblock; - if (d) - return d; =20 - x =3D be64_to_cpu(kp->rm_owner); - y =3D rec->rm_owner; - if (x > y) - return 1; - else if (y > x) - return -1; - - x =3D offset_keymask(be64_to_cpu(kp->rm_offset)); - y =3D offset_keymask(xfs_rmap_irec_offset_pack(rec)); - if (x > y) - return 1; - else if (y > x) - return -1; - return 0; + return cmp_int(be32_to_cpu(kp->rm_startblock), rec->rm_startblock) ?: + cmp_int(be64_to_cpu(kp->rm_owner), rec->rm_owner) ?: + cmp_int(offset_keymask(be64_to_cpu(kp->rm_offset)), + offset_keymask(xfs_rmap_irec_offset_pack(rec))); } =20 STATIC int diff --git a/fs/xfs/scrub/rcbag_btree.c b/fs/xfs/scrub/rcbag_btree.c index 46598817b239..9a4ef823c5a7 100644 --- a/fs/xfs/scrub/rcbag_btree.c +++ b/fs/xfs/scrub/rcbag_btree.c @@ -47,7 +47,7 @@ rcbagbt_init_rec_from_cur( bag_rec->rbg_refcount =3D bag_irec->rbg_refcount; } =20 -STATIC int64_t +STATIC int rcbagbt_cmp_key_with_cur( struct xfs_btree_cur *cur, const union xfs_btree_key *key) @@ -55,17 +55,8 @@ rcbagbt_cmp_key_with_cur( struct rcbag_rec *rec =3D (struct rcbag_rec *)&cur->bc_rec; const struct rcbag_key *kp =3D (const struct rcbag_key *)key; =20 - if (kp->rbg_startblock > rec->rbg_startblock) - return 1; - if (kp->rbg_startblock < rec->rbg_startblock) - return -1; - - if (kp->rbg_blockcount > rec->rbg_blockcount) - return 1; - if (kp->rbg_blockcount < rec->rbg_blockcount) - return -1; - - return 0; + return cmp_int(kp->rbg_startblock, rec->rbg_startblock) ?: + cmp_int(kp->rbg_blockcount, rec->rbg_blockcount); } =20 STATIC int --=20 2.50.0 From nobody Wed Oct 8 04:22:00 2025 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF972253B67; Wed, 2 Jul 2025 09:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449226; cv=none; b=AeCsGBtsmMAnaZ0RyUDWQnw7RRv6nEFUGG5AvyWECqlVjLOTDWMmidiM1TPd4XbkAgL1i9o+36NAxMNLIbN1sG7Dw5MZFc4WLA/r0vRtBO7UtMZ3NU/vc2tt4GuYe2Mn0AR4R0Ane1PTm7+Pnp4l84EeYOXxrYby5wK6LWq4lP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449226; c=relaxed/simple; bh=RQYcNROOPLIn2tNT/r9qUAjCa4QFJ6VeikSfvlUZ3/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kL8vqAFg5Kuiy3RPfw5pToFWGRBPIMVtSKa8s1ZYLIrCp4b54fsrdTURd6UwX5lXNA1vFV6vbZ0JroGd5RBY57qGxXe8p9RmIPvJ20x6K7bnzfauiT7C5/JryOX9oJV1sJmuK64r5cwg3CRnle1g6dCQ8EzZXIWvbYcw2tSYsLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=J3C48x82; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="J3C48x82" Received: from fedora.intra.ispras.ru (unknown [10.10.165.14]) by mail.ispras.ru (Postfix) with ESMTPSA id 571494076B5F; Wed, 2 Jul 2025 09:40:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 571494076B5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1751449214; bh=r6wtu7KOop3pbRUG/1WRnQPZWmDWqzWUwGwr/9/U5+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J3C48x82vr4rytESnJXzvVtg0MehnOtHAzWmmMJs8rFqsbUPDd4OUSGFLITfIdlVf TkVGwbCwYfRc2IVoNMfmtjXsgM9MMI2jIOgbwd/sJMZuPJAfrvadSi1fyLW+y0GO7H SAaolmqrSRSZF9QJr4R4uyjvlJAseC3gMXHWMYUo= From: Fedor Pchelkin To: Carlos Maiolino , "Darrick J. Wong" Cc: Fedor Pchelkin , Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2 5/6] xfs: use a proper variable name and type for storing a comparison result Date: Wed, 2 Jul 2025 12:39:32 +0300 Message-ID: <20250702093935.123798-6-pchelkin@ispras.ru> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702093935.123798-1-pchelkin@ispras.ru> References: <20250702093935.123798-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Perhaps that's just my silly imagination but 'diff' doesn't look good for the name of a variable to hold a result of a three-way-comparison (-1, 0, 1) which is what ->cmp_key_with_cur() does. It implies to contain an actual difference between the two integer variables but that's not true anymore after recent refactoring. Declaring it as int64_t is also misleading now. Plain integer type is more than enough. Found by Linux Verification Center (linuxtesting.org). Signed-off-by: Fedor Pchelkin Reviewed-by: "Darrick J. Wong" --- v2: add R-b fs/xfs/libxfs/xfs_btree.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 99a63a178f25..d3591728998e 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -1985,7 +1985,7 @@ xfs_btree_lookup( int *stat) /* success/failure */ { struct xfs_btree_block *block; /* current btree block */ - int64_t diff; /* difference for the current key */ + int cmp_r; /* current key comparison result */ int error; /* error return value */ int keyno; /* current key number */ int level; /* level in the btree */ @@ -2013,13 +2013,13 @@ xfs_btree_lookup( * on the lookup record, then follow the corresponding block * pointer down to the next level. */ - for (level =3D cur->bc_nlevels - 1, diff =3D 1; level >=3D 0; level--) { + for (level =3D cur->bc_nlevels - 1, cmp_r =3D 1; level >=3D 0; level--) { /* Get the block we need to do the lookup on. */ error =3D xfs_btree_lookup_get_block(cur, level, pp, &block); if (error) goto error0; =20 - if (diff =3D=3D 0) { + if (cmp_r =3D=3D 0) { /* * If we already had a key match at a higher level, we * know we need to use the first entry in this block. @@ -2065,15 +2065,16 @@ xfs_btree_lookup( keyno, block, &key); =20 /* - * Compute difference to get next direction: + * Compute comparison result to get next + * direction: * - less than, move right * - greater than, move left * - equal, we're done */ - diff =3D cur->bc_ops->cmp_key_with_cur(cur, kp); - if (diff < 0) + cmp_r =3D cur->bc_ops->cmp_key_with_cur(cur, kp); + if (cmp_r < 0) low =3D keyno + 1; - else if (diff > 0) + else if (cmp_r > 0) high =3D keyno - 1; else break; @@ -2089,7 +2090,7 @@ xfs_btree_lookup( * If we moved left, need the previous key number, * unless there isn't one. */ - if (diff > 0 && --keyno < 1) + if (cmp_r > 0 && --keyno < 1) keyno =3D 1; pp =3D xfs_btree_ptr_addr(cur, keyno, block); =20 @@ -2102,7 +2103,7 @@ xfs_btree_lookup( } =20 /* Done with the search. See if we need to adjust the results. */ - if (dir !=3D XFS_LOOKUP_LE && diff < 0) { + if (dir !=3D XFS_LOOKUP_LE && cmp_r < 0) { keyno++; /* * If ge search and we went off the end of the block, but it's @@ -2125,14 +2126,14 @@ xfs_btree_lookup( *stat =3D 1; return 0; } - } else if (dir =3D=3D XFS_LOOKUP_LE && diff > 0) + } else if (dir =3D=3D XFS_LOOKUP_LE && cmp_r > 0) keyno--; cur->bc_levels[0].ptr =3D keyno; =20 /* Return if we succeeded or not. */ if (keyno =3D=3D 0 || keyno > xfs_btree_get_numrecs(block)) *stat =3D 0; - else if (dir !=3D XFS_LOOKUP_EQ || diff =3D=3D 0) + else if (dir !=3D XFS_LOOKUP_EQ || cmp_r =3D=3D 0) *stat =3D 1; else *stat =3D 0; --=20 2.50.0 From nobody Wed Oct 8 04:22:00 2025 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE326253B7B; Wed, 2 Jul 2025 09:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449227; cv=none; b=qTN16uUMydAnk2v1EuG5zqll9sE2wJiGcSRH/zAqA4pfqosXU7Qmv75RP1Fw4rcJSmvu7t/XiFwLR3LQ2VoJOUdp0JKg+T625tcUHuoh2TL2W+9tadaN1CNJzKjOz2FV+Syr27VmQxHFo/EsWiRzLy5d+6pnBCcG8ohqStYhHP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751449227; c=relaxed/simple; bh=SWBV92Aw9D0MuSpaoBqozv/60pjWKAg+MXiW9xCAc6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bV/pggfOenwEoFWvcOMXvuKD1oh2nWHldP073fziR3V1v1tP73otHw1XQf4/5Gm7EvlLm7+gPGMHPkAJ4kRUZ7ppb37iXXyttg0jy4paDp7GD997KWhx/CttP1k666XmR6FZFWMMNV616JhW53/d24YO0b46qlqIaVRdpjDisak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=PrMjVQDO; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="PrMjVQDO" Received: from fedora.intra.ispras.ru (unknown [10.10.165.14]) by mail.ispras.ru (Postfix) with ESMTPSA id F0A1F40777A0; Wed, 2 Jul 2025 09:40:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru F0A1F40777A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1751449215; bh=qJ+yQ7bGSosbW+GSIN8nYNUzz74OZS3bFx3ImJMdxjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PrMjVQDOuV6INje+Bv9Z+cGrKOK8S9K8eyZArGjs0VJivj5duZuvSefw9+t4C6GVw Q3gByugtGFN3jiyRiYpDWL1aiZzOQ2n7iEDH2KhIeDsbDjvsHHIeutJ5JmtTu5EKyA PLheMnJmGL/ZeyMdsIMxtIQjhO/3biVkyIkNmm6E= From: Fedor Pchelkin To: Carlos Maiolino , "Darrick J. Wong" Cc: Fedor Pchelkin , Christoph Hellwig , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2 6/6] xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int() Date: Wed, 2 Jul 2025 12:39:33 +0300 Message-ID: <20250702093935.123798-7-pchelkin@ispras.ru> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250702093935.123798-1-pchelkin@ispras.ru> References: <20250702093935.123798-1-pchelkin@ispras.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- v2: rename the "diff_two_ptrs" part (Darrick) 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( } =20 /* 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 =3D=3D 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)); } =20 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); =20 - 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); --=20 2.50.0