summaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorGao Feng <fgao@ikuai8.com>2016-10-25 16:26:09 +0200
committerDavid S. Miller <davem@davemloft.net>2016-10-29 20:51:42 +0200
commit0f16bc1355bab719958577b2e519a8cef1637b28 (patch)
tree5d78ddca868f0146e7ae379221afede07958eaa1 /drivers/net/tun.c
parentvirtio-net: Update the mtu code to match virtio spec (diff)
downloadlinux-0f16bc1355bab719958577b2e519a8cef1637b28.tar.xz
linux-0f16bc1355bab719958577b2e519a8cef1637b28.zip
driver: tun: Move tun check into the block of TUNSETIFF condition check
When cmd is TUNSETIFF and tun is not null, the original codes go ahead, then reach the default case of switch(cmd) and set the ret is -EINVAL. It is not clear for readers. Now move the tun check into the block of TUNSETIFF condition check, and return -EEXIST instead of -EINVAL when the tfile already owns one tun. Signed-off-by: Gao Feng <fgao@ikuai8.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 93285687cf13..9142db847ee1 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2005,7 +2005,11 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
rtnl_lock();
tun = __tun_get(tfile);
- if (cmd == TUNSETIFF && !tun) {
+ if (cmd == TUNSETIFF) {
+ ret = -EEXIST;
+ if (tun)
+ goto unlock;
+
ifr.ifr_name[IFNAMSIZ-1] = '\0';
ret = tun_set_iff(sock_net(&tfile->sk), file, &ifr);