[PATCH net] tun: allow positive return values on dev_get_valid_name() call
If the name argument of dev_get_valid_name() contains "%d", it will try to assign it a unit number in __dev__alloc_name() and return either the unit number (>= 0) or an error code (< 0). Considering positive values as error values prevent tun device creations relying this mechanism, therefor we should only consider negative values as errors here. Signed-off-by: Julien Gomes --- drivers/net/tun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index ea29da91ea5a..4d2400c253ba 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2253,7 +2253,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) if (!dev) return -ENOMEM; err = dev_get_valid_name(net, dev, name); - if (err) + if (err < 0) goto err_free_dev; dev_net_set(dev, net); -- 2.14.2
Re: [PATCH net] tun: allow positive return values on dev_get_valid_name() call
On Wed, Oct 25, 2017 at 11:50 AM, Julien Gomes wrote: > If the name argument of dev_get_valid_name() contains "%d", it will try > to assign it a unit number in __dev__alloc_name() and return either the > unit number (>= 0) or an error code (< 0). > Considering positive values as error values prevent tun device creations > relying this mechanism, therefor we should only consider negative values > as errors here. > > Signed-off-by: Julien Gomes Good catch! I missed this case indeed. We'd better document it in the future. Acked-by: Cong Wang
Re: [PATCH net] tun: allow positive return values on dev_get_valid_name() call
From: Julien Gomes Date: Wed, 25 Oct 2017 11:50:50 -0700 > If the name argument of dev_get_valid_name() contains "%d", it will try > to assign it a unit number in __dev__alloc_name() and return either the > unit number (>= 0) or an error code (< 0). > Considering positive values as error values prevent tun device creations > relying this mechanism, therefor we should only consider negative values > as errors here. > > Signed-off-by: Julien Gomes Applied, thanks.
Re: [PATCH net] tun: allow positive return values on dev_get_valid_name() call
From: Julien Gomes Date: Wed, 25 Oct 2017 11:50:50 -0700 > If the name argument of dev_get_valid_name() contains "%d", it will try > to assign it a unit number in __dev__alloc_name() and return either the > unit number (>= 0) or an error code (< 0). > Considering positive values as error values prevent tun device creations > relying this mechanism, therefor we should only consider negative values > as errors here. > > Signed-off-by: Julien Gomes Applied.