[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZN39SM85zuOV+6gP1KK0fdvUGVxL3THpzRNWTOi7KCxw@mail.gmail.com>
Date: Fri, 14 Jan 2022 18:10:46 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Mauricio Vásquez <mauricio@...volk.io>
Cc: Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Quentin Monnet <quentin@...valent.com>,
Rafael David Tinoco <rafaeldtinoco@...il.com>,
Lorenzo Fontana <lorenzo.fontana@...stic.co>,
Leonardo Di Donato <leonardo.didonato@...stic.co>
Subject: Re: [PATCH bpf-next v4 4/8] bpftool: Implement btf_save_raw()
On Wed, Jan 12, 2022 at 6:27 AM Mauricio Vásquez <mauricio@...volk.io> wrote:
>
> Helper function to save a BTF object to a file.
>
> Signed-off-by: Mauricio Vásquez <mauricio@...volk.io>
> Signed-off-by: Rafael David Tinoco <rafael.tinoco@...asec.com>
> Signed-off-by: Lorenzo Fontana <lorenzo.fontana@...stic.co>
> Signed-off-by: Leonardo Di Donato <leonardo.didonato@...stic.co>
> ---
> tools/bpf/bpftool/gen.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
See suggestions, but either way:
Acked-by: Andrii Nakryiko <andrii@...nel.org>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index cdeb1047d79d..5a74fb68dc84 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -1096,6 +1096,36 @@ static int do_help(int argc, char **argv)
> return 0;
> }
>
> +static int btf_save_raw(const struct btf *btf, const char *path)
> +{
> + const void *data;
> + FILE *f = NULL;
> + __u32 data_sz;
> + int err = 0;
> +
> + data = btf__raw_data(btf, &data_sz);
> + if (!data) {
> + err = -ENOMEM;
> + goto out;
> + }
can do just return -ENOMEM instead of goto
> +
> + f = fopen(path, "wb");
> + if (!f) {
> + err = -errno;
> + goto out;
> + }
> +
> + if (fwrite(data, 1, data_sz, f) != data_sz) {
> + err = -errno;
> + goto out;
> + }
> +
> +out:
> + if (f)
with early return above, no need for if (f) check
> + fclose(f);
> + return err;
> +}
> +
> /* Create BTF file for a set of BPF objects */
> static int btfgen(const char *src_btf, const char *dst_btf, const char *objspaths[])
> {
> --
> 2.25.1
>
Powered by blists - more mailing lists