]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: use a proper variable name and type for storing a comparison result
authorFedor Pchelkin <pchelkin@ispras.ru>
Wed, 2 Jul 2025 09:39:32 +0000 (12:39 +0300)
committerCarlos Maiolino <cem@kernel.org>
Thu, 24 Jul 2025 15:30:13 +0000 (17:30 +0200)
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>
fs/xfs/libxfs/xfs_btree.c

index 99a63a178f251f0224690c74bb0c9c4d760baa6f..d3591728998e387a6f7930106bc209d131a48940 100644 (file)
@@ -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 = 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.
@@ -2065,15 +2065,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;
@@ -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 = 1;
                        pp = xfs_btree_ptr_addr(cur, keyno, block);
 
@@ -2102,7 +2103,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
@@ -2125,14 +2126,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;