Skip to contentSkip to conversation

net: sxgbe: fix return value of __setup handler

PATCH Applied Randy Dunlap 3 participants 5 messages Feb 24, 2022 – Feb 25, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sxgbe: fix return value of __setup handler

__setup() handlers should return 1 on success, i.e., the parameter has been handled. A return of 0 causes the "option=value" string to be added to init's environment strings, polluting it.

Fixes acc18c147b22 ("net: sxgbe: add EEE(Energy Efficient Ethernet) for Samsung sxgbe")
Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Link lore.kernel.org/r/[email protected]
Cc Siva Reddy <[email protected]>
Cc Girish K S <[email protected]>
Cc Byungho An <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Jakub Kicinski <[email protected]>
---
 drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +3 -3
@@ -2285,18 +2285,18 @@ static int __init sxgbe_cmdline_opt(char
 	char *opt;
 
 	if (!str || !*str)
-		return -EINVAL;
+		return 1;
 	while ((opt = strsep(&str, ",")) != NULL) {
 		if (!strncmp(opt, "eee_timer:", 10)) {
 			if (kstrtoint(opt + 10, 0, &eee_timer))
 				goto err;
 		}
 	}
-	return 0;
+	return 1;
 
 err:
 	pr_err("%s: ERROR broken module parameter conversion\n", __func__);
-	return -EINVAL;
+	return 1;
 }
 
 __setup("sxgbeeth=", sxgbe_cmdline_opt);
maintainer
#1 lore raw
Quoted 3 lines · On Wed, 23 Feb 2022 19:35:28 -0800 Randy Dunlap wrote:

__setup() handlers should return 1 on success, i.e., the parameter has been handled. A return of 0 causes the "option=value" string to be added to init's environment strings, polluting it.

Meaning early_param_on_off() also returns the wrong thing? Or that's different?

Quoted 20 lines
Fixes acc18c147b22 ("net: sxgbe: add EEE(Energy Efficient Ethernet) for Samsung sxgbe")
Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Link lore.kernel.org/r/[email protected]
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +1 -1
@@ -2285,18 +2285,18 @@ static int __init sxgbe_cmdline_opt(char
 	char *opt;
 
 	if (!str || !*str)
-		return -EINVAL;
+		return 1;
 	while ((opt = strsep(&str, ",")) != NULL) {
 		if (!strncmp(opt, "eee_timer:", 10)) {
 			if (kstrtoint(opt + 10, 0, &eee_timer))
 				goto err;
 		}
 	}

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c static int __init sxgbe_cmdline_opt(char · line 2302

Quoted 10 lines
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +2 -2
-	return 0;
+	return 1;
 
 err:
 	pr_err("%s: ERROR broken module parameter conversion\n", __func__);
-	return -EINVAL;
+	return 1;
 }
 
 __setup("sxgbeeth=", sxgbe_cmdline_opt);

Was the option of making __setup() return void considered? Sounds like we always want to return 1 so what's the point?

#2 lore raw
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 23 Feb 2022 19:35:28 -0800 Randy Dunlap wrote:

__setup() handlers should return 1 on success, i.e., the parameter has been handled. A return of 0 causes the "option=value" string to be added to init's environment strings, polluting it.

Meaning early_param_on_off() also returns the wrong thing? Or that's different?

early_param() and its varieties are different -- 0 for success, else error.

Quoted 29 lines
Quoted 29 lines
Fixes acc18c147b22 ("net: sxgbe: add EEE(Energy Efficient Ethernet) for Samsung sxgbe")
Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Link lore.kernel.org/r/[email protected]
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +3 -3
@@ -2285,18 +2285,18 @@ static int __init sxgbe_cmdline_opt(char
 	char *opt;
 
 	if (!str || !*str)
-		return -EINVAL;
+		return 1;
 	while ((opt = strsep(&str, ",")) != NULL) {
 		if (!strncmp(opt, "eee_timer:", 10)) {
 			if (kstrtoint(opt + 10, 0, &eee_timer))
 				goto err;
 		}
 	}
-	return 0;
+	return 1;
 
 err:
 	pr_err("%s: ERROR broken module parameter conversion\n", __func__);
-	return -EINVAL;
+	return 1;
 }
 
Quoted 4 lines

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c static int __init sxgbe_cmdline_opt(char · line 2302

Quoted 1 line
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +0 -0
 __setup("sxgbeeth=", sxgbe_cmdline_opt);

Was the option of making __setup() return void considered? Sounds like we always want to return 1 so what's the point?

Well, AFAIK __setup() has been around forever (at least 22 years), so No, I don't think anyone has considered making it void.

Returning 1 or 0 gives kernel parameter writers the option of how error input is handled, although 0 is usually wrong. :)

Signature · 1 line
~Randy
maintainer
#3 lore raw
Quoted 10 lines · On Thu, 24 Feb 2022 23:30:42 -0800 Randy Dunlap wrote:
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 23 Feb 2022 19:35:28 -0800 Randy Dunlap wrote:

__setup() handlers should return 1 on success, i.e., the parameter has been handled. A return of 0 causes the "option=value" string to be added to init's environment strings, polluting it.

Meaning early_param_on_off() also returns the wrong thing? Or that's different?

early_param() and its varieties are different -- 0 for success, else error.

Making it an even stronger contender for the worst API ever award ;)

