From: Prateekshit Jaiswal via B4 Relay <devnull+prateekshitjaiswal73.gmail.com@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Prateekshit Jaiswal <prateekshitjaiswal73@gmail.com>
Subject: [PATCH 2/2] docs: kdoc: don't print warnings of stored entries twice
Date: Sat, 14 Nov 2026 11:44:09 +0530 [thread overview]
Message-ID: <20261114-kdoc-dup-warnings-v1-2-265f89bc3f9c@gmail.com> (raw)
In-Reply-To: <20261114-kdoc-dup-warnings-v1-0-265f89bc3f9c@gmail.com>
From: Prateekshit Jaiswal <prateekshitjaiswal73@gmail.com>
Commit 469c1c9eb6c9 ("kernel-doc: Issue warnings that were silently
discarded") was meant to print warnings of entries that never reach
the output step. With no symbol filter, kernel-doc now prints the
warnings of every documented symbol twice:
$ ./scripts/kernel-doc -none -Wall drivers/gpu/drm/i915/display/intel_dkl_phy.c
Warning: drivers/gpu/drm/i915/display/intel_dkl_phy.c:47 No description found for return value of 'intel_dkl_phy_read'
Warning: drivers/gpu/drm/i915/display/intel_dkl_phy.c:47 No description found for return value of 'intel_dkl_phy_read'
The flush uses "self.entry not in self.entries" to tell stored entries
from discarded ones. output_declaration() stores a new KdocItem built
from the entry, never the KernelEntry itself, so that test is always
true. Every stored entry then warns once in the parser and once in the
output plugin.
Those parser-side prints also ignore the later symbol filter, so
"-function intel_dkl_phy_write" still warns about intel_dkl_phy_read().
Commit 292eca316321 ("docs: kdoc: fix logic to handle unissued
warnings") routes the flush through config.warning(), which increments
the warning count. -Werror then reports "2 warnings as errors" for a
single warning, and a -function run fails because of a different
symbol.
Mark the entry as stored in output_declaration(), flush warnings only
for entries that were not stored, and add tests for both cases. This
needs the previous patch. Without it, symbols selected with -function
or -export would lose their warnings.
Running "kernel-doc -none -Wall" over the 10320 .c and .h files with
kernel-doc comments, the output shrinks from 87900 to 49625 lines,
while the set of distinct lines stays the same.
The problem was found, and the fix and tests drafted, with the help of
an AI coding assistant (Claude Code); I have reviewed and tested the
result.
Fixes: 469c1c9eb6c9 ("kernel-doc: Issue warnings that were silently discarded")
Signed-off-by: Prateekshit Jaiswal <prateekshitjaiswal73@gmail.com>
---
tools/lib/python/kdoc/kdoc_parser.py | 4 ++-
tools/unittests/test_kdoc_parser.py | 55 ++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/kdoc_parser.py
index 80d4245acd17..ef5879b05308 100644
--- a/tools/lib/python/kdoc/kdoc_parser.py
+++ b/tools/lib/python/kdoc/kdoc_parser.py
@@ -135,6 +135,7 @@ class KernelEntry:
self.prototype = ""
self.warnings = []
+ self.stored = False
self.parameterlist = []
self.parameterdescs = {}
@@ -323,6 +324,7 @@ class KernelDoc:
self.entry.parametertypes,
self.entry.parameterdesc_start_lines)
self.entries.append(item)
+ self.entry.stored = True
self.config.log.debug("Output: %s:%s = %s", dtype, name, pformat(args))
@@ -346,7 +348,7 @@ class KernelDoc:
during the output step of the code, depending on the
selected symbols.
"""
- if self.entry and self.entry not in self.entries:
+ if self.entry and not self.entry.stored:
for log_msg in self.entry.warnings:
self.config.warning(log_msg)
diff --git a/tools/unittests/test_kdoc_parser.py b/tools/unittests/test_kdoc_parser.py
index 35f7a140942d..709455a4b39c 100755
--- a/tools/unittests/test_kdoc_parser.py
+++ b/tools/unittests/test_kdoc_parser.py
@@ -567,6 +567,61 @@ class TestContextLockStruct(GenerateKdocItem):
self.assertEqual(entries[0].name, "debugfs_cancellation")
self.assertEqual(entries[0].warnings, [])
+class TestUnusedWarnings(GenerateKdocItem):
+ """
+ Test that the parser itself only emits warnings of discarded entries.
+ """
+
+ def parse(self, source):
+ """
+ Parse source, returning the entries and the warnings emitted.
+ """
+ kernel_doc = KernelDoc(self.config, "test.c", self.xforms)
+
+ with patch('builtins.open', new_callable=mock_open,
+ read_data=dedent(source)):
+ with patch.object(self.config, 'warning') as warning:
+ _, entries = kernel_doc.parse_kdoc()
+
+ return entries, [call.args[0] for call in warning.call_args_list]
+
+ def test_stored_entry(self):
+ """
+ Warnings of a stored entry are left for the output step, which
+ applies the symbol filters, so they must not be emitted here.
+ """
+ source = """
+ /**
+ * func - Do nothing
+ */
+ int func(int arg) { return 0; }
+ """
+
+ entries, emitted = self.parse(source)
+
+ self.assertEqual(len(entries), 1)
+ self.assertEqual(len(entries[0].warnings), 1)
+ self.assertIn("'arg' not described", entries[0].warnings[0])
+ self.assertEqual(emitted, [])
+
+ def test_discarded_entry(self):
+ """
+ Warnings of an entry that is never stored are emitted once.
+ """
+ source = """
+ /**
+ * to_user_ptr - cast a u64 to a user space pointer
+ * @x: the u64 to convert
+ */
+ #define u64_to_user_ptr(x) ((void __user *)(uintptr_t)(x))
+ """
+
+ entries, emitted = self.parse(source)
+
+ self.assertEqual(entries, [])
+ self.assertEqual(len(emitted), 1)
+ self.assertIn("expecting prototype for to_user_ptr()", emitted[0])
+
#
# Class and logic to create dynamic tests from YAML
#
--
2.53.0
next prev parent reply other threads:[~2026-11-14 6:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 6:14 [PATCH 0/2] docs: kdoc: print each warning once, and only for selected symbols Prateekshit Jaiswal via B4 Relay
2026-11-14 6:14 ` [PATCH 1/2] docs: kdoc: emit warnings for symbols selected with -function/-export Prateekshit Jaiswal via B4 Relay
2026-11-14 6:14 ` Prateekshit Jaiswal via B4 Relay [this message]
2026-11-14 20:18 ` [PATCH 2/2] docs: kdoc: don't print warnings of stored entries twice Randy Dunlap
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=20261114-kdoc-dup-warnings-v1-2-265f89bc3f9c@gmail.com \
--to=devnull+prateekshitjaiswal73.gmail.com@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=prateekshitjaiswal73@gmail.com \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
/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®