]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: use a proper variable name and type for storing a comparison result
authorFedor Pchelkin <pchelkin@ispras.ru>
Mon, 6 Oct 2025 12:40:16 +0000 (14:40 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 13 Oct 2025 09:53:39 +0000 (11:53 +0200)
Source kernel commit: 2717eb35185581988799bb0d5179409978f36a90

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 <pchelkin@ispras.ru>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
libxfs/xfs_btree.c

index 15846f0ff694dbf8b7408a16d88b803935b9dc28..facc35401f5d2e5af6d18917e9748d06eda64290 100644 (file)
@@ -1982,7 +1982,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 */
@@ -2010,13 +2010,13 @@ xfs_btree_lookup(
         * on the lookup record, then follow the corresponding block
         * pointer down to the next level.
         */
-       for (level = cur->bc_nlevels - 1, diff = 1; level >= 0; level--) {
+       for (level = cur->bc_nlevels - 1, cmp_r = 1; level >= 0; level--) {
                /* Get the block we need to do the lookup on. */
                error = xfs_btree_lookup_get_block(cur, level, pp, &block);
                if (error)
                        goto error0;
 
-               if (diff == 0) {
+               if (cmp_r == 0) {
                        /*
                         * If we already had a key match at a higher level, we
                         * know we need to use the first entry in this block.
@@ -2062,15 +2062,16 @@ xfs_btree_lookup(
                                                keyno, block, &key);
 
                                /*
-                                * 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 = cur->bc_ops->cmp_key_with_cur(cur, kp);
-                               if (diff < 0)
+                               cmp_r = cur->bc_ops->cmp_key_with_cur(cur, kp);
+                               if (cmp_r < 0)
                                        low = keyno + 1;
-                               else if (diff > 0)
+                               else if (cmp_r > 0)
                                        high = keyno - 1;
                                else
                                        break;
@@ -2086,7 +2087,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 = 1;
                        pp = xfs_btree_ptr_addr(cur, keyno, block);
 
@@ -2099,7 +2100,7 @@ xfs_btree_lookup(
        }
 
        /* Done with the search. See if we need to adjust the results. */
-       if (dir != XFS_LOOKUP_LE && diff < 0) {
+       if (dir != XFS_LOOKUP_LE && cmp_r < 0) {
                keyno++;
                /*
                 * If ge search and we went off the end of the block, but it's
@@ -2122,14 +2123,14 @@ xfs_btree_lookup(
                        *stat = 1;
                        return 0;
                }
-       } else if (dir == XFS_LOOKUP_LE && diff > 0)
+       } else if (dir == XFS_LOOKUP_LE && cmp_r > 0)
                keyno--;
        cur->bc_levels[0].ptr = keyno;
 
        /* Return if we succeeded or not. */
        if (keyno == 0 || keyno > xfs_btree_get_numrecs(block))
                *stat = 0;
-       else if (dir != XFS_LOOKUP_EQ || diff == 0)
+       else if (dir != XFS_LOOKUP_EQ || cmp_r == 0)
                *stat = 1;
        else
                *stat = 0;