Skip to content

Commit 0d3547d

Browse files
tobluxfbq
authored andcommitted
locking/ww_mutex/test: Use swap() macro
Fixes the following Coccinelle/coccicheck warning reported by swap.cocci: WARNING opportunity for swap() Compile-tested only. [Boqun: Add the report tags from Jiapeng and Abaci Robot [1].] Reported-by: Abaci Robot <[email protected]> Reported-by: Jiapeng Chong <[email protected]> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11531 Link: https://lore.kernel.org/r/[email protected] [1] Acked-by: Waiman Long <[email protected]> Signed-off-by: Thorsten Blum <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 63a4818 commit 0d3547d

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

kernel/locking/test-ww_mutex.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static inline u32 prandom_u32_below(u32 ceil)
404404
static int *get_random_order(int count)
405405
{
406406
int *order;
407-
int n, r, tmp;
407+
int n, r;
408408

409409
order = kmalloc_array(count, sizeof(*order), GFP_KERNEL);
410410
if (!order)
@@ -415,11 +415,8 @@ static int *get_random_order(int count)
415415

416416
for (n = count - 1; n > 1; n--) {
417417
r = prandom_u32_below(n + 1);
418-
if (r != n) {
419-
tmp = order[n];
420-
order[n] = order[r];
421-
order[r] = tmp;
422-
}
418+
if (r != n)
419+
swap(order[n], order[r]);
423420
}
424421

425422
return order;

0 commit comments

Comments
 (0)