From: Matthieu Baerts <matthieu.baerts@tessares.net>
To: alexei.starovoitov@gmail.com
Cc: andriin@fb.com, ast@kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, davem@davemloft.net, fejes@inf.elte.hu,
john.fastabend@gmail.com, kafai@fb.com, kpsingh@chromium.org,
kuba@kernel.org, linux-kernel@vger.kernel.org,
matthieu.baerts@tessares.net, netdev@vger.kernel.org,
songliubraving@fb.com, yhs@fb.com
Subject: [PATCH bpf v2] bpf: fix unused-var without NETDEVICES
Date: Wed, 3 Jun 2020 21:03:47 +0200 [thread overview]
Message-ID: <20200603190347.2310320-1-matthieu.baerts@tessares.net> (raw)
In-Reply-To: <CAADnVQ+k7+fQmuNQL=GLLaGUvd5+zZN6GViy-oP7Sfq7aQVG1Q@mail.gmail.com>
A recent commit added new variables only used if CONFIG_NETDEVICES is
set. A simple fix would be to only declare these variables if the same
condition is valid but Alexei suggested an even simpler solution:
since CONFIG_NETDEVICES doesn't change anything in .h I think the
best is to remove #ifdef CONFIG_NETDEVICES from net/core/filter.c
and rely on sock_bindtoindex() returning ENOPROTOOPT in the extreme
case of oddly configured kernels.
Fixes: 70c58997c1e8 ("bpf: Allow SO_BINDTODEVICE opt in bpf_setsockopt")
Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
---
Notes:
This fix currently applies on net-next and bpf-next only. Except that
net-next is now closed and -net will get commits from net-next after
Linus' pull.
v2: remove #ifdef CONFIG_NETDEVICES (Alexei)
net/core/filter.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index d01a244b5087..90d2eb77002f 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4340,8 +4340,6 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
}
break;
case SO_BINDTODEVICE:
- ret = -ENOPROTOOPT;
-#ifdef CONFIG_NETDEVICES
optlen = min_t(long, optlen, IFNAMSIZ - 1);
strncpy(devname, optval, optlen);
devname[optlen] = 0;
@@ -4360,7 +4358,6 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
dev_put(dev);
}
ret = sock_bindtoindex(sk, ifindex, false);
-#endif
break;
default:
ret = -EINVAL;
--
2.25.1
next prev parent reply other threads:[~2020-06-03 19:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-03 8:11 [PATCH bpf] bpf: fix unused-var without NETDEVICES Matthieu Baerts
2020-06-03 8:56 ` Ferenc Fejes
2020-06-03 9:12 ` Matthieu Baerts
2020-06-03 18:14 ` Alexei Starovoitov
2020-06-03 18:41 ` Matthieu Baerts
2020-06-03 18:43 ` Alexei Starovoitov
2020-06-03 19:03 ` Matthieu Baerts [this message]
2020-06-03 20:45 ` [PATCH bpf v2] " Song Liu
2020-06-04 20:53 ` Daniel Borkmann
2020-06-03 18:59 ` [PATCH bpf] " Ferenc Fejes
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=20200603190347.2310320-1-matthieu.baerts@tessares.net \
--to=matthieu.baerts@tessares.net \
--cc=alexei.starovoitov@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=fejes@inf.elte.hu \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.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;
as well as URLs for NNTP newsgroup(s).