Commit 2717eb35 authored by Fedor Pchelkin's avatar Fedor Pchelkin Committed by Carlos Maiolino
Browse files

xfs: use a proper variable name and type for storing a comparison result



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: default avatarFedor Pchelkin <pchelkin@ispras.ru>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarCarlos Maiolino <cem@kernel.org>
parent 734b871d
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -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;