diff mbox series

[net-next] net: core: Remove the dup_errno parameter in dev_prep_valid_name()

Message ID 20240618131743.2690-1-yajun.deng@linux.dev (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: core: Remove the dup_errno parameter in dev_prep_valid_name() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 845 this patch: 845
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 849 this patch: 849
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 854 this patch: 854
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 44 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 79 this patch: 79
netdev/source_inline success Was 0 now: 0

Commit Message

Yajun Deng June 18, 2024, 1:17 p.m. UTC
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(-)

Comments

Jiri Pirko June 18, 2024, 2:05 p.m. UTC | #1
Tue, Jun 18, 2024 at 03:17:43PM CEST, yajun.deng@linux.dev wrote:
>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>

Why not.

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Jakub Kicinski June 18, 2024, 2:48 p.m. UTC | #2
On Tue, 18 Jun 2024 21:17:43 +0800 Yajun Deng wrote:
> netdev_name_in_use() return -EEXIST makes more sense if it's not NULL.

netdev_name_in_use() returns bool.

> But dev_alloc_name() should keep the -ENFILE errno.

And it does.

I don't understand what problem you're trying to fix.
The code is fine as is.
Yajun Deng June 19, 2024, 1:55 a.m. UTC | #3
June 18, 2024 at 10:48 PM, "Jakub Kicinski" <kuba@kernel.org> wrote:



> 
> On Tue, 18 Jun 2024 21:17:43 +0800 Yajun Deng wrote:
> 
> > 
> > netdev_name_in_use() return -EEXIST makes more sense if it's not NULL.
> > 
> 
> netdev_name_in_use() returns bool.
> 

I should say the netdev_name_in_use() in dev_prep_valid_name() return -EEXIST. 

> > 
> > But dev_alloc_name() should keep the -ENFILE errno.
> > 
> 
> And it does.
> 
> I don't understand what problem you're trying to fix.
> 
> The code is fine as is.
>

This is not a fix. 

There are three callers to dev_prep_valid_name(), only dev_alloc_name() needs
to replace -EEXIST with -ENFILE. We shouldn't add an extra parameter for this,
because it's not necessary for the other callers.

If we do it in dev_alloc_name(), the other callers can save a parameter.
diff mbox series

Patch

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;
 	}