Skip to content

Commit 4940840

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
RISC-V: selftests: cbo: Ensure asm operands match constraints, take 2
Commit 0de6528 ("RISC-V: selftests: cbo: Ensure asm operands match constraints") attempted to ensure MK_CBO() would always provide to a compile-time constant when given a constant, but cpu_to_le32() isn't necessarily going to do that. Switch to manually shifting the bytes, when needed, to finally get this right. Reported-by: Woodrow Shen <[email protected]> Closes: https://lore.kernel.org/all/CABquHATcBTUwfLpd9sPObBgNobqQKEAZ2yxk+TWSpyO5xvpXpg@mail.gmail.com/ Fixes: a29e2a4 ("RISC-V: selftests: Add CBO tests") Fixes: 0de6528 ("RISC-V: selftests: cbo: Ensure asm operands match constraints") Signed-off-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 9c49085 commit 4940840

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tools/testing/selftests/riscv/hwprobe/cbo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "hwprobe.h"
2020
#include "../../kselftest.h"
2121

22-
#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
22+
#define MK_CBO(fn) le32_bswap((uint32_t)(fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
2323

2424
static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 };
2525

tools/testing/selftests/riscv/hwprobe/hwprobe.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#include <stddef.h>
55
#include <asm/hwprobe.h>
66

7+
#if __BYTE_ORDER == __BIG_ENDIAN
8+
# define le32_bswap(_x) \
9+
((((_x) & 0x000000ffU) << 24) | \
10+
(((_x) & 0x0000ff00U) << 8) | \
11+
(((_x) & 0x00ff0000U) >> 8) | \
12+
(((_x) & 0xff000000U) >> 24))
13+
#else
14+
# define le32_bswap(_x) (_x)
15+
#endif
16+
717
/*
818
* Rather than relying on having a new enough libc to define this, just do it
919
* ourselves. This way we don't need to be coupled to a new-enough libc to

0 commit comments

Comments
 (0)