From nobody Mon May 25 01:14:31 2026 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 1C7EF3E8350 for ; Tue, 19 May 2026 21:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779227777; cv=none; b=XVZrE+eL+v2SFW66LcKT+xCzucRx/1fa+cakhjjJYjyRMIdkg7TWtEMjzgfErWFkvQfYeCsMuQ0rDFGrSTn0Mj3URZAqRV314n08uhC/X2vWxOmaNoE0f06VbjoMyOjYTRnDyxFkZ6NaT1/4OHwJ8haTFiXG8tYV7F/OIc4jv9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779227777; c=relaxed/simple; bh=OssKCqCP2qjBz0eEJoX3HsE/m91NVAmai7qxOU49R6Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=l7kX+zToJ0pRE1RkbTPDxneRuP/2R0L4tHDH7M9d4C9rnoFs/fGYxfWVChkOqXywp7MofUBzS2L/Bo/VP8+61IBvHuHSfhdJpIxCh6sXPGsQ57W1BqXZ6vmp89F9MZWXzaraJGYM1B1x9RQJ/g2S/dP3Gz6Ptuaf2h5f/vNiqow= 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=hdX8+PJq; arc=none smtp.client-ip=91.218.175.171 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="hdX8+PJq" 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=1779227771; 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=zWd3otasr7DsvHmkiLSqXyQ0ctz+xkROkoMf8lwcJWc=; b=hdX8+PJq4wZOHXq3TAhGPyFf/2RrdshvFhqLrFZvZCp2P7Px1c0jdVwaDyxffETG6qzwI3 x9naO6JgewS+Lyo38yMqMEWIZY2hHZBOUY+to1vF5detYUckJwc2qzH6gdEEk3r/IPue3W be6k/17U+PJpSnIbEzFecz0eUY08g6M= From: Andrew Jones To: linux-kernel@vger.kernel.org Cc: apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com, lukas.bulwahn@gmail.com, andriy.shevchenko@linux.intel.com Subject: [PATCH v2] checkpatch: warn on uppercase N/Y/M as Kconfig tristate literals Date: Tue, 19 May 2026 16:56:07 -0500 Message-ID: <20260519215607.83962-1-andrew.jones@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Kconfig tristate literals are always lowercase ('n', 'y', 'm') and uppercase N/Y/M are not Kconfig reserved words. Since undefined symbols evaluate to 'n', writing 'default Y' or 'default M' silently produces 'n' instead of 'y'/'m'. 'default N' happens to produce the right value but is still invalid syntax. Add a warning for N/Y/M in Kconfig expressions found by following the same preprocessing logic used by the Kconfig parser itself. This new warning was inspired by work done for [1]. Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D216748 [1] Assisted-by: Claude:claude-sonnet-4-6 Signed-off-by: Andrew Jones Acked-by: Andy Shevchenko --- v2: - Added Andy's tag - Changes thanks to sashiko's review - strip quoted strings before inline comments to avoid '#' inside a str= ing - use [^)]* instead of .* in macro strip regex to avoid greedy match eating tokens between adjacent $(macro) expansions scripts/checkpatch.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0d18771f1b01..105478ba6c60 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3732,6 +3732,21 @@ sub process { } } =20 +# check for uppercase N/Y/M used as Kconfig tristate literals + if ($realfile =3D~ /Kconfig/ && + $line =3D~ /^\+\s*(?:default|def_bool|def_tristate|select|imply|depe= nds\s+on|visible\s+if|range|if)\s+(.+)$/) { + my $expr =3D $1; + $expr =3D~ s/"[^"]*"//g; # strip "quoted strings" + $expr =3D~ s/'[^']*'//g; # strip 'quoted strings' + $expr =3D~ s/#.*//; # strip inline comments + $expr =3D~ s/\$\([^)]*\)//g; # strip $(macro) expansions + for my $tok (split /[^A-Za-z0-9_]+/, $expr) { + next unless ($tok eq 'Y' || $tok eq 'M' || $tok eq 'N'); + WARN("KCONFIG_TRISTATE_UPPERCASE", + "'$tok' is probably not what you want here; Kconfig tristate lite= rals are always lowercase ('n', 'y', 'm')\n" . $herecurr); + } + } + # check MAINTAINERS entries if ($realfile =3D~ /^MAINTAINERS$/) { # check MAINTAINERS entries for the right form --=20 2.43.0