From nobody Sun May 24 20:33:20 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 A6C0218DB2A for ; Thu, 21 May 2026 20:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779396376; cv=none; b=WIznvfDVmaZfjQ0g/8guPAw10bE3o4zrA/W3pE6sD2Z7Czou8JBOweE35SSjar0BuJX8g+h2osff9ZXSaZJ5Fe9LXgr1OzRZ6H0hZzGdsRnS79RRduqUBW8nTmNscmTQR2urBO/uNI7SNLQkeqB9qBYH4dlF9AYXQfqBUmd5S7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779396376; c=relaxed/simple; bh=7svBzpcXGWuhFn9c2E/+cO/X7WQEHQmeMJm9U9tZN/8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KPio6QvpzRM+P37JUnID4GRp1AagWfdsWRXYyzAbzmJwx8bTM0ym4LRPrXP3+CRdAd51YPtkTsWsFQgI7X3Tm8DPrLxpb9yoM1l1BDRt6WADqwqx3XfuxOQphVVHgQZ7q9/Yexb3Y+P0nln6o6BSKKt/EBuAougsdB6Mb4OZmxg= 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=bj2ev22z; arc=none smtp.client-ip=91.218.175.185 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="bj2ev22z" 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=1779396371; 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=o8mUFCUWSM6SKQhCC0aZsRzJqQQ+QrhI2m+xmXYqUp0=; b=bj2ev22zCmbgkat37X596vugt3cDXnY+DY3pa2C7s+n9147zSWpouwW53eblgKjYEex065 Ty5GrckVzVqHDMPuZZ/2AW2xvZnnyeE9eepjUobL4enKT/4pii7ZA/kIIoLS04W4Fy8z36 gzfyQzz1J5BsItYjbmi+KK4kIEzQMlA= 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 v3] checkpatch: warn on uppercase N/Y/M as Kconfig tristate literals Date: Thu, 21 May 2026 15:46:05 -0500 Message-ID: <20260521204605.534862-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 --- 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0d18771f1b01..e3244c270d26 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3732,6 +3732,20 @@ 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/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'//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