lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241025081455.55089-1-jiapeng.chong@linux.alibaba.com>
Date: Fri, 25 Oct 2024 16:14:55 +0800
From: Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>
To: peterz@...radead.org
Cc: mingo@...hat.com,
	will@...nel.org,
	longman@...hat.com,
	boqun.feng@...il.com,
	linux-kernel@...r.kernel.org,
	Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>,
	Abaci Robot <abaci@...ux.alibaba.com>
Subject: [PATCH -next] locking/ww_mutex: use swap() in get_random_order()

Use existing swap() function rather than duplicating its implementation.

./kernel/locking/test-ww_mutex.c:420:22-23: WARNING opportunity for swap().

Reported-by: Abaci Robot <abaci@...ux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11531
Signed-off-by: Jiapeng Chong <jiapeng.chong@...ux.alibaba.com>
---
 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 5d58b2c0ef98..bcb1b9fea588 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -404,7 +404,7 @@ static inline u32 prandom_u32_below(u32 ceil)
 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)
@@ -415,11 +415,8 @@ static int *get_random_order(int count)
 
 	for (n = count - 1; n > 1; n--) {
 		r = prandom_u32_below(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.32.0.3.g01195cf9f


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