From nobody Mon Jun 8 17:38:09 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 98EBA410D04 for ; Wed, 27 May 2026 14:25:47 +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=1779891954; cv=none; b=mvOatRW4A7zkW70WX2NJqtmJwJGvIC0+60NLgofZvqRQd6VtTKL0XA8sslcgTdvwWjCQ0HqA2i5KwyMJzBKsDvNU7EMJuIv3i+eNdOMxYeJhUfwePlOkVwuSWbJ+FZi+QxejsWDZvOB4Q6LnhCkIwFgzp6Y5siYFs5Kb9BXymI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779891954; c=relaxed/simple; bh=x4h5UsNWZEu5rQT/RFo4tqO+ouSGh5HiQxcYOSojwE8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bl1GQqFG9jGBTGWwaAa8xdgkybzW40wX0w78ccadQf6j6Jus4FFv2Xn6jVA0yXth/6iQX6Q4knKcpSEla8AS+g6kZQzvNqaTVp27X4XyJi8kB89J8YV45KdKNqlMfIIiskBTfYXIsY95bK+DYlk2UnrRJpPgs3YqhFcfj4EZTQc= 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=Zz+dS+yo; 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="Zz+dS+yo" 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=1779891944; 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=PXcWZrMl8NvPyicow5vSrveLCDvKVG3HB7scdQKNEVM=; b=Zz+dS+yogsU90zm4c1ijOIwvftVjntvfuDdAUaIVAz/Db3aUtdbQ7Uw2Zeoav/yYmfWfm+ RCuWhbm2Id971grh9Rn4PoFgYPg5UqeENbD5PEF5dnadXHqVSqqlBlWnvvJWeIUt7dmvrN e8r4NdvIJAw2NOlNDOKCjlHj3Vz2ZJ4= 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, julianbraha@gmail.com Subject: [PATCH v4] checkpatch: warn on uppercase N/Y/M as Kconfig tristate literals Date: Wed, 27 May 2026 09:25:38 -0500 Message-ID: <20260527142538.107022-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 --- v4: - handle quoted N/M/Y [Julian] - improved stripping of $(macro) expansions [Sashiko] v3: - More changes from another sashiko review which required the Perl to get even uglier. 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3727156e4cca..5ed74102ac23 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3732,6 +3732,22 @@ 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|bool|tristate|int|hex|string|prompt)\s+(.+)$= /) { + my $expr =3D $1; + $expr =3D~ s/"([NYM])"/$1/g; # unwrap quoted N/Y/M + $expr =3D~ s/'([NYM])'/$1/g; + $expr =3D~ s/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'//g; # strip quoted str= ings + $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