Skip to contentSkip to conversation

PM/sleep: fix return value of __setup handler

PATCH Applied Randy Dunlap 2 participants 2 messages Feb 28, 2022 – Mar 1, 2022

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

PATCH 1/1 PM/sleep: fix return value of __setup handler

If an invalid option is given for "test_suspend=<option>", the entire string is added to init's environment, so return 1 instead of 0 from the __setup handler.

Unknown kernel command line parameters "BOOT_IMAGE=/boot/bzImage-517rc5
test_suspend=invalid"

and

Run /sbin/init as init process
with arguments:
/sbin/init
with environment:

     HOME=/
     TERM=linux
     BOOT_IMAGE=/boot/bzImage-517rc5
     test_suspend=invalid
Fixes 2ce986892faf ("PM / sleep: Enhance test_suspend option with repeat capability")
Fixes 27ddcc6596e5 ("PM / sleep: Add state field to pm_states[] entries")
Fixes a9d7052363a6 ("PM: Separate suspend to RAM functionality from core")
Link lore.kernel.org/r/[email protected]
Cc Srinivas Pandruvada <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>

---
Would someone like warning messages added in case of bad option strings?

 kernel/power/suspend_test.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/suspend_test.c +4 -4
@@ -157,22 +157,22 @@ static int __init setup_test_suspend(cha
 	value++;
 	suspend_type = strsep(&value, ",");
 	if (!suspend_type)
-		return 0;
+		return 1;
 
 	repeat = strsep(&value, ",");
 	if (repeat) {
 		if (kstrtou32(repeat, 0, &test_repeat_count_max))
-			return 0;
+			return 1;
 	}
 
 	for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
 		if (!strcmp(pm_labels[i], suspend_type)) {
 			test_state_label = pm_labels[i];
-			return 0;
+			return 1;
 		}
 
 	printk(warn_bad_state, suspend_type);
-	return 0;
+	return 1;
 }
 __setup("test_suspend", setup_test_suspend);
 
maintainer Applied
#1 lore raw
Quoted 54 lines · Randy Dunlap

If an invalid option is given for "test_suspend=<option>", the entire string is added to init's environment, so return 1 instead of 0 from the __setup handler.

Unknown kernel command line parameters "BOOT_IMAGE=/boot/bzImage-517rc5
test_suspend=invalid"

and

Run /sbin/init as init process
with arguments:
/sbin/init
with environment:

     HOME=/
     TERM=linux
     BOOT_IMAGE=/boot/bzImage-517rc5
     test_suspend=invalid
Fixes 2ce986892faf ("PM / sleep: Enhance test_suspend option with repeat capability")
Fixes 27ddcc6596e5 ("PM / sleep: Add state field to pm_states[] entries")
Fixes a9d7052363a6 ("PM: Separate suspend to RAM functionality from core")
Link lore.kernel.org/r/[email protected]
Cc Srinivas Pandruvada <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>

---
Would someone like warning messages added in case of bad option strings?

 kernel/power/suspend_test.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/power/suspend_test.c +2 -2
@@ -157,22 +157,22 @@ static int __init setup_test_suspend(cha
        value++;
        suspend_type = strsep(&value, ",");
        if (!suspend_type)
-               return 0;
+               return 1;
 
        repeat = strsep(&value, ",");
        if (repeat) {
                if (kstrtou32(repeat, 0, &test_repeat_count_max))
-                       return 0;
+                       return 1;
        }
 
        for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
                if (!strcmp(pm_labels[i], suspend_type)) {

kernel/power/suspend_test.c static int __init setup_test_suspend(cha · line 177

Quoted 10 lines
kernel/power/suspend_test.c +2 -2
                        test_state_label = pm_labels[i];
-                       return 0;
+                       return 1;
                }
 
        printk(warn_bad_state, suspend_type);
-       return 0;
+       return 1;
 }
 __setup("test_suspend", setup_test_suspend);

Applied as 5.18 material, thanks!