From: Michal Rostecki <mrostecki@opensuse.org>
To: Wang Hai <wanghai38@huawei.com>,
john.fastabend@gmail.com, quentin@isovalent.com
Cc: ast@kernel.org, daniel@iogearbox.net, kafai@fb.com,
songliubraving@fb.com, yhs@fb.com, andrii@kernel.org,
kpsingh@chromium.org, toke@redhat.com, danieltimlee@gmail.com,
bpf@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 bpf] tools: bpftool: Add missing close before bpftool net attach exit
Date: Wed, 11 Nov 2020 15:43:44 +0100 [thread overview]
Message-ID: <60498580-ad5f-da24-5792-897be2290b9d@opensuse.org> (raw)
In-Reply-To: <20201111135425.56533-1-wanghai38@huawei.com>
On 11/11/20 2:54 PM, 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@huawei.com>
> ---
> v2->v3: add 'err = 0' before successful return
> v1->v2: use cleanup tag instead of repeated closes
> tools/bpf/bpftool/net.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c
> index 910e7bac6e9e..f927392271cc 100644
> --- 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,20 @@ 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;
> + err = 0;
> +
> +cleanup:
> + close(progfd);
> + return err;
> }
>
> static int do_detach(int argc, char **argv)
>
LGTM, thanks!
Reviewed-By: Michal Rostecki <mrostecki@opensuse.org>
next prev parent reply other threads:[~2020-11-11 14:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-11 13:54 Wang Hai
2020-11-11 14:43 ` Michal Rostecki [this message]
2020-11-11 21:24 ` Daniel Borkmann
2020-11-11 22:37 ` Andrii Nakryiko
2020-11-11 22:49 ` Andrii Nakryiko
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=60498580-ad5f-da24-5792-897be2290b9d@opensuse.org \
--to=mrostecki@opensuse.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=danieltimlee@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=quentin@isovalent.com \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=wanghai38@huawei.com \
--cc=yhs@fb.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
all inboxes | Powered by JetHome®