Skip to content

Commit

Permalink
bpf: fix unused-var without NETDEVICES
Browse files Browse the repository at this point in the history
A recent commit added new variables only used if CONFIG_NETDEVICES is
set. A simple fix is to only declare these variables if the same
condition is valid.

Other solutions could be to move the code related to SO_BINDTODEVICE
option from _bpf_setsockopt() function to a dedicated one or only
declare these variables in the related "case" section.

Fixes: 70c5899 ("bpf: Allow SO_BINDTODEVICE opt in bpf_setsockopt")
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
  • Loading branch information
matttbe authored and jenkins-tessares committed Jun 5, 2020
1 parent cb8e59c commit 5e296dd
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 5e296dd

Please sign in to comment.