From nobody Fri Oct 10 21:10:43 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 555EF1F92E; Thu, 12 Jun 2025 10:25: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=1749723928; cv=none; b=p1xikMjNtZKmt8Mp2hZuDHsXbON7UHkNtb8fOwp4cN+QMFbyhXheF74NUa1GUERY1Y/uSBCHSVzV+edjl3oRjB7fmx1DqUpxv1rmCdGwoGdk/KcLAzDIwbQejw2X8pVpL7HKCRUKEHe+9v8anmT5S57hHosutm2PvivX/AV5FGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749723928; c=relaxed/simple; bh=VONAksVjcSO2s2yj8Zp764n0sujrMwWVxwCoqAbUey0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hIZR675w2pJrnYhThsqAn7xSd4vEkZyOCPCIX0qi4EigMpk8PyXCdg6BNPDvrpplk2zAzBe9Mur5iBqFcXhLSUiv/SFtoIvjE4gkeiGfuP+P/QqMNvnJm3RIb82XQuL2dWwM0Tb98ChQZ6X9dDJd3fZ1Wx/02iBmZZcznk9Z3EQ= 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=hrrorbEs; 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="hrrorbEs" Received: from fedora.intra.ispras.ru (unknown [10.10.165.6]) by mail.ispras.ru (Postfix) with ESMTPSA id E5778552F556; Thu, 12 Jun 2025 10:25:22 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru E5778552F556 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1749723923; bh=uB8s/TKRC+X6h2ermWN9k7gOsdkkqDl0MQCvqPkW/g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hrrorbEszFJAGmwDVR27MqFagABSGbWrEfroH2kRtPw7PEvPsXeGCHCkLwxG1CkIG sMe4qtz84y6MlIowMehSz6xZhKX1Z8H3zlg2wFUaf+IbKmbWMTWNmF7iw59QiHs2Pg wnNnYKIAO5AFpth83JvjT5o79FoHGsANp5LK9LhE= 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 1/6] xfs: rename diff_two_keys routines Date: Thu, 12 Jun 2025 13:24:45 +0300 Message-ID: <20250612102455.63024-2-pchelkin@ispras.ru> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250612102455.63024-1-pchelkin@ispras.ru> References: <20250612102455.63024-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" --- 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.49.0 From nobody Fri Oct 10 21:10:43 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 5585522423F; Thu, 12 Jun 2025 10:25:26 +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=1749723930; cv=none; b=A8PJQRQxqF4qFTG4Lf+z+sg8a3J55nTVrIMsY5ULgyWaWqY3Skd221DWSljl5wzj5qU0schhh5sdsxKjDT8HpXds8Ud/6LnNRjMrrdW/5aujylP+cv+UCUZD3cnfME95qsUltke7zci9hFPMXNUbFHENnP7BWLvw+drNSA3WAjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749723930; c=relaxed/simple; bh=9CnsJhrfbndRsgnhtB971HFRWQanRxUlBRHvmhrZ3DM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Auc6aKtWY3EvlelNi/EP5Zq5Iwfu09qUXPexf9V9SeGrFE8UA52NBLc93ykLBXqd9qA/dvXTLD99Bf0njRU/9DSg2+r/znhYsPFHwNgwmIJSqSa+NqPhrGhK5UXk/gwUA750d0EYc9sDOOqqmphP2H10UwT6nT+t1D0paklQKIM= 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=PE2VutnK; 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="PE2VutnK" Received: from fedora.intra.ispras.ru (unknown [10.10.165.6]) by mail.ispras.ru (Postfix) with ESMTPSA id AEACB40158F5; Thu, 12 Jun 2025 10:25:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru AEACB40158F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1749723923; bh=1GvrzvmxUXP7LyGCjeE5jq8DK4hB08/BY64fUOGZt9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PE2VutnKc5NKiV86urW9+Wy92X4RaWK1G7sg45fNF1xmOFv09SyukRK48uMZFyfRH TGTg6vzO6bT85AThpKiiuUxmwkYX5x367gy031iV8Z6mO1sqhF4A1cdrak8mofuj0c LLcKDAR/BQOnem7n374GZfNPrS1dp/MnJ1IHLzSE= 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 2/6] xfs: rename key_diff routines Date: Thu, 12 Jun 2025 13:24:46 +0300 Message-ID: <20250612102455.63024-3-pchelkin@ispras.ru> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250612102455.63024-1-pchelkin@ispras.ru> References: <20250612102455.63024-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" --- 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.49.0 From nobody Fri Oct 10 21:10:43 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 EA136224B07; Thu, 12 Jun 2025 10:25:26 +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=1749723930; cv=none; b=GvUc/SrFqRFS7zzV83fU7G5Vh/PILiO8cDt0a+Din5+/nMb3sSwWH0foAjrRfOuMO1vVVHLrMf3eo2nrF56Da+fG98Qn/gbpDJOGIZzKl/N3kvAmI6MoYWF3szhs4r1u4lkSwMWn4Z1h76q4s4D7m7WbjrFdqwBlLtqk0idfdHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749723930; c=relaxed/simple; bh=2lK/64Bs6RHYi29PgH5zwzI3VqPLMd3FFOWuddDRHEk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y1o7b6U0Vism7x0owLO/vFBpV1eqAJnES+O0EiG6l52Ptf4rrvOApNr/e9W7cwJ6PtCQt/kPJGNLw3QyQ4vkPzLc/p/Os+eKxVaCnLXt3on63i3nCuXqqBMjgUgRG0iJaJt+wMQjAuGgQJBAu6j9g4sBfqirbfJzDVRufzjqeXc= 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=h+GR6OIA; 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="h+GR6OIA" Received: from fedora.intra.ispras.ru (unknown [10.10.165.6]) by mail.ispras.ru (Postfix) with ESMTPSA id 5797440737BF; Thu, 12 Jun 2025 10:25:24 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 5797440737BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1749723924; bh=q+iKj53AzjlvGfyIVOde9/3PywjPjxXpkwx68LAPouo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h+GR6OIAKzYAhOORaHx9De22KMRmf2zAWeovQ5lhUNWKMiAS8kf9kInl1t7lvxPAZ qEGHRWpl+TBNNSBNg+0QxWOvSSFPno6wTfZaKndzHHyyMYL6e725WxJ42TlJ1+DNW+ GmbfYz6SLJR3NsYXQd4v0+mjC/FdHlcNPkpYrPHw= 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 3/6] xfs: refactor cmp_two_keys routines to take advantage of cmp_int() Date: Thu, 12 Jun 2025 13:24:47 +0300 Message-ID: <20250612102455.63024-4-pchelkin@ispras.ru> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250612102455.63024-1-pchelkin@ispras.ru> References: <20250612102455.63024-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" --- 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.49.0 From nobody Fri Oct 10 21:10:43 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 EA0CB1C32FF; Thu, 12 Jun 2025 10:25:26 +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=1749723929; cv=none; b=biC+DSOxiVG9QnSqzkZm1SNNBVg/jlXJvkdEmmJeTeqvfE5RbRgnqO6p03TWKmt+bShZyke7zW/EixRWHl98six8MsLJBO4qN4qmyDc1daGYSlpTrypHAc/vm4vs4XjJvg4BaOispsrKM55tTbHC/vWD+7P3DsBaj07Dgmi3ziw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749723929; c=relaxed/simple; bh=8voO2mOf/c8Uy8iuxSiWobrz/7hPMbrqmEbU1cIFsmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ffoNZ+GBbf7MfiId5D/f1H1D9KNPLVzJVXvrOiWb8l1K618f0i5b4kpsPWpesp4EmCdrWrr5DJ2WbZRK88BxNziuEzNsByqRhQ1NR39D1cw7wlo64mzPwwLXWIkt7LXwQYhRWOE+tsHZMkOAzWhmSaYAgce7t8YTTDRzHO2gA08= 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=XFTfe5IP; 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="XFTfe5IP" Received: from fedora.intra.ispras.ru (unknown [10.10.165.6]) by mail.ispras.ru (Postfix) with ESMTPSA id EB46F40737C3; Thu, 12 Jun 2025 10:25:24 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru EB46F40737C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1749723925; bh=f/V6lTWeM8h4Rn8orKvo94b8cHJt/QGhZ2c0fxjXVAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFTfe5IPZJtJ+z8CxFnvi0NdDbe0LHbPyw0tWlPhVdj5TLIW1NkEs4rKo+IZ9l66L KE8sGocpTOA4BVBsn5ICMHrL+JooAaC7uG/Mgt5wKfm8ywysVuPc2rNVhZt+azPwXf J9/FnYTjAlvNSHdDVcysDuaIM6TDcY8GMfb9iOaU= 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 4/6] xfs: refactor cmp_key_with_cur routines to take advantage of cmp_int() Date: Thu, 12 Jun 2025 13:24:48 +0300 Message-ID: <20250612102455.63024-5-pchelkin@ispras.ru> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250612102455.63024-1-pchelkin@ispras.ru> References: <20250612102455.63024-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" --- 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.49.0 From nobody Fri Oct 10 21:10:43 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 D33A1238C33; Thu, 12 Jun 2025 10:25:30 +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=1749723932; cv=none; b=QfpLJHB6XsUybCSZzM78x2gC7RN1h7Zkuj0OmXpbnW/cVqfBIB6e3GmUHXr/xTNqg1JF6uwkLYm7nh97vfto/5U/hWQmlEimWUb757RoOBrmh77lPuluEYmbepewfjyhA3WUwvK/PkqjC/RUtuoS2AS/5svgTCLo9EQP6CzyLpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749723932; c=relaxed/simple; bh=Z6Zj5KmS7FYcgL2YQL7XN//TXTmPNWqFxAWqJ56HrJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nh9Bv/fsVaPSiYRDdAXy0wQFMW+8sn1euajHID87xprkFyUw4ijBjJZjjJ2o23Ne2/Ul6TBlRYnyaETMU3bwk7fxDGjvmKwOP3z0eTPUbGHHCtzhtSaqPYVKfZFYpuOdoGbOCAysc6rozCLEdO3mOq8c117s/MTuPqkj16snbkw= 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=DvvSd8ON; 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="DvvSd8ON" Received: from fedora.intra.ispras.ru (unknown [10.10.165.6]) by mail.ispras.ru (Postfix) with ESMTPSA id 8F33740737CA; Thu, 12 Jun 2025 10:25:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 8F33740737CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1749723925; bh=dCiG/QgCfIturXXE3DzMWFbuSnrkLz750v8RopG6ABE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DvvSd8ONWB/dyBYsQ7zVHC592mF5l62titYB+FbwziPTpzUYhBEQYYncR6NQWcMej 222ik8Jlkaj6uNLZbIWWPTXE5q+zDxgL8c0FCSbNcF3YTFQ3c0uawjqim2jhiif0NW 9yhcJnTncqyct/0UBL1HDjcqmJZBntdyGplap1go= 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 5/6] xfs: use a proper variable name and type for storing a comparison result Date: Thu, 12 Jun 2025 13:24:49 +0300 Message-ID: <20250612102455.63024-6-pchelkin@ispras.ru> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250612102455.63024-1-pchelkin@ispras.ru> References: <20250612102455.63024-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" --- 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.49.0 From nobody Fri Oct 10 21:10:43 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 A3A15238176; Thu, 12 Jun 2025 10:25:30 +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=1749723932; cv=none; b=O8xtVQ6Lo92OX7lkENlwHsXCQ6LnCYIPDtACy2fguCfsuG+WL6hI3H/Wh8wcczhISsMu0JuxqHTsNzlw38qkVprQEEQ0x9RpqVABAWHs+AW43fFjsh7T5SOT73XGFCakq1+jzxNHnXC8WApoI9jI4nQ+tRR0e/zEzlPy/AfgDjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749723932; c=relaxed/simple; bh=IL/Ee0kDLb8vKxIQmMw05p8FdmrpU4ne3hnvCI1+tys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lWVHtq3qPPubjycnDvpzNg2EUugEINbI99v71Cb1h+TUADhrlPkGtgDOglbtGB8NZAIHHkM+r+nTy9CNhCnzB7GILvZNVR2GmIKZYwV3oBQIpTXif3w7uVtBK9t6ewLmA1zv532m/0NAEFLieJ17VcdsEyFdNf3xMn+9ULGPj2w= 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=Omfq8Zw3; 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="Omfq8Zw3" Received: from fedora.intra.ispras.ru (unknown [10.10.165.6]) by mail.ispras.ru (Postfix) with ESMTPSA id 39F7F40737D7; Thu, 12 Jun 2025 10:25:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 39F7F40737D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1749723926; bh=PF768aoX4r6yIrDUHf+haREU0cDIObqduX7ooUbbWAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Omfq8Zw32u6QjraRHp/3OS6OO0Dxhf0Sa4NeamJ+9oYx9eHyQG208M+zBiRsfhKv+ mRB97JkSyhVBnDm9Ozd3Y6ProVBNRjbbQ8zcDgAv1LiNZ0L0iRxAYTLC+vd203jYVL /Sl7huHw7cP64zYs/MNk44O/F4xltwmypyvkEp3U= 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 6/6] xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int() Date: Thu, 12 Jun 2025 13:24:50 +0300 Message-ID: <20250612102455.63024-7-pchelkin@ispras.ru> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250612102455.63024-1-pchelkin@ispras.ru> References: <20250612102455.63024-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. Found by Linux Verification Center (linuxtesting.org). Signed-off-by: Fedor Pchelkin Reviewed-by: "Darrick J. Wong" --- fs/xfs/libxfs/xfs_btree.c | 6 +++--- fs/xfs/libxfs/xfs_btree.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index d3591728998e..9a227b6b3296 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 +int xfs_btree_diff_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..23598f287af5 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_diff_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); --=20 2.49.0