* [PATCH] lib/test_vmalloc.c: use swap() to make code cleaner
@ 2021-10-28 11:14 cgel.zte
2021-10-28 12:02 ` Uladzislau Rezki
0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2021-10-28 11:14 UTC (permalink / raw)
To: akpm; +Cc: urezki, deng.changcheng, linux-kernel, Zeal Robot
From: Changcheng Deng <deng.changcheng@zte.com.cn>
Use swap() in order to make code cleaner. Issue found by coccinelle.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
---
lib/test_vmalloc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c
index e14993bc84d2..cf41fd6df42a 100644
--- a/lib/test_vmalloc.c
+++ b/lib/test_vmalloc.c
@@ -393,7 +393,7 @@ static struct test_driver {
static void shuffle_array(int *arr, int n)
{
unsigned int rnd;
- int i, j, x;
+ int i, j;
for (i = n - 1; i > 0; i--) {
get_random_bytes(&rnd, sizeof(rnd));
@@ -402,9 +402,7 @@ static void shuffle_array(int *arr, int n)
j = rnd % i;
/* Swap indexes. */
- x = arr[i];
- arr[i] = arr[j];
- arr[j] = x;
+ swap(arr[i], arr[j]);
}
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lib/test_vmalloc.c: use swap() to make code cleaner
2021-10-28 11:14 [PATCH] lib/test_vmalloc.c: use swap() to make code cleaner cgel.zte
@ 2021-10-28 12:02 ` Uladzislau Rezki
0 siblings, 0 replies; 3+ messages in thread
From: Uladzislau Rezki @ 2021-10-28 12:02 UTC (permalink / raw)
To: cgel.zte; +Cc: akpm, urezki, deng.changcheng, linux-kernel, Zeal Robot
On Thu, Oct 28, 2021 at 11:14:43AM +0000, cgel.zte@gmail.com wrote:
> From: Changcheng Deng <deng.changcheng@zte.com.cn>
>
> Use swap() in order to make code cleaner. Issue found by coccinelle.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Changcheng Deng <deng.changcheng@zte.com.cn>
> ---
> lib/test_vmalloc.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c
> index e14993bc84d2..cf41fd6df42a 100644
> --- a/lib/test_vmalloc.c
> +++ b/lib/test_vmalloc.c
> @@ -393,7 +393,7 @@ static struct test_driver {
> static void shuffle_array(int *arr, int n)
> {
> unsigned int rnd;
> - int i, j, x;
> + int i, j;
>
> for (i = n - 1; i > 0; i--) {
> get_random_bytes(&rnd, sizeof(rnd));
> @@ -402,9 +402,7 @@ static void shuffle_array(int *arr, int n)
> j = rnd % i;
>
> /* Swap indexes. */
> - x = arr[i];
> - arr[i] = arr[j];
> - arr[j] = x;
> + swap(arr[i], arr[j]);
> }
> }
>
> --
> 2.25.1
Makes sense to me: Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
--
Vlad Rezki
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] lib/test_vmalloc.c: use swap() to make code cleaner
@ 2021-11-04 1:16 davidcomponentone
0 siblings, 0 replies; 3+ messages in thread
From: davidcomponentone @ 2021-11-04 1:16 UTC (permalink / raw)
To: urezki; +Cc: davidcomponentone, akpm, yang.guang5, linux-kernel, Zeal Robot
From: Yang Guang <yang.guang5@zte.com.cn>
Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid
opencoding it.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
lib/test_vmalloc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c
index e14993bc84d2..cf41fd6df42a 100644
--- a/lib/test_vmalloc.c
+++ b/lib/test_vmalloc.c
@@ -393,7 +393,7 @@ static struct test_driver {
static void shuffle_array(int *arr, int n)
{
unsigned int rnd;
- int i, j, x;
+ int i, j;
for (i = n - 1; i > 0; i--) {
get_random_bytes(&rnd, sizeof(rnd));
@@ -402,9 +402,7 @@ static void shuffle_array(int *arr, int n)
j = rnd % i;
/* Swap indexes. */
- x = arr[i];
- arr[i] = arr[j];
- arr[j] = x;
+ swap(arr[i], arr[j]);
}
}
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-04 1:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28 11:14 [PATCH] lib/test_vmalloc.c: use swap() to make code cleaner cgel.zte
2021-10-28 12:02 ` Uladzislau Rezki
2021-11-04 1:16 davidcomponentone
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.