Skip to contentSkip to conversation

tools/bpftool: Avoid using "?:" in generated code

PATCH Superseded Yucong Sun 2 participants 2 messages Sep 28, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yucong Sun

author
#0 lore raw

PATCH 1/1 tools/bpftool: Avoid using "?:" in generated code

"?:" is a GNU C extension, some environment has warning flags for its use, or even prohibit it directly. This patch avoid triggering these problems by simply expand it to its full form, no functionality change.

---
 tools/bpf/bpftool/gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index d40d92bbf0e4..85071b6fa4ad 100644
@@ -803,7 +803,7 @@ static int do_skeleton(int argc, char **argv)
 			}						    \n\
 									    \n\
 			err = %1$s__create_skeleton(obj);		    \n\
-			err = err ?: bpf_object__open_skeleton(obj->skeleton, opts);\n\
+			err = err ? err : bpf_object__open_skeleton(obj->skeleton, opts);\n\
 			if (err)					    \n\
 				goto err_out;				    \n\
 									    \n\
Signature · 1 line
2.30.2
#1 lore raw
Quoted 7 lines · Yucong Sun

"?:" is a GNU C extension, some environment has warning flags for its use, or even prohibit it directly. This patch avoid triggering these problems by simply expand it to its full form, no functionality change.

---

Given there is no bug in the first place, it's not a fix, and thus should target bpf-next tree.

tools/bpf/bpftool/gen.c static int do_skeleton(int argc, char **argv) · line 806

Quoted 13 lines
 tools/bpf/bpftool/gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index d40d92bbf0e4..85071b6fa4ad 100644
@@ -803,7 +803,7 @@ static int do_skeleton(int argc, char **argv)
                        }                                                   \n\
                                                                            \n\
                        err = %1$s__create_skeleton(obj);                   \n\
-                       err = err ?: bpf_object__open_skeleton(obj->skeleton, opts);\n\
+                       err = err ? err : bpf_object__open_skeleton(obj->skeleton, opts);\n\

err+err+err in one row looks quite bad. If we can't use ?: for shortness, maybe let's just do

if (!err)
err = <some operation>

It's more verbose than the original version, but it's more obvious and sort of canonical C?

Quoted 6 lines
tools/bpf/bpftool/gen.c +0 -1
                        if (err)                                            \n\
                                goto err_out;                               \n\
                                                                            \n\
--

2.30.2