From: "Mauricio Vásquez Bernal" <mauricio@kinvolk.io>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Quentin Monnet <quentin@isovalent.com>,
Rafael David Tinoco <rafaeldtinoco@gmail.com>,
Lorenzo Fontana <lorenzo.fontana@elastic.co>,
Leonardo Di Donato <leonardo.didonato@elastic.co>
Subject: Re: [PATCH bpf-next v4 4/8] bpftool: Implement btf_save_raw()
Date: Fri, 21 Jan 2022 15:45:17 -0500 [thread overview]
Message-ID: <CAHap4ztH7vaVjhYMvBKbpkrbVP93egxwNSy08TrNv=GaJWRBGQ@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzZN39SM85zuOV+6gP1KK0fdvUGVxL3THpzRNWTOi7KCxw@mail.gmail.com>
On Fri, Jan 14, 2022 at 9:10 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Jan 12, 2022 at 6:27 AM Mauricio Vásquez <mauricio@kinvolk.io> wrote:
> >
> > Helper function to save a BTF object to a file.
> >
> > Signed-off-by: Mauricio Vásquez <mauricio@kinvolk.io>
> > Signed-off-by: Rafael David Tinoco <rafael.tinoco@aquasec.com>
> > Signed-off-by: Lorenzo Fontana <lorenzo.fontana@elastic.co>
> > Signed-off-by: Leonardo Di Donato <leonardo.didonato@elastic.co>
> > ---
> > tools/bpf/bpftool/gen.c | 30 ++++++++++++++++++++++++++++++
> > 1 file changed, 30 insertions(+)
> >
>
> See suggestions, but either way:
>
> Acked-by: Andrii Nakryiko <andrii@kernel.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
>
After those suggestions I decided to completely remove the out label.
> > + 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
> >
next prev parent reply other threads:[~2022-01-21 20:45 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-12 14:27 [PATCH bpf-next v4 0/8] libbpf: Implement BTFGen Mauricio Vásquez
2022-01-12 14:27 ` [PATCH bpf-next v4 1/8] libbpf: split bpf_core_apply_relo() Mauricio Vásquez
2022-01-15 2:01 ` Andrii Nakryiko
2022-01-21 20:40 ` Mauricio Vásquez Bernal
2022-01-12 14:27 ` [PATCH bpf-next v4 2/8] libbpf: Implement changes needed for BTFGen in bpftool Mauricio Vásquez
2022-01-12 18:08 ` Quentin Monnet
2022-01-21 20:44 ` Mauricio Vásquez Bernal
2022-01-15 2:04 ` Andrii Nakryiko
2022-01-12 14:27 ` [PATCH bpf-next v4 3/8] bpftool: Add gen btf command Mauricio Vásquez
2022-01-12 18:08 ` Quentin Monnet
2022-01-21 20:40 ` Mauricio Vásquez Bernal
2022-01-21 21:35 ` Andrii Nakryiko
2022-01-15 2:09 ` Andrii Nakryiko
2022-01-21 20:44 ` Mauricio Vásquez Bernal
2022-01-12 14:27 ` [PATCH bpf-next v4 4/8] bpftool: Implement btf_save_raw() Mauricio Vásquez
2022-01-15 2:10 ` Andrii Nakryiko
2022-01-21 20:45 ` Mauricio Vásquez Bernal [this message]
2022-01-12 14:27 ` [PATCH bpf-next v4 5/8] bpftool: Add struct definitions and helpers for BTFGen Mauricio Vásquez
2022-01-12 14:27 ` [PATCH bpf-next v4 6/8] bpftool: Implement btfgen() Mauricio Vásquez
2022-01-12 18:09 ` Quentin Monnet
2022-01-15 2:15 ` Andrii Nakryiko
2022-01-12 14:27 ` [PATCH bpf-next v4 7/8] bpftool: Implement relocations recording for BTFGen Mauricio Vásquez
2022-01-12 18:09 ` Quentin Monnet
2022-01-12 14:27 ` [PATCH bpf-next v4 8/8] bpftool: Implement btfgen_get_btf() Mauricio Vásquez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHap4ztH7vaVjhYMvBKbpkrbVP93egxwNSy08TrNv=GaJWRBGQ@mail.gmail.com' \
--to=mauricio@kinvolk.io \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=leonardo.didonato@elastic.co \
--cc=lorenzo.fontana@elastic.co \
--cc=netdev@vger.kernel.org \
--cc=quentin@isovalent.com \
--cc=rafaeldtinoco@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).