[PATCH 1/2] docs: kdoc: emit warnings for symbols selected with -function/-export
From: Prateekshit Jaiswal via B4 Relay
Date: Sat Nov 14 2026 - 01:14:31 EST
From: Prateekshit Jaiswal <prateekshitjaiswal73@xxxxxxxxx>
Commit 9cbc2d3b137b ("scripts/kernel-doc.py: postpone warnings to the
output plugin") moved warning output into
OutputFormat.check_declaration(), which is supposed to print the
warnings of each symbol it lets through. The OUTPUT_INCLUDE and
OUTPUT_EXPORTED branch returns without that call, so -function,
-export, and the Sphinx kernel-doc :identifiers: and :export: options
drop the warnings of the symbols they keep. On v6.18 the command below
prints nothing, even though intel_dkl_phy_read() does not describe its
return value:
$ ./scripts/kernel-doc -none -Wall -function intel_dkl_phy_read drivers/gpu/drm/i915/display/intel_dkl_phy.c
>From v6.19 the warning still appears, because the parser prints the
warnings of every entry itself. That is a separate bug, fixed in the
next patch. Fixing only that one would make this gap visible again.
Until then, this change prints the selected symbols' warnings twice in
these modes.
Call out_warnings() in that branch as well, as the other modes do, and
add tests for the warnings shown with each output filter.
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: 9cbc2d3b137b ("scripts/kernel-doc.py: postpone warnings to the output plugin")
Signed-off-by: Prateekshit Jaiswal <prateekshitjaiswal73@xxxxxxxxx>
---
tools/lib/python/kdoc/kdoc_output.py | 1 +
tools/unittests/test_kdoc_parser.py | 71 ++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/tools/lib/python/kdoc/kdoc_output.py b/tools/lib/python/kdoc/kdoc_output.py
index 659a2c6fb6be..e0f24302cbc4 100644
--- a/tools/lib/python/kdoc/kdoc_output.py
+++ b/tools/lib/python/kdoc/kdoc_output.py
@@ -167,6 +167,7 @@ class OutputFormat:
if self.out_mode in [self.OUTPUT_INCLUDE, self.OUTPUT_EXPORTED]:
if name in self.function_table:
+ self.out_warnings(args)
return True
if self.out_mode == self.OUTPUT_INTERNAL:
diff --git a/tools/unittests/test_kdoc_parser.py b/tools/unittests/test_kdoc_parser.py
index 6e305988cb6d..35f7a140942d 100755
--- a/tools/unittests/test_kdoc_parser.py
+++ b/tools/unittests/test_kdoc_parser.py
@@ -353,6 +353,77 @@ class ManFilterTail(unittest.TestCase):
self.assertEqual(self.run_filter(export=True), "")
+class OutputFilterWarnings(unittest.TestCase):
+ """
+ The output step shows the warnings of the symbols it outputs, once.
+ """
+
+ source = dedent("""
+ /**
+ * foo - First function
+ */
+ int foo(int a) { return 0; };
+
+ /**
+ * bar - Second function
+ * @b: an argument
+ */
+ int bar(int b) { return 0; };
+ """)
+
+ def setUp(self):
+ self.config = MockKdocConfig()
+ kernel_doc = KernelDoc(self.config, "mock.c", CTransforms())
+
+ with patch('builtins.open', new_callable=mock_open,
+ read_data=self.source):
+ with patch.object(self.config, 'warning'):
+ _, self.entries = kernel_doc.parse_kdoc()
+
+ self.out_style = ManFormat()
+ self.out_style.set_config(self.config)
+
+ def run_filter(self, **kwargs):
+ args = {"export": False, "internal": False, "symbol": None,
+ "nosymbol": None, "function_table": set(),
+ "enable_lineno": False, "no_doc_sections": False}
+ args.update(kwargs)
+
+ self.out_style.set_filter(**args)
+
+ with patch.object(self.config, 'warning') as warning:
+ self.out_style.output_symbols("mock.c", self.entries)
+
+ return [call.args[0] for call in warning.call_args_list]
+
+ def test_all_symbols(self):
+ """Without a filter, the warning of foo is shown."""
+ warnings = self.run_filter()
+
+ self.assertEqual(len(warnings), 1)
+ self.assertIn("'a' not described in 'foo'", warnings[0])
+
+ def test_selected_symbol(self):
+ """The warning of a symbol selected by name is shown."""
+ warnings = self.run_filter(symbol=["foo"], function_table={"foo"})
+
+ self.assertEqual(len(warnings), 1)
+ self.assertIn("'a' not described in 'foo'", warnings[0])
+
+ def test_exported_symbol(self):
+ """The warning of an exported symbol is shown."""
+ warnings = self.run_filter(export=True, function_table={"foo"})
+
+ self.assertEqual(len(warnings), 1)
+ self.assertIn("'a' not described in 'foo'", warnings[0])
+
+ def test_other_symbol(self):
+ """The warning of a symbol that is not selected is not shown."""
+ warnings = self.run_filter(symbol=["bar"], function_table={"bar"})
+
+ self.assertEqual(warnings, [])
+
+
class CToRest(unittest.TestCase):
out_style = RestFormat()
config = MockKdocConfig()
--
2.53.0