linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [RFC] scripts: kernel-doc: fix typedef support for struct parsing
@ 2021-02-22 16:03 Aditya Srivastava
  2021-02-22 17:49 ` Lukas Bulwahn
  2021-02-22 21:40 ` Jonathan Corbet
  0 siblings, 2 replies; 13+ messages in thread
From: Aditya Srivastava @ 2021-02-22 16:03 UTC (permalink / raw)
  To: corbet; +Cc: linux-doc, linux-kernel-mentees, linux-kernel, yashsri421

There are files in kernel, which use 'typedef struct' syntax for defining
struct. For eg, include/linux/zstd.h, drivers/scsi/megaraid/mega_common.h,
etc.
However, kernel-doc still does not support it, causing a parsing error.

For eg, running scripts/kernel-doc -none on include/linux/zstd.h emits:
"error: Cannot parse struct or union!"

Add support for parsing it.

Signed-off-by: Aditya Srivastava <yashsri421@gmail.com>
---
 scripts/kernel-doc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 8b5bc7bf4bb8..46e904dc3f87 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -1201,12 +1201,20 @@ sub dump_union($$) {
 sub dump_struct($$) {
     my $x = shift;
     my $file = shift;
+    my $decl_type;
+    my $members;
 
     if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
-	my $decl_type = $1;
+	$decl_type = $1;
 	$declaration_name = $2;
-	my $members = $3;
+	$members = $3;
+    } elsif ($x =~ /typedef\s+(struct|union)\s*\{(.*)\}(?:\s*(?:__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*\s*(\w*)\s*;/) {
+	$decl_type = $1;
+	$declaration_name = $3;
+	$members = $2;
+    }
 
+    if ($members) {
 	if ($identifier ne $declaration_name) {
 	    print STDERR "${file}:$.: warning: expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n";
 	    return;
-- 
2.17.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-03-07  7:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 16:03 [Linux-kernel-mentees] [RFC] scripts: kernel-doc: fix typedef support for struct parsing Aditya Srivastava
2021-02-22 17:49 ` Lukas Bulwahn
2021-02-22 21:40 ` Jonathan Corbet
2021-02-23 12:25   ` Aditya
2021-02-24 13:30   ` [RFC v2] scripts: kernel-doc: fix typedef support for struct/union parsing Aditya Srivastava
2021-02-25 11:48     ` Lukas Bulwahn
2021-02-25 14:50       ` [RFC v3] " Aditya Srivastava
2021-03-01 21:51         ` Jonathan Corbet
2021-03-06  4:35         ` Matthew Wilcox
2021-03-06  6:25           ` Lukas Bulwahn
2021-03-06  7:48             ` Aditya
2021-03-06 15:20               ` Matthew Wilcox
2021-03-07  7:36                 ` Aditya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).