[PATCH 09/12] docs: kdoc: straighten up dump_declaration()

Jonathan Corbet posted 12 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH 09/12] docs: kdoc: straighten up dump_declaration()
Posted by Jonathan Corbet 3 months, 1 week ago
Get rid of the excess "return" statements in dump_declaration(), along with
a line of never-executed dead code.

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

diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index 6e35e508608b..7191fa94e17a 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -878,18 +878,13 @@ class KernelDoc:
 
         if self.entry.decl_type == "enum":
             self.dump_enum(ln, prototype)
-            return
-
-        if self.entry.decl_type == "typedef":
+        elif self.entry.decl_type == "typedef":
             self.dump_typedef(ln, prototype)
-            return
-
-        if self.entry.decl_type in ["union", "struct"]:
+        elif self.entry.decl_type in ["union", "struct"]:
             self.dump_struct(ln, prototype)
-            return
-
-        self.output_declaration(self.entry.decl_type, prototype,
-                                entry=self.entry)
+        else:
+            # This would be a bug
+            self.emit_message(ln, f'Unknown declaration type: {self.entry.decl_type}')
 
     def dump_function(self, ln, prototype):
         """
-- 
2.49.0
Re: [PATCH 09/12] docs: kdoc: straighten up dump_declaration()
Posted by Mauro Carvalho Chehab 2 months, 4 weeks ago
Em Wed,  2 Jul 2025 16:35:21 -0600
Jonathan Corbet <corbet@lwn.net> escreveu:

> Get rid of the excess "return" statements in dump_declaration(), along with
> a line of never-executed dead code.
> 
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
> ---
>  scripts/lib/kdoc/kdoc_parser.py | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
> index 6e35e508608b..7191fa94e17a 100644
> --- a/scripts/lib/kdoc/kdoc_parser.py
> +++ b/scripts/lib/kdoc/kdoc_parser.py
> @@ -878,18 +878,13 @@ class KernelDoc:
>  
>          if self.entry.decl_type == "enum":
>              self.dump_enum(ln, prototype)
> -            return
> -
> -        if self.entry.decl_type == "typedef":
> +        elif self.entry.decl_type == "typedef":
>              self.dump_typedef(ln, prototype)
> -            return
> -
> -        if self.entry.decl_type in ["union", "struct"]:
> +        elif self.entry.decl_type in ["union", "struct"]:
>              self.dump_struct(ln, prototype)
> -            return
> -

The above LGTM.

> -        self.output_declaration(self.entry.decl_type, prototype,
> -                                entry=self.entry)
> +        else:
> +            # This would be a bug
> +            self.emit_message(ln, f'Unknown declaration type: {self.entry.decl_type}')

Hmm... Are you sure about that? If I'm not mistaken, this was used for
other types of arguments, like DOC: tags.

>  
>      def dump_function(self, ln, prototype):
>          """

Thanks,
Mauro
Re: [PATCH 09/12] docs: kdoc: straighten up dump_declaration()
Posted by Jonathan Corbet 2 months, 4 weeks ago
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:

> Em Wed,  2 Jul 2025 16:35:21 -0600
> Jonathan Corbet <corbet@lwn.net> escreveu:
>
>> Get rid of the excess "return" statements in dump_declaration(), along with
>> a line of never-executed dead code.
>> 
>> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
>> ---
>>  scripts/lib/kdoc/kdoc_parser.py | 15 +++++----------
>>  1 file changed, 5 insertions(+), 10 deletions(-)
>> 
>> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
>> index 6e35e508608b..7191fa94e17a 100644
>> --- a/scripts/lib/kdoc/kdoc_parser.py
>> +++ b/scripts/lib/kdoc/kdoc_parser.py
>> @@ -878,18 +878,13 @@ class KernelDoc:
>>  
>>          if self.entry.decl_type == "enum":
>>              self.dump_enum(ln, prototype)
>> -            return
>> -
>> -        if self.entry.decl_type == "typedef":
>> +        elif self.entry.decl_type == "typedef":
>>              self.dump_typedef(ln, prototype)
>> -            return
>> -
>> -        if self.entry.decl_type in ["union", "struct"]:
>> +        elif self.entry.decl_type in ["union", "struct"]:
>>              self.dump_struct(ln, prototype)
>> -            return
>> -
>
> The above LGTM.
>
>> -        self.output_declaration(self.entry.decl_type, prototype,
>> -                                entry=self.entry)
>> +        else:
>> +            # This would be a bug
>> +            self.emit_message(ln, f'Unknown declaration type: {self.entry.decl_type}')
>
> Hmm... Are you sure about that? If I'm not mistaken, this was used for
> other types of arguments, like DOC: tags.

DOC tags are handled in a different path entirely.  I did ensure that
the code in question was never executed ... but then left the message in
place just in case.

Thanks,

jon
Re: [PATCH 09/12] docs: kdoc: straighten up dump_declaration()
Posted by Mauro Carvalho Chehab 2 months, 4 weeks ago
Em Thu, 10 Jul 2025 07:27:07 -0600
Jonathan Corbet <corbet@lwn.net> escreveu:

> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:
> 
> > Em Wed,  2 Jul 2025 16:35:21 -0600
> > Jonathan Corbet <corbet@lwn.net> escreveu:
> >  
> >> Get rid of the excess "return" statements in dump_declaration(), along with
> >> a line of never-executed dead code.
> >> 
> >> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
> >> ---
> >>  scripts/lib/kdoc/kdoc_parser.py | 15 +++++----------
> >>  1 file changed, 5 insertions(+), 10 deletions(-)
> >> 
> >> diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
> >> index 6e35e508608b..7191fa94e17a 100644
> >> --- a/scripts/lib/kdoc/kdoc_parser.py
> >> +++ b/scripts/lib/kdoc/kdoc_parser.py
> >> @@ -878,18 +878,13 @@ class KernelDoc:
> >>  
> >>          if self.entry.decl_type == "enum":
> >>              self.dump_enum(ln, prototype)
> >> -            return
> >> -
> >> -        if self.entry.decl_type == "typedef":
> >> +        elif self.entry.decl_type == "typedef":
> >>              self.dump_typedef(ln, prototype)
> >> -            return
> >> -
> >> -        if self.entry.decl_type in ["union", "struct"]:
> >> +        elif self.entry.decl_type in ["union", "struct"]:
> >>              self.dump_struct(ln, prototype)
> >> -            return
> >> -  
> >
> > The above LGTM.
> >  
> >> -        self.output_declaration(self.entry.decl_type, prototype,
> >> -                                entry=self.entry)
> >> +        else:
> >> +            # This would be a bug
> >> +            self.emit_message(ln, f'Unknown declaration type: {self.entry.decl_type}')  
> >
> > Hmm... Are you sure about that? If I'm not mistaken, this was used for
> > other types of arguments, like DOC: tags.  
> 
> DOC tags are handled in a different path entirely.  I did ensure that
> the code in question was never executed ... but then left the message in
> place just in case.

OK.


If the output didn't change neither for ReST nor for man, that's fine
for me. Besides being a port from Perl, I'm almost sure I hit this
code before during the conversion, but it it is now a dead code,
your approach is better ;-)

While I didn't test, I trust you. So feel free to add:

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

Thanks,
Mauro