* [PATCH -next] locking/ww_mutex: use swap() in get_random_order()
@ 2024-10-25 8:14 Jiapeng Chong
2024-10-25 16:23 ` Boqun Feng
0 siblings, 1 reply; 2+ messages in thread
From: Jiapeng Chong @ 2024-10-25 8:14 UTC (permalink / raw)
To: peterz
Cc: mingo, will, longman, boqun.feng, linux-kernel, Jiapeng Chong,
Abaci Robot
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@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11531
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH -next] locking/ww_mutex: use swap() in get_random_order()
2024-10-25 8:14 [PATCH -next] locking/ww_mutex: use swap() in get_random_order() Jiapeng Chong
@ 2024-10-25 16:23 ` Boqun Feng
0 siblings, 0 replies; 2+ messages in thread
From: Boqun Feng @ 2024-10-25 16:23 UTC (permalink / raw)
To: Jiapeng Chong; +Cc: peterz, mingo, will, longman, linux-kernel, Abaci Robot
On Fri, Oct 25, 2024 at 04:14:55PM +0800, Jiapeng Chong wrote:
> 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@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11531
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Thanks for the patch. However, I think Thorsten Blum beat you to it [1].
Would it be Ok if I queue that patch with you as a Reported-by (plus
the other Reported-by tag and Close tag)?
[1]: https://lore.kernel.org/r/20240731135850.81018-2-thorsten.blum@toblux.com
Regards,
Boqun
> ---
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-25 16:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-25 8:14 [PATCH -next] locking/ww_mutex: use swap() in get_random_order() Jiapeng Chong
2024-10-25 16:23 ` Boqun Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®