From: Yajun Deng <yajun.deng@linux.dev>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH net-next] net: core: Remove the dup_errno parameter in dev_prep_valid_name()
Date: Tue, 18 Jun 2024 21:17:43 +0800 [thread overview]
Message-ID: <20240618131743.2690-1-yajun.deng@linux.dev> (raw)
netdev_name_in_use() return -EEXIST makes more sense if it's not NULL.
But dev_alloc_name() should keep the -ENFILE errno.
Remove the dup_errno parameter in dev_prep_valid_name() and add a
conditional operator to dev_alloc_name(), replace -EEXIST with
-ENFILE.
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
net/core/dev.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index c361a7b69da8..29e4c786cb8a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1151,8 +1151,7 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res)
/* 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,
- int dup_errno)
+ const char *want_name, char *out_name)
{
if (!dev_valid_name(want_name))
return -EINVAL;
@@ -1161,7 +1160,7 @@ static int dev_prep_valid_name(struct net *net, struct net_device *dev,
return __dev_alloc_name(net, want_name, out_name);
if (netdev_name_in_use(net, want_name))
- return -dup_errno;
+ return -EEXIST;
if (out_name != want_name)
strscpy(out_name, want_name, IFNAMSIZ);
return 0;
@@ -1183,7 +1182,10 @@ 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_prep_valid_name(dev_net(dev), dev, name, dev->name, ENFILE);
+ int ret;
+
+ ret = dev_prep_valid_name(dev_net(dev), dev, name, dev->name);
+ return ret == -EEXIST ? -ENFILE : ret;
}
EXPORT_SYMBOL(dev_alloc_name);
@@ -1192,7 +1194,7 @@ static int dev_get_valid_name(struct net *net, struct net_device *dev,
{
int ret;
- ret = dev_prep_valid_name(net, dev, name, dev->name, EEXIST);
+ ret = dev_prep_valid_name(net, dev, name, dev->name);
return ret < 0 ? ret : 0;
}
@@ -11395,7 +11397,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, EEXIST);
+ err = dev_prep_valid_name(net, dev, pat, new_name);
if (err < 0)
goto out;
}
--
2.25.1
next reply other threads:[~2024-06-18 13:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 13:17 Yajun Deng [this message]
2024-06-18 14:05 ` [PATCH net-next] net: core: Remove the dup_errno parameter in dev_prep_valid_name() Jiri Pirko
2024-06-18 14:48 ` Jakub Kicinski
2024-06-19 1:55 ` Yajun Deng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240618131743.2690-1-yajun.deng@linux.dev \
--to=yajun.deng@linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).