[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5faba45f90ac8_bb260208e0@john-XPS-13-9370.notmuch>
Date: Wed, 11 Nov 2020 00:44:15 -0800
From: John Fastabend <john.fastabend@...il.com>
To: "wanghai (M)" <wanghai38@...wei.com>,
John Fastabend <john.fastabend@...il.com>
Cc: quentin@...valent.com, mrostecki@...nsuse.org, ast@...nel.org,
daniel@...earbox.net, kafai@...com, songliubraving@...com,
yhs@...com, andrii@...nel.org, kpsingh@...omium.org,
toke@...hat.com, danieltimlee@...il.com, bpf@...r.kernel.org,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 bpf] tools: bpftool: Add missing close before bpftool
net attach exit
wanghai (M) wrote:
>
> 在 2020/11/10 12:33, John Fastabend 写道:
> > Wang Hai wrote:
> >> progfd is created by prog_parse_fd(), before 'bpftool net attach' exit,
> >> it should be closed.
> >>
> >> Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
> >> Signed-off-by: Wang Hai <wanghai38@...wei.com>
> >> ---
[...]
> > Alternatively we could add an 'err = 0' here, but above should never
> > return a value >0 as far as I can see.
> It's true that 'err > 0' doesn't exist currently , but adding 'err = 0'
> would make the code clearer. Thanks for your advice.
> >> +cleanup:
> >> + close(progfd);
> >> + return err;
> >> }
> >>
> >> static int do_detach(int argc, char **argv)
> >> --
> >> 2.17.1
> >>
> Can it be fixed like this?
>
> --- a/tools/bpf/bpftool/net.c
> +++ b/tools/bpf/bpftool/net.c
> @@ -578,8 +578,8 @@ static int do_attach(int argc, char **argv)
>
> ifindex = net_parse_dev(&argc, &argv);
> if (ifindex < 1) {
> - close(progfd);
> - return -EINVAL;
> + err = -EINVAL;
> + goto cleanup;
> }
>
> if (argc) {
> @@ -587,8 +587,8 @@ static int do_attach(int argc, char **argv)
> overwrite = true;
> } else {
> p_err("expected 'overwrite', got: '%s'?", *argv);
> - close(progfd);
> - return -EINVAL;
> + err = -EINVAL;
> + goto cleanup;
> }
> }
>
> @@ -597,16 +597,19 @@ static int do_attach(int argc, char **argv)
> err = do_attach_detach_xdp(progfd, attach_type, ifindex,
> overwrite);
>
> - if (err < 0) {
> + if (err) {
> p_err("interface %s attach failed: %s",
> attach_type_strings[attach_type], strerror(-err));
> - return err;
> + goto cleanup;
> }
>
> if (json_output)
> jsonw_null(json_wtr);
>
> - return 0;
> + ret = 0;
> +cleanup:
> + close(progfd);
> + return err;
> }
>
LGTM. Send a v3.
Powered by blists - more mailing lists