Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scripts/kernel-doc: handle object-like macros

Object-like macros are different than function-like macros:
https://gcc.gnu.org/onlinedocs/cpp/Object-like-Macros.html
https://gcc.gnu.org/onlinedocs/cpp/Function-like-Macros.html

They are not parsed correctly, generating invalid intermediate
files (xmls) for cases like:
#define BIT_MASK (0xFF << BIT_SHIFT)
where "OxFF <<" is considered to be parameter type.

When parsing, we can differentiate beween these two types of macros by
checking whether there is at least one whitespace b/w "#define" and
first opening parenthesis.

Signed-off-by: Horia Geanta <horia.geanta@freescale.com>
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Horia Geanta and committed by
Linus Torvalds
cbb4d3e6 c8c3f7d6

+12 -3
+12 -3
scripts/kernel-doc
··· 2073 2073 sub dump_function($$) { 2074 2074 my $prototype = shift; 2075 2075 my $file = shift; 2076 + my $noret = 0; 2076 2077 2077 2078 $prototype =~ s/^static +//; 2078 2079 $prototype =~ s/^extern +//; ··· 2087 2086 $prototype =~ s/__init_or_module +//; 2088 2087 $prototype =~ s/__must_check +//; 2089 2088 $prototype =~ s/__weak +//; 2090 - $prototype =~ s/^#\s*define\s+//; #ak added 2089 + my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2091 2090 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 2092 2091 2093 2092 # Yes, this truly is vile. We are looking for: ··· 2106 2105 # - atomic_set (macro) 2107 2106 # - pci_match_device, __copy_to_user (long return type) 2108 2107 2109 - if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2108 + if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2109 + # This is an object-like macro, it has no return type and no parameter 2110 + # list. 2111 + # Function-like macros are not allowed to have spaces between 2112 + # declaration_name and opening parenthesis (notice the \s+). 2113 + $return_type = $1; 2114 + $declaration_name = $2; 2115 + $noret = 1; 2116 + } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2110 2117 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2111 2118 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2112 2119 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || ··· 2149 2140 # of warnings goes sufficiently down, the check is only performed in 2150 2141 # verbose mode. 2151 2142 # TODO: always perform the check. 2152 - if ($verbose) { 2143 + if ($verbose && !$noret) { 2153 2144 check_return_section($file, $declaration_name, $return_type); 2154 2145 } 2155 2146