mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Uros Bizjak <ubizjak@gmail.com>,
	Yue Haibing <yuehaibing@huawei.com>,
	"devzero@web.de" <devzero@web.de>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
	Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] x86/cmdline: Return 0 from cmdline_find_option_bool() for no cmdline
Date: Sat,  1 Aug 2026 14:54:41 +0200	[thread overview]
Message-ID: <20260801125444.18082-2-thorsten.blum@linux.dev> (raw)

cmdline_find_option_bool() is documented to return the position of the
option or 0 when the option is not found. However, the boot-time and
kernel-proper implementations return -1 when there is no command line,
and the real-mode wrapper also returns -1 when the command line is
inaccessible.

That makes normal boolean use of the helper wrong: callers testing the
return value directly treat an unavailable command line as if the option
was present.

Return 0 from cmdline_find_option_bool() for unavailable command lines.

Fixes: 32d0b9898029 ("x86 setup: early cmdline parser handle boolean options")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/x86/boot/boot.h    |  2 +-
 arch/x86/boot/cmdline.c |  6 +++---
 arch/x86/lib/cmdline.c  | 11 ++++++-----
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
index 8e3eab34dff4..b623572b6964 100644
--- a/arch/x86/boot/boot.h
+++ b/arch/x86/boot/boot.h
@@ -261,7 +261,7 @@ static inline int cmdline_find_option_bool(const char *option)
 	unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr;
 
 	if (cmd_line_ptr >= 0x100000)
-		return -1;      /* inaccessible */
+		return 0;	/* inaccessible */
 
 	return __cmdline_find_option_bool(cmd_line_ptr, option);
 }
diff --git a/arch/x86/boot/cmdline.c b/arch/x86/boot/cmdline.c
index 21d56ae83cdf..2418c9d0b5aa 100644
--- a/arch/x86/boot/cmdline.c
+++ b/arch/x86/boot/cmdline.c
@@ -94,8 +94,8 @@ int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *b
 /*
  * Find a boolean option (like quiet,noapic,nosmp....)
  *
- * Returns the position of that option (starts counting with 1)
- * or 0 on not found
+ * Returns the position of that option (starts counting with 1),
+ * or 0 if the option is not found or the command line is unavailable.
  */
 int __cmdline_find_option_bool(unsigned long cmdline_ptr, const char *option)
 {
@@ -110,7 +110,7 @@ int __cmdline_find_option_bool(unsigned long cmdline_ptr, const char *option)
 	} state = st_wordstart;
 
 	if (!cmdline_ptr)
-		return -1;      /* No command line */
+		return 0;	/* No command line */
 
 	cptr = cmdline_ptr & 0xf;
 	set_fs(cmdline_ptr >> 4);
diff --git a/arch/x86/lib/cmdline.c b/arch/x86/lib/cmdline.c
index c65cd5550454..0e40779a4729 100644
--- a/arch/x86/lib/cmdline.c
+++ b/arch/x86/lib/cmdline.c
@@ -23,10 +23,11 @@ static inline int myisspace(u8 c)
  * @max_cmdline_size: the maximum size of cmdline
  * @option: option string to look for
  *
- * Returns the position of that @option (starts counting with 1)
- * or 0 on not found.  @option will only be found if it is found
- * as an entire word in @cmdline.  For instance, if @option="car"
- * then a cmdline which contains "cart" will not match.
+ * Returns the position of that @option (starts counting with 1),
+ * or 0 if the option is not found or the command line is unavailable.
+ * @option will only be found if it is found as an entire word in
+ * @cmdline.  For instance, if @option="car" then a cmdline which
+ * contains "cart" will not match.
  */
 static int
 __cmdline_find_option_bool(const char *cmdline, int max_cmdline_size,
@@ -42,7 +43,7 @@ __cmdline_find_option_bool(const char *cmdline, int max_cmdline_size,
 	} state = st_wordstart;
 
 	if (!cmdline)
-		return -1;      /* No command line */
+		return 0;	/* No command line */
 
 	/*
 	 * This 'pos' check ensures we do not overrun

                 reply	other threads:[~2026-08-01 12:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260801125444.18082-2-thorsten.blum@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=devzero@web.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=ubizjak@gmail.com \
    --cc=x86@kernel.org \
    --cc=yuehaibing@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®