From: Paul Dolan <paul.dolan.dev@gmail.com>
To: Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] selftests/exec: reject zero as power-of-two alignment
Date: Fri, 4 Sep 2026 16:40:57 +0100 [thread overview]
Message-ID: <20260904154057.160753-1-paul.dolan.dev@gmail.com> (raw)
The load_address test reports whether an alignment was found separately
from whether that alignment is a power of two. However, the usual
x & (x - 1) check also evaluates to zero when x is zero, causing a
missing alignment to be reported as a power of two.
Require the alignment to be non-zero when reporting the power-of-two
result.
Fixes: b57a2907c9d9 ("selftests/exec: Build both static and non-static load_address tests")
Signed-off-by: Paul Dolan <paul.dolan.dev@gmail.com>
---
tools/testing/selftests/exec/load_address.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/exec/load_address.c b/tools/testing/selftests/exec/load_address.c
index 55fd3732f029..e279d85e8f19 100644
--- a/tools/testing/selftests/exec/load_address.c
+++ b/tools/testing/selftests/exec/load_address.c
@@ -92,9 +92,10 @@ int main(int argc, char **argv)
/* Is the alignment sane? */
pow2 = extracted.alignment & (extracted.alignment - 1);
- ksft_test_result(pow2 == 0,
- "Alignment is%s a power of 2: %#llx\n",
- pow2 == 0 ? "" : " NOT", extracted.alignment);
+ ksft_test_result(extracted.alignment != 0 && pow2 == 0,
+ "Alignment is%s a power of 2: %#llx\n",
+ extracted.alignment != 0 && pow2 == 0 ? "" : " NOT",
+ extracted.alignment);
/* Is the load address aligned? */
misalign = extracted.load_address & (extracted.alignment - 1);
--
2.55.0
reply other threads:[~2026-09-04 15:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260904154057.160753-1-paul.dolan.dev@gmail.com \
--to=paul.dolan.dev@gmail.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®