* [PATCH net-next v2] net: core: Remove the dup_errno parameter in dev_prep_valid_name()
@ 2024-06-27 13:41 Yajun Deng
2024-06-27 22:03 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Yajun Deng @ 2024-06-27 13:41 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni
Cc: netdev, linux-kernel, Yajun Deng, Jiri Pirko
netdev_name_in_use() in dev_prep_valid_name() return -EEXIST makes
more sense if it's not NULL, but dev_alloc_name() should keep the
-ENFILE errno.
There are three callers to dev_prep_valid_name(), the dup_errno
parameter is only for dev_alloc_name, it's not necessary for the other
callers.
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>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
v2: Make the commit more detailed.
v1: https://lore.kernel.org/all/20240618131743.2690-1-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 0a23d7da7fbc..00e8c785e5ee 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1153,8 +1153,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;
@@ -1163,7 +1162,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;
@@ -1185,7 +1184,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);
@@ -1194,7 +1196,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;
}
@@ -11446,7 +11448,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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next v2] net: core: Remove the dup_errno parameter in dev_prep_valid_name()
2024-06-27 13:41 [PATCH net-next v2] net: core: Remove the dup_errno parameter in dev_prep_valid_name() Yajun Deng
@ 2024-06-27 22:03 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2024-06-27 22:03 UTC (permalink / raw)
To: Yajun Deng; +Cc: davem, edumazet, pabeni, netdev, linux-kernel, Jiri Pirko
On Thu, 27 Jun 2024 21:41:31 +0800 Yajun Deng wrote:
> netdev_name_in_use() in dev_prep_valid_name() return -EEXIST makes
> more sense if it's not NULL, but dev_alloc_name() should keep the
> -ENFILE errno.
>
> There are three callers to dev_prep_valid_name(), the dup_errno
> parameter is only for dev_alloc_name, it's not necessary for the other
> callers.
>
> Remove the dup_errno parameter in dev_prep_valid_name() and add a
> conditional operator to dev_alloc_name(), replace -EEXIST with
> -ENFILE.
Let me be more direct this time - I like this code the way I wrote it.
Please leave it be.
--
pw-bot: reject
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-27 22:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-27 13:41 [PATCH net-next v2] net: core: Remove the dup_errno parameter in dev_prep_valid_name() Yajun Deng
2024-06-27 22:03 ` Jakub Kicinski
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).