Quoted 34 lines
Quoted 29 lines
Quoted 29 lines
Fixes acc18c147b22 ("net: sxgbe: add EEE(Energy Efficient Ethernet) for Samsung sxgbe")
Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Link lore.kernel.org/r/[email protected]
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +3 -3
@@ -2285,18 +2285,18 @@ static int __init sxgbe_cmdline_opt(char
 	char *opt;
 
 	if (!str || !*str)
-		return -EINVAL;
+		return 1;
 	while ((opt = strsep(&str, ",")) != NULL) {
 		if (!strncmp(opt, "eee_timer:", 10)) {
 			if (kstrtoint(opt + 10, 0, &eee_timer))
 				goto err;
 		}
 	}
-	return 0;
+	return 1;
 
 err:
 	pr_err("%s: ERROR broken module parameter conversion\n", __func__);
-	return -EINVAL;
+	return 1;
 }
 
Quoted 4 lines

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c static int __init sxgbe_cmdline_opt(char · line 2302

Quoted 1 line
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +0 -0
 __setup("sxgbeeth=", sxgbe_cmdline_opt);  

Was the option of making __setup() return void considered? Sounds like we always want to return 1 so what's the point?

Quoted 5 lines

Well, AFAIK __setup() has been around forever (at least 22 years), so No, I don't think anyone has considered making it void.

Returning 1 or 0 gives kernel parameter writers the option of how error input is handled, although 0 is usually wrong. :)

Yeah, well, we've been making bus ->remove() functions void IIUC so why not this. That's separate from fixing the current incorrect uses tho, so let me apply both of the netdev fixes, thank you!

#4 lore raw
In reply to Randy Dunlap
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 15 lines · On Wed, 23 Feb 2022 19:35:28 -0800 you wrote:

__setup() handlers should return 1 on success, i.e., the parameter has been handled. A return of 0 causes the "option=value" string to be added to init's environment strings, polluting it.

Fixes acc18c147b22 ("net: sxgbe: add EEE(Energy Efficient Ethernet) for Samsung sxgbe")
Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Link lore.kernel.org/r/[email protected]
Cc Siva Reddy <[email protected]>
Cc Girish K S <[email protected]>
Cc Byungho An <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Jakub Kicinski <[email protected]>
Quoted 1 line

[...]

Here is the summary with links:
- net: sxgbe: fix return value of __setup handler

    https://git.kernel.org/netdev/net/c/50e06ddceeea

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html