[PATCH 7/9] docs: kdoc: coalesce the end-of-comment processing

Jonathan Corbet posted 9 patches 3 months, 2 weeks ago
[PATCH 7/9] docs: kdoc: coalesce the end-of-comment processing
Posted by Jonathan Corbet 3 months, 2 weeks ago
Separate out the end-of-comment logic into its own helper and remove the
duplicated code introduced earlier.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
 scripts/lib/kdoc/kdoc_parser.py | 36 +++++++++++++--------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index 5998b02ca3a0..f7a5b85a8ed7 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -1351,13 +1351,10 @@ class KernelDoc:
             return True
         return False
 
-    def process_decl(self, ln, line):
-        """
-        STATE_DECLARATION: We've seen the beginning of a declaration
-        """
-        if self.is_new_section(ln, line):
-            return
-
+    #
+    # Helper function to detect (and effect) the end of a kerneldoc comment.
+    #
+    def is_comment_end(self, ln, line):
         if doc_end.search(line):
             self.dump_section()
 
@@ -1370,6 +1367,15 @@ class KernelDoc:
             self.entry.new_start_line = ln + 1
 
             self.state = state.PROTO
+            return True
+        return False
+
+
+    def process_decl(self, ln, line):
+        """
+        STATE_DECLARATION: We've seen the beginning of a declaration
+        """
+        if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
             return
 
         if doc_content.search(line):
@@ -1406,21 +1412,7 @@ class KernelDoc:
         """
         STATE_BODY: the bulk of a kerneldoc comment.
         """
-        if self.is_new_section(ln, line):
-            return
-
-        if doc_end.search(line):
-            self.dump_section()
-
-            # Look for doc_com + <text> + doc_end:
-            r = KernRe(r'\s*\*\s*[a-zA-Z_0-9:\.]+\*/')
-            if r.match(line):
-                self.emit_msg(ln, f"suspicious ending line: {line}")
-
-            self.entry.prototype = ""
-            self.entry.new_start_line = ln + 1
-
-            self.state = state.PROTO
+        if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
             return
 
         if doc_content.search(line):
-- 
2.49.0
Re: [PATCH 7/9] docs: kdoc: coalesce the end-of-comment processing
Posted by Mauro Carvalho Chehab 3 months, 2 weeks ago
Em Sat, 21 Jun 2025 14:35:10 -0600
Jonathan Corbet <corbet@lwn.net> escreveu:

> Separate out the end-of-comment logic into its own helper and remove the
> duplicated code introduced earlier.
> 
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>

LGTM.
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

> ---
>  scripts/lib/kdoc/kdoc_parser.py | 36 +++++++++++++--------------------
>  1 file changed, 14 insertions(+), 22 deletions(-)
> 
> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
> index 5998b02ca3a0..f7a5b85a8ed7 100644
> --- a/scripts/lib/kdoc/kdoc_parser.py
> +++ b/scripts/lib/kdoc/kdoc_parser.py
> @@ -1351,13 +1351,10 @@ class KernelDoc:
>              return True
>          return False
>  
> -    def process_decl(self, ln, line):
> -        """
> -        STATE_DECLARATION: We've seen the beginning of a declaration
> -        """
> -        if self.is_new_section(ln, line):
> -            return
> -
> +    #
> +    # Helper function to detect (and effect) the end of a kerneldoc comment.
> +    #
> +    def is_comment_end(self, ln, line):
>          if doc_end.search(line):
>              self.dump_section()
>  
> @@ -1370,6 +1367,15 @@ class KernelDoc:
>              self.entry.new_start_line = ln + 1
>  
>              self.state = state.PROTO
> +            return True
> +        return False
> +
> +
> +    def process_decl(self, ln, line):
> +        """
> +        STATE_DECLARATION: We've seen the beginning of a declaration
> +        """
> +        if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
>              return
>  
>          if doc_content.search(line):
> @@ -1406,21 +1412,7 @@ class KernelDoc:
>          """
>          STATE_BODY: the bulk of a kerneldoc comment.
>          """
> -        if self.is_new_section(ln, line):
> -            return
> -
> -        if doc_end.search(line):
> -            self.dump_section()
> -
> -            # Look for doc_com + <text> + doc_end:
> -            r = KernRe(r'\s*\*\s*[a-zA-Z_0-9:\.]+\*/')
> -            if r.match(line):
> -                self.emit_msg(ln, f"suspicious ending line: {line}")
> -
> -            self.entry.prototype = ""
> -            self.entry.new_start_line = ln + 1
> -
> -            self.state = state.PROTO
> +        if self.is_new_section(ln, line) or self.is_comment_end(ln, line):
>              return
>  
>          if doc_content.search(line):



Thanks,
Mauro