[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250806124341.382446-1-liaoyuanhong@vivo.com>
Date: Wed, 6 Aug 2025 20:43:41 +0800
From: Liao Yuanhong <liaoyuanhong@...o.com>
To: Kees Cook <kees@...nel.org>,
linux-hardening@...r.kernel.org (open list:GCC PLUGINS),
linux-kernel@...r.kernel.org (open list)
Cc: liaoyuanhong@...o.com
Subject: [PATCH] gcc-plugins: Use swap() to simplify code
Replace the original swapping logic with swap() to improve readability and
remove temporary variables
Signed-off-by: Liao Yuanhong <liaoyuanhong@...o.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
Powered by blists - more mailing lists