mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gcc-plugins: Use swap() to simplify code
@ 2025-08-06 12:43 Liao Yuanhong
  2025-08-07  4:45 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Liao Yuanhong @ 2025-08-06 12:43 UTC (permalink / raw)
  To: Kees Cook, open list:GCC PLUGINS, open list; +Cc: liaoyuanhong

Replace the original swapping logic with swap() to improve readability and
remove temporary variables

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 scripts/gcc-plugins/randomize_layout_plugin.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
index ff65a4f87f24..5d6ebe292cbf 100644
--- a/scripts/gcc-plugins/randomize_layout_plugin.c
+++ b/scripts/gcc-plugins/randomize_layout_plugin.c
@@ -199,17 +199,12 @@ static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prn
 
 	/* FIXME: this group shuffle is currently a no-op. */
 	for (i = num_groups - 1; i > 0; i--) {
-		struct partition_group tmp;
 		randnum = ranval(prng_state) % (i + 1);
-		tmp = size_group[i];
-		size_group[i] = size_group[randnum];
-		size_group[randnum] = tmp;
+		swap(size_group[randnum], size_group[i]);
 	}
 
 	for (x = 0; x < num_groups; x++) {
 		for (index = size_group[x].length - 1; index > 0; index--) {
-			tree tmp;
-
 			i = size_group[x].start + index;
 			if (DECL_BIT_FIELD_TYPE(newtree[i]))
 				continue;
@@ -218,9 +213,7 @@ static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prn
 			// we could handle this case differently if desired
 			if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
 				continue;
-			tmp = newtree[i];
-			newtree[i] = newtree[randnum];
-			newtree[randnum] = tmp;
+			swap(newtree[randnum], newtree[i]);
 		}
 	}
 }
@@ -230,11 +223,8 @@ static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state
 	unsigned long i, randnum;
 
 	for (i = length - 1; i > 0; i--) {
-		tree tmp;
 		randnum = ranval(prng_state) % (i + 1);
-		tmp = newtree[i];
-		newtree[i] = newtree[randnum];
-		newtree[randnum] = tmp;
+		swap(newtree[randnum], newtree[i]);
 	}
 }
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-07  4:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-06 12:43 [PATCH] gcc-plugins: Use swap() to simplify code Liao Yuanhong
2025-08-07  4:45 ` kernel test robot

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®