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 <abaci@linux.alibaba.com> Reported-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11531 Link: https://lore.kernel.org/r/20241025081455.55089-1-jiapeng.chong@linux.alibaba.com [1] Acked-by: Waiman Long <longman@redhat.com> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20240731135850.81018-2-thorsten.blum@toblux.com
1 parent 63a4818 commit 0d3547d

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

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)