stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Thorsten Blum <thorsten.blum@toblux.com>,
	Abaci Robot <abaci@linux.alibaba.com>,
	Jiapeng Chong <jiapeng.chong@linux.alibaba.com>,
	Waiman Long <longman@redhat.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Sasha Levin <sashal@kernel.org>,
	peterz@infradead.org, mingo@redhat.com, will@kernel.org
Subject: [PATCH AUTOSEL 6.13 5/7] locking/ww_mutex/test: Use swap() macro
Date: Sun, 26 Jan 2025 09:50:08 -0500	[thread overview]
Message-ID: <20250126145011.925720-5-sashal@kernel.org> (raw)
In-Reply-To: <20250126145011.925720-1-sashal@kernel.org>

From: Thorsten Blum <thorsten.blum@toblux.com>

[ Upstream commit 0d3547df6934b8f9600630322799a2a76b4567d8 ]

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
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 5d58b2c0ef98b..bcb1b9fea5880 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.39.5


  parent reply	other threads:[~2025-01-26 14:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-26 14:50 [PATCH AUTOSEL 6.13 1/7] sched: Don't try to catch up excess steal time Sasha Levin
2025-01-26 14:50 ` [PATCH AUTOSEL 6.13 2/7] sched/deadline: Correctly account for allocated bandwidth during hotplug Sasha Levin
2025-01-26 14:50 ` [PATCH AUTOSEL 6.13 3/7] sched/deadline: Check bandwidth overflow earlier for hotplug Sasha Levin
2025-01-26 14:50 ` [PATCH AUTOSEL 6.13 4/7] x86: Convert unreachable() to BUG() Sasha Levin
2025-01-26 14:50 ` Sasha Levin [this message]
2025-01-26 14:50 ` [PATCH AUTOSEL 6.13 6/7] lockdep: Fix upper limit for LOCKDEP_*_BITS configs Sasha Levin
2025-01-26 14:50 ` [PATCH AUTOSEL 6.13 7/7] x86/amd_nb: Restrict init function to AMD-based systems Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250126145011.925720-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=abaci@linux.alibaba.com \
    --cc=boqun.feng@gmail.com \
    --cc=jiapeng.chong@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=thorsten.blum@toblux.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).