Skip to contentSkip to conversation

lib/test_vmalloc.c: use swap() to make code cleaner

PATCH Applied [email protected] 2 participants 2 messages Oct 28, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/test_vmalloc.c: use swap() to make code cleaner

From: Changcheng Deng <[email protected]>

Use swap() in order to make code cleaner. Issue found by coccinelle.

---
 lib/test_vmalloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/test_vmalloc.c +2 -4
index e14993bc84d2..cf41fd6df42a 100644
@@ -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]);
 	}
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 36 lines · On Thu, Oct 28, 2021 at 11:14:43AM +0000, [email protected] wrote:

From: Changcheng Deng <[email protected]>

Use swap() in order to make code cleaner. Issue found by coccinelle.

---
 lib/test_vmalloc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/test_vmalloc.c +2 -4
index e14993bc84d2..cf41fd6df42a 100644
@@ -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]);
 	}
 }
 
Signature · 1 line
2.25.1

Makes sense to me: Reviewed-by: Uladzislau Rezki (Sony) <[email protected]>

--
Vlad Rezki