From: Gao Feng Date: Tue, 25 Oct 2016 14:26:09 +0000 (+0800) Subject: driver: tun: Move tun check into the block of TUNSETIFF condition check X-Git-Tag: v4.14-rc1~1973^2~395 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f16bc1355bab719958577b2e519a8cef1637b28;p=platform%2Fkernel%2Flinux-rpi3.git 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 Signed-off-by: David S. Miller --- diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 9328568..9142db8 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);