All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clocksource: acpi_pm: fix return value of __setup handler
@ 2022-03-09  4:03 Randy Dunlap
  2022-03-09  8:56 ` Dan Carpenter
  2022-03-12  7:09 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Randy Dunlap @ 2022-03-09  4:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: patches, Randy Dunlap, Dan Carpenter, John Stultz,
	Daniel Lezcano, Thomas Gleixner, Rafael J. Wysocki

__setup() handlers should return 1 to obsolete_checksetup() in
init/main.c to indicate that the boot option has been handled.
A return of 0 causes the boot option/value to be listed as an Unknown
kernel parameter and added to init's (limited) environment strings.

The __setup() handler interface isn't meant to handle negative return
values -- they are non-zero, so they mean "handled" (like a return
value of 1 does), but that's just a quirk. So return 1 from
parse_pmtmr(). Also print a warning message if kstrtouint() returns
an error.

Fixes: 60e3bf14d4e2 ("clocksource: clean up parse_pmtmr()")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
From: Igor Zhbanov <i.zhbanov@omprussia.ru>
Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
---
 drivers/clocksource/acpi_pm.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- linux-next-20220308.orig/drivers/clocksource/acpi_pm.c
+++ linux-next-20220308/drivers/clocksource/acpi_pm.c
@@ -229,8 +229,10 @@ static int __init parse_pmtmr(char *arg)
 	int ret;
 
 	ret = kstrtouint(arg, 16, &base);
-	if (ret)
-		return ret;
+	if (ret) {
+		pr_warn("PMTMR: invalid 'pmtmr=' value: '%s'\n", arg);
+		return 1;
+	}
 
 	pr_info("PMTMR IOPort override: 0x%04x -> 0x%04x\n", pmtmr_ioport,
 		base);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clocksource: acpi_pm: fix return value of __setup handler
  2022-03-09  4:03 [PATCH] clocksource: acpi_pm: fix return value of __setup handler Randy Dunlap
@ 2022-03-09  8:56 ` Dan Carpenter
  2022-03-12  7:09 ` Dan Carpenter
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-03-09  8:56 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: linux-kernel, patches, John Stultz, Daniel Lezcano,
	Thomas Gleixner, Rafael J. Wysocki

On Tue, Mar 08, 2022 at 08:03:01PM -0800, Randy Dunlap wrote:
> __setup() handlers should return 1 to obsolete_checksetup() in
> init/main.c to indicate that the boot option has been handled.
> A return of 0 causes the boot option/value to be listed as an Unknown
> kernel parameter and added to init's (limited) environment strings.
> 
> The __setup() handler interface isn't meant to handle negative return
> values -- they are non-zero, so they mean "handled" (like a return
> value of 1 does), but that's just a quirk. So return 1 from
> parse_pmtmr(). Also print a warning message if kstrtouint() returns
> an error.

Everyone probably predicted that this API was/is going to cause bugs?

Smatch treats every (struct obs_kernel_param)->setup_func function as
the same so it's impossible to write a static checker for this because
in do_early_param() it expects zero on success and obsolete_checksetup()
has expects 1 on success and also on failure.

init/main.c
   732        static int __init do_early_param(char *param, char *val,
   733                                         const char *unused __always_unused,
   734                                         void *arg __always_unused)
   735        {
   736                const struct obs_kernel_param *p;
   737
   738                for (p = __setup_start; p < __setup_end; p++) {
   739                        if ((p->early && parameq(param, p->str)) ||
   740                            (strcmp(param, "console") == 0 &&
   741                             strcmp(p->str, "earlycon") == 0)
   742                        ) {
   743                                if (p->setup_func(val) != 0)
   744                                        pr_warn("Malformed early option '%s'\n", param);
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   745                        }
   746                }
   747                /* We accept everything at this stage. */
   748                return 0;
   749        }

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clocksource: acpi_pm: fix return value of __setup handler
  2022-03-09  4:03 [PATCH] clocksource: acpi_pm: fix return value of __setup handler Randy Dunlap
  2022-03-09  8:56 ` Dan Carpenter
@ 2022-03-12  7:09 ` Dan Carpenter
  2022-03-12 19:23   ` Randy Dunlap
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-03-12  7:09 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: linux-kernel, patches, John Stultz, Daniel Lezcano,
	Thomas Gleixner, Rafael J. Wysocki

On Tue, Mar 08, 2022 at 08:03:01PM -0800, Randy Dunlap wrote:
> __setup() handlers should return 1 to obsolete_checksetup() in
> init/main.c to indicate that the boot option has been handled.
> A return of 0 causes the boot option/value to be listed as an Unknown
> kernel parameter and added to init's (limited) environment strings.
> 
> The __setup() handler interface isn't meant to handle negative return
> values -- they are non-zero, so they mean "handled" (like a return
> value of 1 does), but that's just a quirk. So return 1 from
> parse_pmtmr(). Also print a warning message if kstrtouint() returns
> an error.
> 
> Fixes: 60e3bf14d4e2 ("clocksource: clean up parse_pmtmr()")

I was wondering why I was CC'd on this.

This fixes tag is wrong...  My patch just cleaned up the function.
The original code returned negative error codes already.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] clocksource: acpi_pm: fix return value of __setup handler
  2022-03-12  7:09 ` Dan Carpenter
@ 2022-03-12 19:23   ` Randy Dunlap
  0 siblings, 0 replies; 4+ messages in thread
From: Randy Dunlap @ 2022-03-12 19:23 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: linux-kernel, patches, John Stultz, Daniel Lezcano,
	Thomas Gleixner, Rafael J. Wysocki



On 3/11/22 23:09, Dan Carpenter wrote:
> On Tue, Mar 08, 2022 at 08:03:01PM -0800, Randy Dunlap wrote:
>> __setup() handlers should return 1 to obsolete_checksetup() in
>> init/main.c to indicate that the boot option has been handled.
>> A return of 0 causes the boot option/value to be listed as an Unknown
>> kernel parameter and added to init's (limited) environment strings.
>>
>> The __setup() handler interface isn't meant to handle negative return
>> values -- they are non-zero, so they mean "handled" (like a return
>> value of 1 does), but that's just a quirk. So return 1 from
>> parse_pmtmr(). Also print a warning message if kstrtouint() returns
>> an error.
>>
>> Fixes: 60e3bf14d4e2 ("clocksource: clean up parse_pmtmr()")
> 
> I was wondering why I was CC'd on this.
> 
> This fixes tag is wrong...  My patch just cleaned up the function.
> The original code returned negative error codes already.

OK, thanks for the info.

-- 
~Randy

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-12 19:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09  4:03 [PATCH] clocksource: acpi_pm: fix return value of __setup handler Randy Dunlap
2022-03-09  8:56 ` Dan Carpenter
2022-03-12  7:09 ` Dan Carpenter
2022-03-12 19:23   ` Randy Dunlap

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.