From: Charlie Jenkins <thecharlesjenkins@gmail.com>
EXPECT_EQ() expands to multiple lines, breaking up one-line if
statements. This issue was not present in the patch on the mailing list
but was instead introduced by the maintainer when attempting to fix up
checkpatch warnings. Add braces around EXPECT_EQ() to avoid the error
even though checkpatch suggests them to be removed:
validate_v_ptrace.c:626:17: error: ‘else’ without a previous ‘if’
Fixes: 3789d5eecd5a ("selftests: riscv: verify syscalls discard vector context")
Fixes: 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")
Fixes: 849f05ae1ea6 ("selftests: riscv: verify ptrace accepts valid vector csr values")
Signed-off-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
---
tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
index 257de36274e9..5724e6eb3309 100644
--- a/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
+++ b/tools/testing/selftests/riscv/vector/validate_v_ptrace.c
@@ -291,10 +291,11 @@ TEST(ptrace_v_syscall_clobbering)
/* verify initial vsetvli settings */
- if (is_xtheadvector_supported())
+ if (is_xtheadvector_supported()) {
EXPECT_EQ(5UL, regset_data->vtype);
- else
+ } else {
EXPECT_EQ(9UL, regset_data->vtype);
+ }
EXPECT_EQ(regset_data->vlenb, regset_data->vl);
EXPECT_EQ(vlenb, regset_data->vlenb);
@@ -620,10 +621,11 @@ TEST_F(v_csr_invalid, ptrace_v_invalid_values)
/* verify initial vsetvli settings */
- if (is_xtheadvector_supported())
+ if (is_xtheadvector_supported()) {
EXPECT_EQ(5UL, regset_data->vtype);
- else
+ } else {
EXPECT_EQ(9UL, regset_data->vtype);
+ }
EXPECT_EQ(regset_data->vlenb, regset_data->vl);
EXPECT_EQ(vlenb, regset_data->vlenb);
@@ -828,10 +830,11 @@ TEST_F(v_csr_valid, ptrace_v_valid_values)
/* verify initial vsetvli settings */
- if (is_xtheadvector_supported())
+ if (is_xtheadvector_supported()) {
EXPECT_EQ(5UL, regset_data->vtype);
- else
+ } else {
EXPECT_EQ(9UL, regset_data->vtype);
+ }
EXPECT_EQ(regset_data->vlenb, regset_data->vl);
EXPECT_EQ(vlenb, regset_data->vlenb);
--
2.52.0
On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
> From: Charlie Jenkins <thecharlesjenkins@gmail.com>
>
> EXPECT_EQ() expands to multiple lines, breaking up one-line if
> statements. This issue was not present in the patch on the mailing list
> but was instead introduced by the maintainer when attempting to fix up
> checkpatch warnings. Add braces around EXPECT_EQ() to avoid the error
> even though checkpatch suggests them to be removed:
>
> validate_v_ptrace.c:626:17: error: ‘else’ without a previous ‘if’
That's annoying. Can't the macro body be wrapped in do { ... } while (0);
instead, rather than adding these permanent checkpatch warnings?
- Paul
On Fri, 20 Mar 2026, Paul Walmsley wrote:
> On Mon, 9 Mar 2026, Charlie Jenkins via B4 Relay wrote:
>
> > From: Charlie Jenkins <thecharlesjenkins@gmail.com>
> >
> > EXPECT_EQ() expands to multiple lines, breaking up one-line if
> > statements. This issue was not present in the patch on the mailing list
> > but was instead introduced by the maintainer when attempting to fix up
> > checkpatch warnings. Add braces around EXPECT_EQ() to avoid the error
> > even though checkpatch suggests them to be removed:
> >
> > validate_v_ptrace.c:626:17: error: ‘else’ without a previous ‘if’
>
> That's annoying. Can't the macro body be wrapped in do { ... } while (0);
> instead, rather than adding these permanent checkpatch warnings?
I guess you haven't had the chance to take a look at this. Or maybe you
took a look at the kselftest harness macro mess and just decided not to
say anything ;-) I did look, after not hearing back, and the way those
macros are used would make it a big and painful lift to straighten out -
definitely not something for the -rc time frame.
So in the short term, I'm planning to take this as a fix to deal with the
immediate issue.
checkpatch.pl clearly needs to be patched to assume that these kselftest
harness macros don't follow the rules. Care to take that on?
- Paul
On Mon, Mar 09, 2026 at 06:52:11PM -0700, Charlie Jenkins via B4 Relay wrote:
> From: Charlie Jenkins <thecharlesjenkins@gmail.com>
>
> EXPECT_EQ() expands to multiple lines, breaking up one-line if
> statements. This issue was not present in the patch on the mailing list
> but was instead introduced by the maintainer when attempting to fix up
> checkpatch warnings. Add braces around EXPECT_EQ() to avoid the error
> even though checkpatch suggests them to be removed:
>
> validate_v_ptrace.c:626:17: error: ‘else’ without a previous ‘if’
>
> Fixes: 3789d5eecd5a ("selftests: riscv: verify syscalls discard vector context")
> Fixes: 30eb191c895b ("selftests: riscv: verify ptrace rejects invalid vector csr inputs")
> Fixes: 849f05ae1ea6 ("selftests: riscv: verify ptrace accepts valid vector csr values")
> Signed-off-by: Charlie Jenkins <thecharlesjenkins@gmail.com>
> ---
> tools/testing/selftests/riscv/vector/validate_v_ptrace.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
Reviewed-and-Tested-by: Sergey Matyukevich <geomatsi@gmail.com>
Thanks,
Sergey
(adding Kees Cook as he originally submitted this __EXPECT macro)
On Mon, 2026-03-09 at 18:52 -0700, Charlie Jenkins via B4 Relay wrote:
> From: Charlie Jenkins <[thecharlesjenkins@gmail.com](mailto:thecharlesjenkins@gmail.com)>
>
> EXPECT_EQ() expands to multiple lines, breaking up one-line if
> statements. This issue was not present in the patch on the mailing list
> but was instead introduced by the maintainer when attempting to fix up
> checkpatch warnings. Add braces around EXPECT_EQ() to avoid the error
> even though checkpatch suggests them to be removed:
The __EXPECT macro definition is a multistatement
"do { ... } while (0); OPTIONAL_HANDLER(_assert)
Perhaps the multistatement __EXPECT should have another
do {} while (0) around both statments like:
do {
do { ... } while (0);
OPTIONAL_HANDLER(_assert);
} while (0)
so if else blocks without braces would work.
Perhaps the same for the __EXPECT_STR macro definition.
© 2016 - 2026 Red Hat, Inc.