From patchwork Thu Oct 7 16:16:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12542215 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F9F8C433FE for ; Thu, 7 Oct 2021 16:17:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 499C461245 for ; Thu, 7 Oct 2021 16:17:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242692AbhJGQTF (ORCPT ); Thu, 7 Oct 2021 12:19:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:34856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242596AbhJGQSv (ORCPT ); Thu, 7 Oct 2021 12:18:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D4DB96105A; Thu, 7 Oct 2021 16:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633623417; bh=Fb3G46eVZSaqJ/73u+jZiUnK+uT23FPtztNo6bYR00U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AUftzbAyJuUai2SjIIXo1q915/vX8LBB0w/V3lGuGB5zLgKEIw4rpirQCOFECrxap BdB0POrzQ9Qw36+yIfG84RHDq+W55y16ilF43AmNlroK+2VWZuwjG0L+x2fMP0UERo /DyUvgy67rE6o3Vs7vFIZlAGajB3q/Rqk8WfiiOjDg1WEB8Fj5gTKxWk+Hz3BLbpiW 4L+2V7MCTXmX2LIvARqsUSpIXz1jglAL/ghNT+bJ6G3zmp4b2XTpkSE/DMWFc9C/B2 0ADv4Qi+jcdDzEFezC6jOMX9tlwmOHukzDAwqRcM6FH4trfnrU984FaPL+RR9YqC5+ fSeG03RKYI2Jw== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [PATCH net-next 1/3] net: introduce a function to check if a netdev name is in use Date: Thu, 7 Oct 2021 18:16:50 +0200 Message-Id: <20211007161652.374597-2-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007161652.374597-1-atenart@kernel.org> References: <20211007161652.374597-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org __dev_get_by_name is currently used to either retrieve a net device reference using its name or to check if a name is already used by a registered net device (per ns). In the later case there is no need to return a reference to a net device. Introduce a new helper, netdev_name_in_use, to check if a name is currently used by a registered net device without leaking a reference the corresponding net device. This helper uses netdev_name_node_lookup instead of __dev_get_by_name as we don't need the extra logic retrieving a reference to the corresponding net device. Signed-off-by: Antoine Tenart --- include/linux/netdevice.h | 1 + net/core/dev.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index d79163208dfd..15f4a658e436 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2955,6 +2955,7 @@ struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags, struct net_device *dev_get_by_name(struct net *net, const char *name); struct net_device *dev_get_by_name_rcu(struct net *net, const char *name); struct net_device *__dev_get_by_name(struct net *net, const char *name); +bool netdev_name_in_use(struct net *net, const char *name); int dev_alloc_name(struct net_device *dev, const char *name); int dev_open(struct net_device *dev, struct netlink_ext_ack *extack); void dev_close(struct net_device *dev); diff --git a/net/core/dev.c b/net/core/dev.c index 16ab09b6a7f8..1594cd2955ba 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -303,6 +303,12 @@ static struct netdev_name_node *netdev_name_node_lookup_rcu(struct net *net, return NULL; } +bool netdev_name_in_use(struct net *net, const char *name) +{ + return netdev_name_node_lookup(net, name); +} +EXPORT_SYMBOL(netdev_name_in_use); + int netdev_name_node_alt_create(struct net_device *dev, const char *name) { struct netdev_name_node *name_node; @@ -1133,7 +1139,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf) } snprintf(buf, IFNAMSIZ, name, i); - if (!__dev_get_by_name(net, buf)) + if (!netdev_name_in_use(net, buf)) return i; /* It is possible to run out of possible slots @@ -1187,7 +1193,7 @@ static int dev_get_valid_name(struct net *net, struct net_device *dev, if (strchr(name, '%')) return dev_alloc_name_ns(net, dev, name); - else if (__dev_get_by_name(net, name)) + else if (netdev_name_in_use(net, name)) return -EEXIST; else if (dev->name != name) strlcpy(dev->name, name, IFNAMSIZ); @@ -11153,7 +11159,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, * we can use it in the destination network namespace. */ err = -EEXIST; - if (__dev_get_by_name(net, dev->name)) { + if (netdev_name_in_use(net, dev->name)) { /* We get here if we can't use the current device name */ if (!pat) goto out; @@ -11506,7 +11512,7 @@ static void __net_exit default_device_exit(struct net *net) /* Push remaining network devices to init_net */ snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); - if (__dev_get_by_name(&init_net, fb_name)) + if (netdev_name_in_use(&init_net, fb_name)) snprintf(fb_name, IFNAMSIZ, "dev%%d"); err = dev_change_net_namespace(dev, &init_net, fb_name); if (err) { From patchwork Thu Oct 7 16:16:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12542213 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B1FEC433FE for ; Thu, 7 Oct 2021 16:17:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FA54610E6 for ; Thu, 7 Oct 2021 16:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242668AbhJGQS5 (ORCPT ); Thu, 7 Oct 2021 12:18:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:34892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242639AbhJGQSx (ORCPT ); Thu, 7 Oct 2021 12:18:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 276986113E; Thu, 7 Oct 2021 16:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633623419; bh=kbowb8lxcB967BBq1xJzUoWMBbuImOONRup+OQUabfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BIaNtu7p7HGAFhZW4zsk5lDk8m4Fu7WNJmF9/VOd31AZcCjOi69m/7VeaHd305lsb 8Cs4U3OgpZTMk5udZXn2bATiKw1GaTTWCl9B9qJzPcNb0/wDrRrfY7Cf0ltfrVTBMS dY35n6NAg/sH/H6emeCPdYVPKXzE1+ulO8Yda3serwaj074uhsHen+LCV8/TKw5d2u 9njyJ246o8oEE5PFoStzYL40xphqAwLVOnXryNDtcsZDRcR/9qU9d+vuoaJatvPsZ5 II7ykHH10xUH6wcKxqJGMGK0QMVS8JSYqFt9ckOGijnQOVuGgjJtYitkJ72XkKN58R n/xbeTeZzhsoA== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [PATCH net-next 2/3] bonding: use the correct function to check for netdev name collision Date: Thu, 7 Oct 2021 18:16:51 +0200 Message-Id: <20211007161652.374597-3-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007161652.374597-1-atenart@kernel.org> References: <20211007161652.374597-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org A new helper to detect if a net device name is in use was added. Use it here as the return reference from __dev_get_by_name was discarded. Signed-off-by: Antoine Tenart --- drivers/net/bonding/bond_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index b9e9842fed94..c48b77167fab 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c @@ -811,8 +811,8 @@ int bond_create_sysfs(struct bond_net *bn) */ if (ret == -EEXIST) { /* Is someone being kinky and naming a device bonding_master? */ - if (__dev_get_by_name(bn->net, - class_attr_bonding_masters.attr.name)) + if (netdev_name_in_use(bn->net, + class_attr_bonding_masters.attr.name)) pr_err("network device named %s already exists in sysfs\n", class_attr_bonding_masters.attr.name); ret = 0; From patchwork Thu Oct 7 16:16:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 12542217 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB6A3C433FE for ; Thu, 7 Oct 2021 16:17:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CC13611C3 for ; Thu, 7 Oct 2021 16:17:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242647AbhJGQTP (ORCPT ); Thu, 7 Oct 2021 12:19:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:34986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242652AbhJGQSz (ORCPT ); Thu, 7 Oct 2021 12:18:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E76B611C3; Thu, 7 Oct 2021 16:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633623422; bh=8sAV6q+14eiHBjK3Y1sRwJSYdxxyN2jhUlobDg8wR3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qp8bT3qmqYLZfGCQb1/rnKOH+4khEsO/N8Ceo+Abrs0CIEo567L0MuSPBvUXytrXi BnbFzQBHuQaYsFzznwyAJyamkn4EDmiJM8iH3PApUsy65pVKJ+VrbkaOAH8xPEm5Io g6HYhUkhclMpFeyWvpKA5XnEXVTwXHbLIgio/ZqRhBpwN9dgMMST46hgwFi/rJLy+G AeNT/iudXpfvflCMchMbxAHELUK/i9S+/b0En+0WnsyM5gkd2OqU1tsFDqz4T1BjEk 4hONHA7Ag5HGjarzCbKPrlDt1m9kxHvMjfD5gG20KZAGRbZjERoQVNmCl0/77EcVCy D0HJGcOxAA9Gg== From: Antoine Tenart To: davem@davemloft.net, kuba@kernel.org Cc: Antoine Tenart , pabeni@redhat.com, juri.lelli@redhat.com, netdev@vger.kernel.org Subject: [PATCH net-next 3/3] ppp: use the correct function to check if a netdev name is in use Date: Thu, 7 Oct 2021 18:16:52 +0200 Message-Id: <20211007161652.374597-4-atenart@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211007161652.374597-1-atenart@kernel.org> References: <20211007161652.374597-1-atenart@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org A new helper to detect if a net device name is in use was added. Use it here as the return reference from __dev_get_by_name was discarded. Signed-off-by: Antoine Tenart --- drivers/net/ppp/ppp_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index fb52cd175b45..1180a0e2445f 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1161,7 +1161,7 @@ static int ppp_unit_register(struct ppp *ppp, int unit, bool ifname_is_set) if (!ifname_is_set) { while (1) { snprintf(ppp->dev->name, IFNAMSIZ, "ppp%i", ret); - if (!__dev_get_by_name(ppp->ppp_net, ppp->dev->name)) + if (!netdev_name_in_use(ppp->ppp_net, ppp->dev->name)) break; unit_put(&pn->units_idr, ret); ret = unit_get(&pn->units_idr, ppp, ret + 1);