From patchwork Fri Oct 20 01:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13429954 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 404C939E for ; Fri, 20 Oct 2023 01:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PqAhyEQD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63BA9C433C9; Fri, 20 Oct 2023 01:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764738; bh=jwf0kIkzjClGiJzzxrsDWzhWMg0TOqyIQL/vjbwvzwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PqAhyEQDGWBvS0/bASrp1K2q1oVryM2UDQ5tP1ZmDz7Xe1y0n6ns75ch+WJj1M86j +svbHUxQerWLDr/6dOsL4/9N9HnGGQFx0H6cDi9OUSE11ynL869pNCJKJLWcycKyLr IPweU8k5LODuEZIptOciyMx/DRZnrMHBaUpHmC1AlQCJP1xz6bxNaPrCmEp4MyCopd 3uiSVPulmzhfZRlsEMqlDXzov8GU+9Jk0EfuS44c3TunQlQmwiDfqx4fZPLEquBwak eAqa7XtmcIkSCDbCXgVFpq3FFLCJZOQ8ACRkH+v5FOkvC3h1Ao4FEzwq5Blp+yirQt BhDoAhZ7SXKrw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, johannes.berg@intel.com, mpe@ellerman.id.au, j@w1.fi, jiri@resnulli.us Subject: [PATCH net-next 1/6] net: don't use input buffer of __dev_alloc_name() as a scratch space Date: Thu, 19 Oct 2023 18:18:51 -0700 Message-ID: <20231020011856.3244410-2-kuba@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020011856.3244410-1-kuba@kernel.org> References: <20231020011856.3244410-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Callers of __dev_alloc_name() want to pass dev->name as the output buffer. Make __dev_alloc_name() not clobber that buffer on failure, and remove the workarounds in callers. dev_alloc_name_ns() is now completely unnecessary. The extra strscpy() added here will be gone by the end of the patch series. Signed-off-by: Jakub Kicinski Reviewed-by: Jiri Pirko --- net/core/dev.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 1025dc79bc49..874c7daa81f5 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1057,7 +1057,7 @@ EXPORT_SYMBOL(dev_valid_name); * __dev_alloc_name - allocate a name for a device * @net: network namespace to allocate the device name in * @name: name format string - * @buf: scratch buffer and result name string + * @res: result name string * * Passed a format string - eg "lt%d" it will try and find a suitable * id. It scans list of devices to build up a free map, then chooses @@ -1068,13 +1068,14 @@ EXPORT_SYMBOL(dev_valid_name); * Returns the number of the unit assigned or a negative errno code. */ -static int __dev_alloc_name(struct net *net, const char *name, char *buf) +static int __dev_alloc_name(struct net *net, const char *name, char *res) { int i = 0; const char *p; const int max_netdevices = 8*PAGE_SIZE; unsigned long *inuse; struct net_device *d; + char buf[IFNAMSIZ]; if (!dev_valid_name(name)) return -EINVAL; @@ -1124,8 +1125,10 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf) } snprintf(buf, IFNAMSIZ, name, i); - if (!netdev_name_in_use(net, buf)) + if (!netdev_name_in_use(net, buf)) { + strscpy(res, buf, IFNAMSIZ); return i; + } /* It is possible to run out of possible slots * when the name is long and there isn't enough space left @@ -1154,20 +1157,6 @@ static int dev_prep_valid_name(struct net *net, struct net_device *dev, return 0; } -static int dev_alloc_name_ns(struct net *net, - struct net_device *dev, - const char *name) -{ - char buf[IFNAMSIZ]; - int ret; - - BUG_ON(!net); - ret = __dev_alloc_name(net, name, buf); - if (ret >= 0) - strscpy(dev->name, buf, IFNAMSIZ); - return ret; -} - /** * dev_alloc_name - allocate a name for a device * @dev: device @@ -1184,20 +1173,14 @@ static int dev_alloc_name_ns(struct net *net, int dev_alloc_name(struct net_device *dev, const char *name) { - return dev_alloc_name_ns(dev_net(dev), dev, name); + return __dev_alloc_name(dev_net(dev), name, dev->name); } EXPORT_SYMBOL(dev_alloc_name); static int dev_get_valid_name(struct net *net, struct net_device *dev, const char *name) { - char buf[IFNAMSIZ]; - int ret; - - ret = dev_prep_valid_name(net, dev, name, buf); - if (ret >= 0) - strscpy(dev->name, buf, IFNAMSIZ); - return ret; + return dev_prep_valid_name(net, dev, name, dev->name); } /** From patchwork Fri Oct 20 01:18:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13429955 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B21C8651 for ; Fri, 20 Oct 2023 01:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fBqNsF10" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFFCDC433C8; Fri, 20 Oct 2023 01:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764739; bh=f95JIzztzdYYksSOam+CAsXzVDRhrcugWJ0tZQSRL6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fBqNsF10F2KMzEu6xA8EiCeKmJJX/iikt4ySP3l+KmPRUYlY33VY7gtXKxEXb5bwz 3R+J0OwP1jyYzxHme4S+SxHNTbAE2nydyfwnmqdIrGlJykNMDoKpX1NeRLZCSsTrV1 jYITTSGqt3Co+z+Q3GHJemrrEnqE+uFC3gmKopZSpKVJfiZVQ4jXEOFZD6hukmRqn9 vhQ4PyDANCu/Sx4LEBeCbVm/FZwaFqHxyotWHlAw34iBmYA9W7O4IeRCr6liqXrHXC NII1tCWma88IwOHKc8XHONNt3rM+LJqaFOlyqHgEHI/BmVNnoEgfYu2ecnAJQYuFPs KNhv0wLmk5FGA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, johannes.berg@intel.com, mpe@ellerman.id.au, j@w1.fi, jiri@resnulli.us Subject: [PATCH net-next 2/6] net: make dev_alloc_name() call dev_prep_valid_name() Date: Thu, 19 Oct 2023 18:18:52 -0700 Message-ID: <20231020011856.3244410-3-kuba@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020011856.3244410-1-kuba@kernel.org> References: <20231020011856.3244410-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org __dev_alloc_name() handles both the sprintf and non-sprintf target names. This complicates the code. dev_prep_valid_name() already handles the non-sprintf case, before calling __dev_alloc_name(), make the only other caller also go thru dev_prep_valid_name(). This way we can drop the non-sprintf handling in __dev_alloc_name() in one of the next changes. commit 55a5ec9b7710 ("Revert "net: core: dev_get_valid_name is now the same as dev_alloc_name_ns"") and commit 029b6d140550 ("Revert "net: core: maybe return -EEXIST in __dev_alloc_name"") tell us that we can't start returning -EEXIST from dev_alloc_name() on name duplicates. Bite the bullet and pass the expected errno to dev_prep_valid_name(). dev_prep_valid_name() must now propagate out the allocated id for printf names. Signed-off-by: Jakub Kicinski Reviewed-by: Jiri Pirko --- net/core/dev.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 874c7daa81f5..004e9f26b160 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1137,19 +1137,18 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res) return -ENFILE; } +/* Returns negative errno or allocated unit id (see __dev_alloc_name()) */ static int dev_prep_valid_name(struct net *net, struct net_device *dev, - const char *want_name, char *out_name) + const char *want_name, char *out_name, + int dup_errno) { - int ret; - if (!dev_valid_name(want_name)) return -EINVAL; if (strchr(want_name, '%')) { - ret = __dev_alloc_name(net, want_name, out_name); - return ret < 0 ? ret : 0; + return __dev_alloc_name(net, want_name, out_name); } else if (netdev_name_in_use(net, want_name)) { - return -EEXIST; + return -dup_errno; } else if (out_name != want_name) { strscpy(out_name, want_name, IFNAMSIZ); } @@ -1173,14 +1172,17 @@ static int dev_prep_valid_name(struct net *net, struct net_device *dev, int dev_alloc_name(struct net_device *dev, const char *name) { - return __dev_alloc_name(dev_net(dev), name, dev->name); + return dev_prep_valid_name(dev_net(dev), dev, name, dev->name, ENFILE); } EXPORT_SYMBOL(dev_alloc_name); static int dev_get_valid_name(struct net *net, struct net_device *dev, const char *name) { - return dev_prep_valid_name(net, dev, name, dev->name); + int ret; + + ret = dev_prep_valid_name(net, dev, name, dev->name, EEXIST); + return ret < 0 ? ret : 0; } /** @@ -11118,7 +11120,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, /* We get here if we can't use the current device name */ if (!pat) goto out; - err = dev_prep_valid_name(net, dev, pat, new_name); + err = dev_prep_valid_name(net, dev, pat, new_name, EEXIST); if (err < 0) goto out; } From patchwork Fri Oct 20 01:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13429956 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0089F808 for ; Fri, 20 Oct 2023 01:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mIcd0zSD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66DFDC433CB; Fri, 20 Oct 2023 01:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764739; bh=lL4gbfWmP27dPiZgO+7HF5Cy++dpF+1q2A/5lFk9Xc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIcd0zSDJ1aqpgZIc+MLU74rxoL2ocZuxcFlak20U1GDmVgZ+KmSM5SZhBV9fHV4b eUD/permyBbMOfwLOzUWlKR95zrv3cMIcnCYtIxSVb+0Y7MgeAy4Did11qpg15Xv/T swiylSz8P6UKS9Md+N1BrpKnMzMczHZi7LdKde2JMzB3eLahJTsT2Q7scnj+TPwXqY ARu8sET6nIyVvLDVVjQMH3/ImaylPt+2WQu1znHGd7VEkTouCQ8JN7FEHZvsSKD4rl tQK517rnParwSQIVg+1E975SENaVSLhfR3s7KYmZ0zRp2OU4XEsOS4vx8tciAFRY6o Zna7KJtAcEaKQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, johannes.berg@intel.com, mpe@ellerman.id.au, j@w1.fi, jiri@resnulli.us Subject: [PATCH net-next 3/6] net: reduce indentation of __dev_alloc_name() Date: Thu, 19 Oct 2023 18:18:53 -0700 Message-ID: <20231020011856.3244410-4-kuba@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020011856.3244410-1-kuba@kernel.org> References: <20231020011856.3244410-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org All callers of __dev_valid_name() go thru dev_prep_valid_name() which handles the non-printf case. Focus __dev_alloc_name() on the sprintf case, remove the indentation level. Minor functional change of returning -EINVAL if % is not found, which should now never happen. Signed-off-by: Jakub Kicinski Reviewed-by: Jiri Pirko --- net/core/dev.c | 56 +++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 004e9f26b160..bbfb02b4a228 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1080,50 +1080,46 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res) if (!dev_valid_name(name)) return -EINVAL; + /* Verify the string as this thing may have come from the user. + * There must be one "%d" and no other "%" characters. + */ p = strchr(name, '%'); - if (p) { - /* - * Verify the string as this thing may have come from - * the user. There must be either one "%d" and no other "%" - * characters. - */ - if (p[1] != 'd' || strchr(p + 2, '%')) - return -EINVAL; + if (!p || p[1] != 'd' || strchr(p + 2, '%')) + return -EINVAL; - /* Use one page as a bit array of possible slots */ - inuse = bitmap_zalloc(max_netdevices, GFP_ATOMIC); - if (!inuse) - return -ENOMEM; + /* Use one page as a bit array of possible slots */ + inuse = bitmap_zalloc(max_netdevices, GFP_ATOMIC); + if (!inuse) + return -ENOMEM; - for_each_netdev(net, d) { - struct netdev_name_node *name_node; + for_each_netdev(net, d) { + struct netdev_name_node *name_node; - netdev_for_each_altname(d, name_node) { - if (!sscanf(name_node->name, name, &i)) - continue; - if (i < 0 || i >= max_netdevices) - continue; - - /* avoid cases where sscanf is not exact inverse of printf */ - snprintf(buf, IFNAMSIZ, name, i); - if (!strncmp(buf, name_node->name, IFNAMSIZ)) - __set_bit(i, inuse); - } - if (!sscanf(d->name, name, &i)) + netdev_for_each_altname(d, name_node) { + if (!sscanf(name_node->name, name, &i)) continue; if (i < 0 || i >= max_netdevices) continue; - /* avoid cases where sscanf is not exact inverse of printf */ + /* avoid cases where sscanf is not exact inverse of printf */ snprintf(buf, IFNAMSIZ, name, i); - if (!strncmp(buf, d->name, IFNAMSIZ)) + if (!strncmp(buf, name_node->name, IFNAMSIZ)) __set_bit(i, inuse); } + if (!sscanf(d->name, name, &i)) + continue; + if (i < 0 || i >= max_netdevices) + continue; - i = find_first_zero_bit(inuse, max_netdevices); - bitmap_free(inuse); + /* avoid cases where sscanf is not exact inverse of printf */ + snprintf(buf, IFNAMSIZ, name, i); + if (!strncmp(buf, d->name, IFNAMSIZ)) + __set_bit(i, inuse); } + i = find_first_zero_bit(inuse, max_netdevices); + bitmap_free(inuse); + snprintf(buf, IFNAMSIZ, name, i); if (!netdev_name_in_use(net, buf)) { strscpy(res, buf, IFNAMSIZ); From patchwork Fri Oct 20 01:18:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13429957 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75909ECE for ; Fri, 20 Oct 2023 01:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E9iKs/1I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2A1EC433CA; Fri, 20 Oct 2023 01:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764740; bh=4nxRFy7uAeXFMKE//Wszpq3lf9oOTfgFd8lrOhnblBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E9iKs/1IdZwt0/pcOsobUvDNteQpksrGPkVz996DCJIj008LpMgFifuzFblCXGv9q xYWtbIek8fr4UFPJmY7rI32b5tqYjTlFjsKcdRar9BvaEF+QO+y0WcOEGaDO2lQv0F WXKvjP3Uvj05H/V2iMv5Qvo93gcUCjUSJxWKJFELcS8822Cxf0TuVoTo7BX0xl3k5O x2um2Bq1AYVvCc39i7cDAURFAg9T94kkugaMNxhckyQ3N9ZZElIA8AdTnfFDr0YSJ7 FdqAUpjkpj0PZ4d6ACPPKgewHqKSsoZUg8XKweSLzL/b3YxDj+gfMSPU5pN/0b+XLP lp3IkqSfsj1Pw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, johannes.berg@intel.com, mpe@ellerman.id.au, j@w1.fi, jiri@resnulli.us Subject: [PATCH net-next 4/6] net: trust the bitmap in __dev_alloc_name() Date: Thu, 19 Oct 2023 18:18:54 -0700 Message-ID: <20231020011856.3244410-5-kuba@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020011856.3244410-1-kuba@kernel.org> References: <20231020011856.3244410-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Prior to restructuring __dev_alloc_name() handled both printf and non-printf names. In a clever attempt at code reuse it always prints the name into a buffer and checks if it's a duplicate. Trust the bitmap, and return an error if its full. Signed-off-by: Jakub Kicinski --- net/core/dev.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index bbfb02b4a228..d2698b4bbad4 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1119,18 +1119,11 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res) i = find_first_zero_bit(inuse, max_netdevices); bitmap_free(inuse); + if (i == max_netdevices) + return -ENFILE; - snprintf(buf, IFNAMSIZ, name, i); - if (!netdev_name_in_use(net, buf)) { - strscpy(res, buf, IFNAMSIZ); - return i; - } - - /* It is possible to run out of possible slots - * when the name is long and there isn't enough space left - * for the digits, or if all bits are used. - */ - return -ENFILE; + snprintf(res, IFNAMSIZ, name, i); + return i; } /* Returns negative errno or allocated unit id (see __dev_alloc_name()) */ From patchwork Fri Oct 20 01:18:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13429958 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5437117D3 for ; Fri, 20 Oct 2023 01:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TGp4afcy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71588C433C8; Fri, 20 Oct 2023 01:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764740; bh=N7q0nY7TNQy4Cbw7fiBk47VxXEXIPG5CF+M3HOATVv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGp4afcyqQXoXn81MK7TdHEb7geiCbOGTRA4opOIEaXg5SJQuB4cgHAJ+CYXEzqfs sK/uuz52mRbhWL3ePSSFUZeTZYjD2a8yHcdHMfHoFspSZdXnXFr5SDhSVruCQ34OQ7 EwhVfsFtyPJUN6rzZ+XjHSR+EyzSSqtd4yEs4HZgt2ocNoAFh4NYDBpKuHTKnO6unS SV3iQbHAiAENhtS2NjPx/bgKKVoaPKL7E3Pqwq0eKz7X52I7t1O6+z7PBt7Tzl37Lf 7fbuNfuGQkkNtYatgJS/GV6Y0zzWJauHdD974BdrWGRFmJdnFRGWfRbu173r3e2XJ3 Us1AkA8pzrxuA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, johannes.berg@intel.com, mpe@ellerman.id.au, j@w1.fi, jiri@resnulli.us Subject: [PATCH net-next 5/6] net: remove dev_valid_name() check from __dev_alloc_name() Date: Thu, 19 Oct 2023 18:18:55 -0700 Message-ID: <20231020011856.3244410-6-kuba@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020011856.3244410-1-kuba@kernel.org> References: <20231020011856.3244410-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org __dev_alloc_name() is only called by dev_prep_valid_name(), which already checks that name is valid. Signed-off-by: Jakub Kicinski Reviewed-by: Jiri Pirko --- net/core/dev.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index d2698b4bbad4..0830f2967221 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1077,9 +1077,6 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res) struct net_device *d; char buf[IFNAMSIZ]; - if (!dev_valid_name(name)) - return -EINVAL; - /* Verify the string as this thing may have come from the user. * There must be one "%d" and no other "%" characters. */ From patchwork Fri Oct 20 01:18:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13429959 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA7061C02 for ; Fri, 20 Oct 2023 01:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ot5K9W25" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 021AFC433C7; Fri, 20 Oct 2023 01:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697764741; bh=WkjlebE+uQgY9ZblbfFKEjPqmY+WADIj8s8n39W8FlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ot5K9W25EtIWZUcuoN9f38vRTxCQgtfogvoHeDiI373vxvST8tI+iSCqbIzRloqR0 AgI3xhqUg1mDGgqYhYqv8tOiq88MwCAgjXI0ZcFX3Xkb78YPCAtBMq27Zl16uqHK1H qgO3nUok7NJdjrMxwPiHXuf65EZ1R5IS5lbV9jocW1z8faBN2zkbFjXGKwaohPqQ7g BObE4Gzj8VIc7SmIl+21dTmfGRcLANOTE07Ie7QyU8Ka4wW/1M5gumxK5lNGE8Hal5 1nIWHqk4w59U5yndIEnh3dzoEU7G4defhpNODAa3BU/U4B+Hwu5hnW7+kCheOYxT7N bEG9Z+M5A8Ldw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, johannes.berg@intel.com, mpe@ellerman.id.au, j@w1.fi, jiri@resnulli.us Subject: [PATCH net-next 6/6] net: remove else after return in dev_prep_valid_name() Date: Thu, 19 Oct 2023 18:18:56 -0700 Message-ID: <20231020011856.3244410-7-kuba@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020011856.3244410-1-kuba@kernel.org> References: <20231020011856.3244410-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Remove unnecessary else clauses after return. I copied this if / else construct from somewhere, it makes the code harder to read. Signed-off-by: Jakub Kicinski Reviewed-by: Jiri Pirko --- net/core/dev.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 0830f2967221..a37a932a3e14 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1131,14 +1131,13 @@ static int dev_prep_valid_name(struct net *net, struct net_device *dev, if (!dev_valid_name(want_name)) return -EINVAL; - if (strchr(want_name, '%')) { + if (strchr(want_name, '%')) return __dev_alloc_name(net, want_name, out_name); - } else if (netdev_name_in_use(net, want_name)) { - return -dup_errno; - } else if (out_name != want_name) { - strscpy(out_name, want_name, IFNAMSIZ); - } + if (netdev_name_in_use(net, want_name)) + return -dup_errno; + if (out_name != want_name) + strscpy(out_name, want_name, IFNAMSIZ); return 0; }