Skip to contentSkip to conversation

selftests/bpf: Fix broken build where char is unsigned

PATCH Applied Björn Töpel 4 participants 4 messages Nov 2, 2023

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: Fix broken build where char is unsigned

From: Björn Töpel <[email protected]>

There are architectures where char is not signed. If so, the following error is triggered:

  | xdp_hw_metadata.c:435:42: error: result of comparison of constant -1 \
  |   with expression of type 'char' is always true \
  |   [-Werror,-Wtautological-constant-out-of-range-compare]
  |   435 |         while ((opt = getopt(argc, argv, "mh")) != -1) {
  |       |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
  | 1 error generated.

Correct by changing the char to int.

Fixes bb6a88885fde ("selftests/bpf: Add options and frags to xdp_hw_metadata")
---
 tools/testing/selftests/bpf/xdp_hw_metadata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/xdp_hw_metadata.c +1 -1
index 17c0f92ff160..c3ba40d0b9de 100644
@@ -430,7 +430,7 @@ static void print_usage(void)
 
 static void read_args(int argc, char *argv[])
 {
-	char opt;
+	int opt;
 
 	while ((opt = getopt(argc, argv, "mh")) != -1) {
 		switch (opt) {

base-commit: cb3c6a58be50c65014296aa3455cae0fa1e82eac

Signature · 1 line
2.40.1
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Björn Töpel

From: Björn Töpel <[email protected]>

There are architectures where char is not signed. If so, the following error is triggered:

  | xdp_hw_metadata.c:435:42: error: result of comparison of constant -1 \
  |   with expression of type 'char' is always true \
  |   [-Werror,-Wtautological-constant-out-of-range-compare]
  |   435 |         while ((opt = getopt(argc, argv, "mh")) != -1) {
  |       |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
  | 1 error generated.
Quoted 4 lines

Correct by changing the char to int.

Fixes bb6a88885fde ("selftests/bpf: Add options and frags to xdp_hw_metadata")
Quoted 23 lines
---
 tools/testing/selftests/bpf/xdp_hw_metadata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/xdp_hw_metadata.c +1 -1
index 17c0f92ff160..c3ba40d0b9de 100644
@@ -430,7 +430,7 @@ static void print_usage(void)
 
 static void read_args(int argc, char *argv[])
 {
-	char opt;
+	int opt;
 
 	while ((opt = getopt(argc, argv, "mh")) != -1) {
 		switch (opt) {

base-commit: cb3c6a58be50c65014296aa3455cae0fa1e82eac

Signature · 1 line
2.40.1
Tested-by on v1 1/1
#2 lore raw
In reply to Björn Töpel
Quoted 12 lines · Björn Töpel

From: Björn Töpel <[email protected]>

There are architectures where char is not signed. If so, the following error is triggered:

  | xdp_hw_metadata.c:435:42: error: result of comparison of constant -1 \
  |   with expression of type 'char' is always true \
  |   [-Werror,-Wtautological-constant-out-of-range-compare]
  |   435 |         while ((opt = getopt(argc, argv, "mh")) != -1) {
  |       |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
  | 1 error generated.
Quoted 4 lines

Correct by changing the char to int.

Fixes bb6a88885fde ("selftests/bpf: Add options and frags to xdp_hw_metadata")

Thank you for the patch.
I saw the same failure when I built selftests/bpf for arm64.

With this patch ontop of today's next-20231102, fixes that build issue.

Cheers,
Anders

Quoted 22 lines
---
 tools/testing/selftests/bpf/xdp_hw_metadata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/xdp_hw_metadata.c +1 -1
index 17c0f92ff160..c3ba40d0b9de 100644
@@ -430,7 +430,7 @@ static void print_usage(void)
 
 static void read_args(int argc, char *argv[])
 {
-	char opt;
+	int opt;
 
 	while ((opt = getopt(argc, argv, "mh")) != -1) {
 		switch (opt) {

base-commit: cb3c6a58be50c65014296aa3455cae0fa1e82eac

Signature · 1 line
2.40.1
#3 lore raw
In reply to Björn Töpel
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:

Quoted 5 lines · On Thu, 2 Nov 2023 11:35:37 +0100 you wrote:

From: Björn Töpel <[email protected]>

There are architectures where char is not signed. If so, the following error is triggered:

Quoted 8 lines
  | xdp_hw_metadata.c:435:42: error: result of comparison of constant -1 \
  |   with expression of type 'char' is always true \
  |   [-Werror,-Wtautological-constant-out-of-range-compare]
  |   435 |         while ((opt = getopt(argc, argv, "mh")) != -1) {
  |       |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
  | 1 error generated.

[...]

Here is the summary with links:
- [bpf] selftests/bpf: Fix broken build where char is unsigned

    https://git.kernel.org/bpf/bpf/c/d84b139f53e8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html