bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] tools/bpftool: Avoid using "?:" in generated code
@ 2021-09-28 18:11 Yucong Sun
  2021-09-28 18:25 ` Andrii Nakryiko
  0 siblings, 1 reply; 2+ messages in thread
From: Yucong Sun @ 2021-09-28 18:11 UTC (permalink / raw)
  To: bpf; +Cc: andrii, sunyucong, 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.

Signed-off-by: Yucong Sun <fallentree@fb.com>
---
 tools/bpf/bpftool/gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index d40d92bbf0e4..85071b6fa4ad 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -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\
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf] tools/bpftool: Avoid using "?:" in generated code
  2021-09-28 18:11 [PATCH bpf] tools/bpftool: Avoid using "?:" in generated code Yucong Sun
@ 2021-09-28 18:25 ` Andrii Nakryiko
  0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2021-09-28 18:25 UTC (permalink / raw)
  To: Yucong Sun; +Cc: bpf, Andrii Nakryiko, Yucong Sun

On Tue, Sep 28, 2021 at 11:11 AM Yucong Sun <fallentree@fb.com> wrote:
>
> "?:" 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.
>
> Signed-off-by: Yucong Sun <fallentree@fb.com>
> ---

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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index d40d92bbf0e4..85071b6fa4ad 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -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?

>                         if (err)                                            \n\
>                                 goto err_out;                               \n\
>                                                                             \n\
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-28 18:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 18:11 [PATCH bpf] tools/bpftool: Avoid using "?:" in generated code Yucong Sun
2021-09-28 18:25 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).