docs: kdoc: simplify the kerneldoc recognition code
authorJonathan Corbet <corbet@lwn.net>
Fri, 6 Jun 2025 16:34:33 +0000 (10:34 -0600)
committerJonathan Corbet <corbet@lwn.net>
Mon, 9 Jun 2025 20:37:17 +0000 (14:37 -0600)
process_name() looks for the first line of a kerneldoc comment.  It
contains two nearly identical regular expressions, the second of which only
catches six cases in the kernel, all of the form:

  define SOME_MACRO_NAME - description

Simply put the "define" into the regex and discard it, eliminating the loop
and the code to remove it specially.

Note that this still treats these defines as if they were functions, but
that's a separate issue.

There is no change in the generated output.

Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250606163438.229916-5-corbet@lwn.net
scripts/lib/kdoc/kdoc_parser.py

index f8871f6a26387881eee3781c662c5df06f55ea49..72919a5d71b29f7ac3015eb926a0fe2fbe8f3acf 100644 (file)
@@ -1238,26 +1238,18 @@ class KernelDoc:
 
             # Test for data declaration
             r = KernRe(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)")
+            r2 = KernRe(fr"^{decl_start}{fn_type}(?:define\s+)?(\w+)\s*{parenthesis}\s*{decl_end}?$")
             if r.search(line):
                 self.entry.decl_type = r.group(1)
                 self.entry.identifier = r.group(2)
                 self.entry.is_kernel_comment = True
-            else:
-                # Look for foo() or static void foo() - description;
-                # or misspelt identifier
-
-                r1 = KernRe(fr"^{decl_start}{fn_type}(\w+)\s*{parenthesis}\s*{decl_end}?$")
-                r2 = KernRe(fr"^{decl_start}{fn_type}(\w+[^-:]*){parenthesis}\s*{decl_end}$")
-
-                for r in [r1, r2]:
-                    if r.search(line):
-                        self.entry.identifier = r.group(1)
-                        self.entry.decl_type = "function"
-
-                        r = KernRe(r"define\s+")
-                        self.entry.identifier = r.sub("", self.entry.identifier)
-                        self.entry.is_kernel_comment = True
-                        break
+            #
+            # Look for a function description
+            #
+            elif r2.search(line):
+                self.entry.identifier = r2.group(1)
+                self.entry.decl_type = "function"
+                self.entry.is_kernel_comment = True
 
             self.entry.identifier = self.entry.identifier.strip(" ")