From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02C0F2AE76 for ; Sat, 1 Aug 2026 12:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785589125; cv=none; b=Vk0Yu7Cngbfe3ud6EWQTQUwpChi3C7+iVCNftaoM19P9jQWZ9/SkYUTxnraJOulUn6WgoGJBh/pF3ZS1rgxDeUecSQdKXhXhd2Ae2yGn8+/QFbe2k3PhgWH457MnuVUszN+9UFiFjzIrHNcvKhZg6+zo2+sX2t4zkLug6oSMZI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785589125; c=relaxed/simple; bh=gkMOtkl/ShAKMF+lsGUwIlvlOIzwdsVty3g2r7PD9+A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=A1Og4fCotLQIFulTvTeEU3ZQWvYOtQge0ortHqCUc8cdzbkNb1nZavRJglR7QGYldUM4J5QfThta8rqcKH79UQduVVaEG4T7/xm+UVphDN1TrxkUP3nHK827eEIRwHD83Q6RhswvLXu7j4oCz/JqMSb5iGeEQoLAcI7DGSjbxsk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wEFLaTUJ; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wEFLaTUJ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785589120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ykgEY6flDrVI9rDt0OOZw1wHASyGl7pnpDM+qcX/O0w=; b=wEFLaTUJdveM3iyEj3am5eQ5IZ5acITtTeRDGgv+u+6CyZQvppAXA0QTXC2QHFbVF3Zr6W h2CPGVUV9q6EuNfIrqPK8vo23nLzMxL2ilenHPorC2W+yq5MHSGiU6ygCtXliQbtzO3bhO aSkgNTNT6gETwK2OGjh4Qru0Ru7hDt8= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Uros Bizjak , Yue Haibing , "devzero@web.de" Cc: Thorsten Blum , Ingo Molnar , 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 Message-ID: <20260801125444.18082-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3516; i=thorsten.blum@linux.dev; h=from:subject; bh=gkMOtkl/ShAKMF+lsGUwIlvlOIzwdsVty3g2r7PD9+A=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFm5b6ZUPepwSiy4FxQx9Y/cUakCvnWTd26Ve6lxk/HFP xfxrc/+dpSyMIhxMciKKbI8mPVjhm9pTeUmk4idMHNYmUCGMHBxCsBE2BoYGW6klOgt15ofqJr0 yPaCltnE2NVKgWyRX3bbliv/mJ/8WoKRYWLdA6n5Tnpyea+vf131gEvBSd/i7jvJJRaTH56fypp 9hBUA X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 --- 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