[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20211110060015.137121-1-chi.minghao@zte.com.cn>
Date: Wed, 10 Nov 2021 06:00:15 +0000
From: cgel.zte@...il.com
To: peterz@...radead.org
Cc: mingo@...hat.com, will@...nel.org, longman@...hat.com,
boqun.feng@...il.com, linux-kernel@...r.kernel.org,
chiminghao <chi.minghao@....com.cn>,
Zeal Robot <zealci@....com.cn>
Subject: [PATCH] kernel:locking: use swap() to make code cleaner
From: chiminghao <chi.minghao@....com.cn>
Fix the following coccicheck REVIEW:
Use swap() instead of reimplementing it.
Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: chiminghao <chi.minghao@....com.cn>
---
kernel/locking/test-ww_mutex.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index 353004155d65..fa021b8a9edc 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -389,7 +389,7 @@ struct stress {
static int *get_random_order(int count)
{
int *order;
- int n, r, tmp;
+ int n, r;
order = kmalloc_array(count, sizeof(*order), GFP_KERNEL);
if (!order)
@@ -400,11 +400,8 @@ static int *get_random_order(int count)
for (n = count - 1; n > 1; n--) {
r = get_random_int() % (n + 1);
- if (r != n) {
- tmp = order[n];
- order[n] = order[r];
- order[r] = tmp;
- }
+ if (r != n)
+ swap(order[n], order[r]);
}
return order;
--
2.25.1
Powered by blists - more mailing lists