Skip to contentSkip to conversation

bpftool: fix output for skipping kernel config check

PATCH In review Chethan Suresh 2 participants 3 messages Dec 6, 2022 – Dec 13, 2022

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

PATCH 1/1 bpftool: fix output for skipping kernel config check

When bpftool feature does not find kernel config files under default path, do not output CONFIG_XYZ is not set. Skip kernel config check and continue.

---
 tools/bpf/bpftool/feature.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/bpf/bpftool/feature.c +7 -7
index 36cf0f1517c9..316c4a01bdb7 100644
@@ -487,14 +487,14 @@ static void probe_kernel_image_config(const char *define_prefix)
 	}
 
 end_parse:
-	if (file)
+	if (file) {
 		gzclose(file);
-
-	for (i = 0; i < ARRAY_SIZE(options); i++) {
-		if (define_prefix && !options[i].macro_dump)
-			continue;
-		print_kernel_option(options[i].name, values[i], define_prefix);
-		free(values[i]);
+		for (i = 0; i < ARRAY_SIZE(options); i++) {
+			if (define_prefix && !options[i].macro_dump)
+				continue;
+			print_kernel_option(options[i].name, values[i], define_prefix);
+			free(values[i]);
+		}
 	}
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Chethan Suresh

When bpftool feature does not find kernel config files under default path, do not output CONFIG_XYZ is not set. Skip kernel config check and continue.

---
 tools/bpf/bpftool/feature.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/bpf/bpftool/feature.c +0 -0
index 36cf0f1517c9..316c4a01bdb7 100644

tools/bpf/bpftool/feature.c static void probe_kernel_image_config(const char *define_prefix) · line 490

Quoted 5 lines
tools/bpf/bpftool/feature.c +1 -1
@@ -487,14 +487,14 @@ static void probe_kernel_image_config(const char *define_prefix)
        }
 
 end_parse:
-       if (file)
+       if (file) {

There are two error conditions when file != NULL but we actually don't read kconfig contents. Please handle those properly, otherwise all the same confusion will keep happening.

Quoted 19 lines
tools/bpf/bpftool/feature.c +6 -7
                gzclose(file);
-
-       for (i = 0; i < ARRAY_SIZE(options); i++) {
-               if (define_prefix && !options[i].macro_dump)
-                       continue;
-               print_kernel_option(options[i].name, values[i], define_prefix);
-               free(values[i]);
+               for (i = 0; i < ARRAY_SIZE(options); i++) {
+                       if (define_prefix && !options[i].macro_dump)
+                               continue;
+                       print_kernel_option(options[i].name, values[i], define_prefix);
+                       free(values[i]);
+               }
        }
 }
 
--

2.17.1

#2 lore raw
Quoted 19 lines · Andrii Nakryiko
Quoted 18 lines · Chethan Suresh

When bpftool feature does not find kernel config files under default path, do not output CONFIG_XYZ is not set. Skip kernel config check and continue.

---
 tools/bpf/bpftool/feature.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/bpf/bpftool/feature.c +0 -0
index 36cf0f1517c9..316c4a01bdb7 100644
@@ -487,14 +487,14 @@ static void probe_kernel_image_config(const char *define_prefix)
        }
 
Quoted 7 lines

tools/bpf/bpftool/feature.c static void probe_kernel_image_config(const char *define_prefix) · line 490

Quoted 3 lines
tools/bpf/bpftool/feature.c +1 -1
 end_parse:
-       if (file)
+       if (file) {

There are two error conditions when file != NULL but we actually don't read kconfig contents. Please handle those properly, otherwise all the same confusion will keep happening.

As I understand, the check should skip when file != NULL itself rather than handling it in end_parse.
I'll send the updated patch based on review.

Quoted 20 lines
Quoted 20 lines
tools/bpf/bpftool/feature.c +6 -7
                gzclose(file);
-
-       for (i = 0; i < ARRAY_SIZE(options); i++) {
-               if (define_prefix && !options[i].macro_dump)
-                       continue;
-               print_kernel_option(options[i].name, values[i], define_prefix);
-               free(values[i]);
+               for (i = 0; i < ARRAY_SIZE(options); i++) {
+                       if (define_prefix && !options[i].macro_dump)
+                               continue;
+                       print_kernel_option(options[i].name, values[i], define_prefix);
+                       free(values[i]);
+               }
        }
 }
 
--

2.17.1