checkpatch.pl 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413
  1. #!/usr/bin/perl -w
  2. # (c) 2001, Dave Jones. (the file handling bit)
  3. # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
  4. # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
  5. # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
  6. # Licensed under the terms of the GNU GPL License version 2
  7. use strict;
  8. my $P = $0;
  9. $P =~ s@.*/@@g;
  10. my $V = '0.32';
  11. use Getopt::Long qw(:config no_auto_abbrev);
  12. my $quiet = 0;
  13. my $tree = 1;
  14. my $chk_signoff = 1;
  15. my $chk_patch = 1;
  16. my $tst_only;
  17. my $emacs = 0;
  18. my $terse = 0;
  19. my $file = 0;
  20. my $check = 0;
  21. my $summary = 1;
  22. my $mailback = 0;
  23. my $summary_file = 0;
  24. my $show_types = 0;
  25. my $root;
  26. my %debug;
  27. my %ignore_type = ();
  28. my @ignore = ();
  29. my $help = 0;
  30. my $configuration_file = ".checkpatch.conf";
  31. sub help {
  32. my ($exitcode) = @_;
  33. print << "EOM";
  34. Usage: $P [OPTION]... [FILE]...
  35. Version: $V
  36. Options:
  37. -q, --quiet quiet
  38. --no-tree run without a kernel tree
  39. --no-signoff do not check for 'Signed-off-by' line
  40. --patch treat FILE as patchfile (default)
  41. --emacs emacs compile window format
  42. --terse one line per report
  43. -f, --file treat FILE as regular source file
  44. --subjective, --strict enable more subjective tests
  45. --ignore TYPE(,TYPE2...) ignore various comma separated message types
  46. --show-types show the message "types" in the output
  47. --root=PATH PATH to the kernel tree root
  48. --no-summary suppress the per-file summary
  49. --mailback only produce a report in case of warnings/errors
  50. --summary-file include the filename in summary
  51. --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
  52. 'values', 'possible', 'type', and 'attr' (default
  53. is all off)
  54. --test-only=WORD report only warnings/errors containing WORD
  55. literally
  56. -h, --help, --version display this help and exit
  57. When FILE is - read standard input.
  58. EOM
  59. exit($exitcode);
  60. }
  61. my $conf = which_conf($configuration_file);
  62. if (-f $conf) {
  63. my @conf_args;
  64. open(my $conffile, '<', "$conf")
  65. or warn "$P: Can't find a readable $configuration_file file $!\n";
  66. while (<$conffile>) {
  67. my $line = $_;
  68. $line =~ s/\s*\n?$//g;
  69. $line =~ s/^\s*//g;
  70. $line =~ s/\s+/ /g;
  71. next if ($line =~ m/^\s*#/);
  72. next if ($line =~ m/^\s*$/);
  73. my @words = split(" ", $line);
  74. foreach my $word (@words) {
  75. last if ($word =~ m/^#/);
  76. push (@conf_args, $word);
  77. }
  78. }
  79. close($conffile);
  80. unshift(@ARGV, @conf_args) if @conf_args;
  81. }
  82. GetOptions(
  83. 'q|quiet+' => \$quiet,
  84. 'tree!' => \$tree,
  85. 'signoff!' => \$chk_signoff,
  86. 'patch!' => \$chk_patch,
  87. 'emacs!' => \$emacs,
  88. 'terse!' => \$terse,
  89. 'f|file!' => \$file,
  90. 'subjective!' => \$check,
  91. 'strict!' => \$check,
  92. 'ignore=s' => \@ignore,
  93. 'show-types!' => \$show_types,
  94. 'root=s' => \$root,
  95. 'summary!' => \$summary,
  96. 'mailback!' => \$mailback,
  97. 'summary-file!' => \$summary_file,
  98. 'debug=s' => \%debug,
  99. 'test-only=s' => \$tst_only,
  100. 'h|help' => \$help,
  101. 'version' => \$help
  102. ) or help(1);
  103. help(0) if ($help);
  104. my $exit = 0;
  105. if ($#ARGV < 0) {
  106. print "$P: no input files\n";
  107. exit(1);
  108. }
  109. @ignore = split(/,/, join(',',@ignore));
  110. foreach my $word (@ignore) {
  111. $word =~ s/\s*\n?$//g;
  112. $word =~ s/^\s*//g;
  113. $word =~ s/\s+/ /g;
  114. $word =~ tr/[a-z]/[A-Z]/;
  115. next if ($word =~ m/^\s*#/);
  116. next if ($word =~ m/^\s*$/);
  117. $ignore_type{$word}++;
  118. }
  119. my $dbg_values = 0;
  120. my $dbg_possible = 0;
  121. my $dbg_type = 0;
  122. my $dbg_attr = 0;
  123. for my $key (keys %debug) {
  124. ## no critic
  125. eval "\${dbg_$key} = '$debug{$key}';";
  126. die "$@" if ($@);
  127. }
  128. my $rpt_cleaners = 0;
  129. if ($terse) {
  130. $emacs = 1;
  131. $quiet++;
  132. }
  133. if ($tree) {
  134. if (defined $root) {
  135. if (!top_of_kernel_tree($root)) {
  136. die "$P: $root: --root does not point at a valid tree\n";
  137. }
  138. } else {
  139. if (top_of_kernel_tree('.')) {
  140. $root = '.';
  141. } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
  142. top_of_kernel_tree($1)) {
  143. $root = $1;
  144. }
  145. }
  146. if (!defined $root) {
  147. print "Must be run from the top-level dir. of a kernel tree\n";
  148. exit(2);
  149. }
  150. }
  151. my $emitted_corrupt = 0;
  152. our $Ident = qr{
  153. [A-Za-z_][A-Za-z\d_]*
  154. (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
  155. }x;
  156. our $Storage = qr{extern|static|asmlinkage};
  157. our $Sparse = qr{
  158. __user|
  159. __kernel|
  160. __force|
  161. __iomem|
  162. __must_check|
  163. __init_refok|
  164. __kprobes|
  165. __ref|
  166. __rcu
  167. }x;
  168. # Notes to $Attribute:
  169. # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
  170. our $Attribute = qr{
  171. const|
  172. __percpu|
  173. __nocast|
  174. __safe|
  175. __bitwise__|
  176. __packed__|
  177. __packed2__|
  178. __naked|
  179. __maybe_unused|
  180. __always_unused|
  181. __noreturn|
  182. __used|
  183. __cold|
  184. __noclone|
  185. __deprecated|
  186. __read_mostly|
  187. __kprobes|
  188. __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
  189. ____cacheline_aligned|
  190. ____cacheline_aligned_in_smp|
  191. ____cacheline_internodealigned_in_smp|
  192. __weak
  193. }x;
  194. our $Modifier;
  195. our $Inline = qr{inline|__always_inline|noinline};
  196. our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
  197. our $Lval = qr{$Ident(?:$Member)*};
  198. our $Constant = qr{(?i:(?:[0-9]+|0x[0-9a-f]+)[ul]*)};
  199. our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
  200. our $Compare = qr{<=|>=|==|!=|<|>};
  201. our $Operators = qr{
  202. <=|>=|==|!=|
  203. =>|->|<<|>>|<|>|!|~|
  204. &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
  205. }x;
  206. our $NonptrType;
  207. our $Type;
  208. our $Declare;
  209. our $NON_ASCII_UTF8 = qr{
  210. [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  211. | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  212. | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  213. | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  214. | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  215. | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  216. | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  217. }x;
  218. our $UTF8 = qr{
  219. [\x09\x0A\x0D\x20-\x7E] # ASCII
  220. | $NON_ASCII_UTF8
  221. }x;
  222. our $typeTypedefs = qr{(?x:
  223. (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
  224. atomic_t
  225. )};
  226. our $logFunctions = qr{(?x:
  227. printk(?:_ratelimited|_once|)|
  228. [a-z0-9]+_(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
  229. WARN(?:_RATELIMIT|_ONCE|)|
  230. panic|
  231. MODULE_[A-Z_]+
  232. )};
  233. our $signature_tags = qr{(?xi:
  234. Signed-off-by:|
  235. Acked-by:|
  236. Tested-by:|
  237. Reviewed-by:|
  238. Reported-by:|
  239. To:|
  240. Cc:
  241. )};
  242. our @typeList = (
  243. qr{void},
  244. qr{(?:unsigned\s+)?char},
  245. qr{(?:unsigned\s+)?short},
  246. qr{(?:unsigned\s+)?int},
  247. qr{(?:unsigned\s+)?long},
  248. qr{(?:unsigned\s+)?long\s+int},
  249. qr{(?:unsigned\s+)?long\s+long},
  250. qr{(?:unsigned\s+)?long\s+long\s+int},
  251. qr{unsigned},
  252. qr{float},
  253. qr{double},
  254. qr{bool},
  255. qr{struct\s+$Ident},
  256. qr{union\s+$Ident},
  257. qr{enum\s+$Ident},
  258. qr{${Ident}_t},
  259. qr{${Ident}_handler},
  260. qr{${Ident}_handler_fn},
  261. );
  262. our @modifierList = (
  263. qr{fastcall},
  264. );
  265. our $allowed_asm_includes = qr{(?x:
  266. irq|
  267. memory
  268. )};
  269. # memory.h: ARM has a custom one
  270. sub build_types {
  271. my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
  272. my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
  273. $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
  274. $NonptrType = qr{
  275. (?:$Modifier\s+|const\s+)*
  276. (?:
  277. (?:typeof|__typeof__)\s*\([^\)]*\)|
  278. (?:$typeTypedefs\b)|
  279. (?:${all}\b)
  280. )
  281. (?:\s+$Modifier|\s+const)*
  282. }x;
  283. $Type = qr{
  284. $NonptrType
  285. (?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)?
  286. (?:\s+$Inline|\s+$Modifier)*
  287. }x;
  288. $Declare = qr{(?:$Storage\s+)?$Type};
  289. }
  290. build_types();
  291. our $match_balanced_parentheses = qr/(\((?:[^\(\)]+|(-1))*\))/;
  292. our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
  293. our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s*};
  294. our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
  295. sub deparenthesize {
  296. my ($string) = @_;
  297. return "" if (!defined($string));
  298. $string =~ s@^\s*\(\s*@@g;
  299. $string =~ s@\s*\)\s*$@@g;
  300. $string =~ s@\s+@ @g;
  301. return $string;
  302. }
  303. $chk_signoff = 0 if ($file);
  304. my @dep_includes = ();
  305. my @dep_functions = ();
  306. my $removal = "Documentation/feature-removal-schedule.txt";
  307. if ($tree && -f "$root/$removal") {
  308. open(my $REMOVE, '<', "$root/$removal") ||
  309. die "$P: $removal: open failed - $!\n";
  310. while (<$REMOVE>) {
  311. if (/^Check:\s+(.*\S)/) {
  312. for my $entry (split(/[, ]+/, $1)) {
  313. if ($entry =~ m@include/(.*)@) {
  314. push(@dep_includes, $1);
  315. } elsif ($entry !~ m@/@) {
  316. push(@dep_functions, $entry);
  317. }
  318. }
  319. }
  320. }
  321. close($REMOVE);
  322. }
  323. my @rawlines = ();
  324. my @lines = ();
  325. my $vname;
  326. for my $filename (@ARGV) {
  327. my $FILE;
  328. if ($file) {
  329. open($FILE, '-|', "diff -u /dev/null $filename") ||
  330. die "$P: $filename: diff failed - $!\n";
  331. } elsif ($filename eq '-') {
  332. open($FILE, '<&STDIN');
  333. } else {
  334. open($FILE, '<', "$filename") ||
  335. die "$P: $filename: open failed - $!\n";
  336. }
  337. if ($filename eq '-') {
  338. $vname = 'Your patch';
  339. } else {
  340. $vname = $filename;
  341. }
  342. while (<$FILE>) {
  343. chomp;
  344. push(@rawlines, $_);
  345. }
  346. close($FILE);
  347. if (!process($filename)) {
  348. $exit = 1;
  349. }
  350. @rawlines = ();
  351. @lines = ();
  352. }
  353. exit($exit);
  354. sub top_of_kernel_tree {
  355. my ($root) = @_;
  356. my @tree_check = (
  357. "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
  358. "README", "Documentation", "arch", "include", "drivers",
  359. "fs", "init", "ipc", "kernel", "lib", "scripts",
  360. );
  361. foreach my $check (@tree_check) {
  362. if (! -e $root . '/' . $check) {
  363. return 0;
  364. }
  365. }
  366. return 1;
  367. }
  368. sub parse_email {
  369. my ($formatted_email) = @_;
  370. my $name = "";
  371. my $address = "";
  372. my $comment = "";
  373. if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
  374. $name = $1;
  375. $address = $2;
  376. $comment = $3 if defined $3;
  377. } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
  378. $address = $1;
  379. $comment = $2 if defined $2;
  380. } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
  381. $address = $1;
  382. $comment = $2 if defined $2;
  383. $formatted_email =~ s/$address.*$//;
  384. $name = $formatted_email;
  385. $name =~ s/^\s+|\s+$//g;
  386. $name =~ s/^\"|\"$//g;
  387. # If there's a name left after stripping spaces and
  388. # leading quotes, and the address doesn't have both
  389. # leading and trailing angle brackets, the address
  390. # is invalid. ie:
  391. # "joe smith joe@smith.com" bad
  392. # "joe smith <joe@smith.com" bad
  393. if ($name ne "" && $address !~ /^<[^>]+>$/) {
  394. $name = "";
  395. $address = "";
  396. $comment = "";
  397. }
  398. }
  399. $name =~ s/^\s+|\s+$//g;
  400. $name =~ s/^\"|\"$//g;
  401. $address =~ s/^\s+|\s+$//g;
  402. $address =~ s/^\<|\>$//g;
  403. if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
  404. $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
  405. $name = "\"$name\"";
  406. }
  407. return ($name, $address, $comment);
  408. }
  409. sub format_email {
  410. my ($name, $address) = @_;
  411. my $formatted_email;
  412. $name =~ s/^\s+|\s+$//g;
  413. $name =~ s/^\"|\"$//g;
  414. $address =~ s/^\s+|\s+$//g;
  415. if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
  416. $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
  417. $name = "\"$name\"";
  418. }
  419. if ("$name" eq "") {
  420. $formatted_email = "$address";
  421. } else {
  422. $formatted_email = "$name <$address>";
  423. }
  424. return $formatted_email;
  425. }
  426. sub which_conf {
  427. my ($conf) = @_;
  428. foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
  429. if (-e "$path/$conf") {
  430. return "$path/$conf";
  431. }
  432. }
  433. return "";
  434. }
  435. sub expand_tabs {
  436. my ($str) = @_;
  437. my $res = '';
  438. my $n = 0;
  439. for my $c (split(//, $str)) {
  440. if ($c eq "\t") {
  441. $res .= ' ';
  442. $n++;
  443. for (; ($n % 8) != 0; $n++) {
  444. $res .= ' ';
  445. }
  446. next;
  447. }
  448. $res .= $c;
  449. $n++;
  450. }
  451. return $res;
  452. }
  453. sub copy_spacing {
  454. (my $res = shift) =~ tr/\t/ /c;
  455. return $res;
  456. }
  457. sub line_stats {
  458. my ($line) = @_;
  459. # Drop the diff line leader and expand tabs
  460. $line =~ s/^.//;
  461. $line = expand_tabs($line);
  462. # Pick the indent from the front of the line.
  463. my ($white) = ($line =~ /^(\s*)/);
  464. return (length($line), length($white));
  465. }
  466. my $sanitise_quote = '';
  467. sub sanitise_line_reset {
  468. my ($in_comment) = @_;
  469. if ($in_comment) {
  470. $sanitise_quote = '*/';
  471. } else {
  472. $sanitise_quote = '';
  473. }
  474. }
  475. sub sanitise_line {
  476. my ($line) = @_;
  477. my $res = '';
  478. my $l = '';
  479. my $qlen = 0;
  480. my $off = 0;
  481. my $c;
  482. # Always copy over the diff marker.
  483. $res = substr($line, 0, 1);
  484. for ($off = 1; $off < length($line); $off++) {
  485. $c = substr($line, $off, 1);
  486. # Comments we are wacking completly including the begin
  487. # and end, all to $;.
  488. if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
  489. $sanitise_quote = '*/';
  490. substr($res, $off, 2, "$;$;");
  491. $off++;
  492. next;
  493. }
  494. if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
  495. $sanitise_quote = '';
  496. substr($res, $off, 2, "$;$;");
  497. $off++;
  498. next;
  499. }
  500. if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
  501. $sanitise_quote = '//';
  502. substr($res, $off, 2, $sanitise_quote);
  503. $off++;
  504. next;
  505. }
  506. # A \ in a string means ignore the next character.
  507. if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
  508. $c eq "\\") {
  509. substr($res, $off, 2, 'XX');
  510. $off++;
  511. next;
  512. }
  513. # Regular quotes.
  514. if ($c eq "'" || $c eq '"') {
  515. if ($sanitise_quote eq '') {
  516. $sanitise_quote = $c;
  517. substr($res, $off, 1, $c);
  518. next;
  519. } elsif ($sanitise_quote eq $c) {
  520. $sanitise_quote = '';
  521. }
  522. }
  523. #print "c<$c> SQ<$sanitise_quote>\n";
  524. if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
  525. substr($res, $off, 1, $;);
  526. } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
  527. substr($res, $off, 1, $;);
  528. } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
  529. substr($res, $off, 1, 'X');
  530. } else {
  531. substr($res, $off, 1, $c);
  532. }
  533. }
  534. if ($sanitise_quote eq '//') {
  535. $sanitise_quote = '';
  536. }
  537. # The pathname on a #include may be surrounded by '<' and '>'.
  538. if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
  539. my $clean = 'X' x length($1);
  540. $res =~ s@\<.*\>@<$clean>@;
  541. # The whole of a #error is a string.
  542. } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
  543. my $clean = 'X' x length($1);
  544. $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
  545. }
  546. return $res;
  547. }
  548. sub ctx_statement_block {
  549. my ($linenr, $remain, $off) = @_;
  550. my $line = $linenr - 1;
  551. my $blk = '';
  552. my $soff = $off;
  553. my $coff = $off - 1;
  554. my $coff_set = 0;
  555. my $loff = 0;
  556. my $type = '';
  557. my $level = 0;
  558. my @stack = ();
  559. my $p;
  560. my $c;
  561. my $len = 0;
  562. my $remainder;
  563. while (1) {
  564. @stack = (['', 0]) if ($#stack == -1);
  565. #warn "CSB: blk<$blk> remain<$remain>\n";
  566. # If we are about to drop off the end, pull in more
  567. # context.
  568. if ($off >= $len) {
  569. for (; $remain > 0; $line++) {
  570. last if (!defined $lines[$line]);
  571. next if ($lines[$line] =~ /^-/);
  572. $remain--;
  573. $loff = $len;
  574. $blk .= $lines[$line] . "\n";
  575. $len = length($blk);
  576. $line++;
  577. last;
  578. }
  579. # Bail if there is no further context.
  580. #warn "CSB: blk<$blk> off<$off> len<$len>\n";
  581. if ($off >= $len) {
  582. last;
  583. }
  584. if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
  585. $level++;
  586. $type = '#';
  587. }
  588. }
  589. $p = $c;
  590. $c = substr($blk, $off, 1);
  591. $remainder = substr($blk, $off);
  592. #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
  593. # Handle nested #if/#else.
  594. if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
  595. push(@stack, [ $type, $level ]);
  596. } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
  597. ($type, $level) = @{$stack[$#stack - 1]};
  598. } elsif ($remainder =~ /^#\s*endif\b/) {
  599. ($type, $level) = @{pop(@stack)};
  600. }
  601. # Statement ends at the ';' or a close '}' at the
  602. # outermost level.
  603. if ($level == 0 && $c eq ';') {
  604. last;
  605. }
  606. # An else is really a conditional as long as its not else if
  607. if ($level == 0 && $coff_set == 0 &&
  608. (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
  609. $remainder =~ /^(else)(?:\s|{)/ &&
  610. $remainder !~ /^else\s+if\b/) {
  611. $coff = $off + length($1) - 1;
  612. $coff_set = 1;
  613. #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
  614. #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
  615. }
  616. if (($type eq '' || $type eq '(') && $c eq '(') {
  617. $level++;
  618. $type = '(';
  619. }
  620. if ($type eq '(' && $c eq ')') {
  621. $level--;
  622. $type = ($level != 0)? '(' : '';
  623. if ($level == 0 && $coff < $soff) {
  624. $coff = $off;
  625. $coff_set = 1;
  626. #warn "CSB: mark coff<$coff>\n";
  627. }
  628. }
  629. if (($type eq '' || $type eq '{') && $c eq '{') {
  630. $level++;
  631. $type = '{';
  632. }
  633. if ($type eq '{' && $c eq '}') {
  634. $level--;
  635. $type = ($level != 0)? '{' : '';
  636. if ($level == 0) {
  637. if (substr($blk, $off + 1, 1) eq ';') {
  638. $off++;
  639. }
  640. last;
  641. }
  642. }
  643. # Preprocessor commands end at the newline unless escaped.
  644. if ($type eq '#' && $c eq "\n" && $p ne "\\") {
  645. $level--;
  646. $type = '';
  647. $off++;
  648. last;
  649. }
  650. $off++;
  651. }
  652. # We are truly at the end, so shuffle to the next line.
  653. if ($off == $len) {
  654. $loff = $len + 1;
  655. $line++;
  656. $remain--;
  657. }
  658. my $statement = substr($blk, $soff, $off - $soff + 1);
  659. my $condition = substr($blk, $soff, $coff - $soff + 1);
  660. #warn "STATEMENT<$statement>\n";
  661. #warn "CONDITION<$condition>\n";
  662. #print "coff<$coff> soff<$off> loff<$loff>\n";
  663. return ($statement, $condition,
  664. $line, $remain + 1, $off - $loff + 1, $level);
  665. }
  666. sub statement_lines {
  667. my ($stmt) = @_;
  668. # Strip the diff line prefixes and rip blank lines at start and end.
  669. $stmt =~ s/(^|\n)./$1/g;
  670. $stmt =~ s/^\s*//;
  671. $stmt =~ s/\s*$//;
  672. my @stmt_lines = ($stmt =~ /\n/g);
  673. return $#stmt_lines + 2;
  674. }
  675. sub statement_rawlines {
  676. my ($stmt) = @_;
  677. my @stmt_lines = ($stmt =~ /\n/g);
  678. return $#stmt_lines + 2;
  679. }
  680. sub statement_block_size {
  681. my ($stmt) = @_;
  682. $stmt =~ s/(^|\n)./$1/g;
  683. $stmt =~ s/^\s*{//;
  684. $stmt =~ s/}\s*$//;
  685. $stmt =~ s/^\s*//;
  686. $stmt =~ s/\s*$//;
  687. my @stmt_lines = ($stmt =~ /\n/g);
  688. my @stmt_statements = ($stmt =~ /;/g);
  689. my $stmt_lines = $#stmt_lines + 2;
  690. my $stmt_statements = $#stmt_statements + 1;
  691. if ($stmt_lines > $stmt_statements) {
  692. return $stmt_lines;
  693. } else {
  694. return $stmt_statements;
  695. }
  696. }
  697. sub ctx_statement_full {
  698. my ($linenr, $remain, $off) = @_;
  699. my ($statement, $condition, $level);
  700. my (@chunks);
  701. # Grab the first conditional/block pair.
  702. ($statement, $condition, $linenr, $remain, $off, $level) =
  703. ctx_statement_block($linenr, $remain, $off);
  704. #print "F: c<$condition> s<$statement> remain<$remain>\n";
  705. push(@chunks, [ $condition, $statement ]);
  706. if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
  707. return ($level, $linenr, @chunks);
  708. }
  709. # Pull in the following conditional/block pairs and see if they
  710. # could continue the statement.
  711. for (;;) {
  712. ($statement, $condition, $linenr, $remain, $off, $level) =
  713. ctx_statement_block($linenr, $remain, $off);
  714. #print "C: c<$condition> s<$statement> remain<$remain>\n";
  715. last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
  716. #print "C: push\n";
  717. push(@chunks, [ $condition, $statement ]);
  718. }
  719. return ($level, $linenr, @chunks);
  720. }
  721. sub ctx_block_get {
  722. my ($linenr, $remain, $outer, $open, $close, $off) = @_;
  723. my $line;
  724. my $start = $linenr - 1;
  725. my $blk = '';
  726. my @o;
  727. my @c;
  728. my @res = ();
  729. my $level = 0;
  730. my @stack = ($level);
  731. for ($line = $start; $remain > 0; $line++) {
  732. next if ($rawlines[$line] =~ /^-/);
  733. $remain--;
  734. $blk .= $rawlines[$line];
  735. # Handle nested #if/#else.
  736. if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
  737. push(@stack, $level);
  738. } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
  739. $level = $stack[$#stack - 1];
  740. } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
  741. $level = pop(@stack);
  742. }
  743. foreach my $c (split(//, $lines[$line])) {
  744. ##print "C<$c>L<$level><$open$close>O<$off>\n";
  745. if ($off > 0) {
  746. $off--;
  747. next;
  748. }
  749. if ($c eq $close && $level > 0) {
  750. $level--;
  751. last if ($level == 0);
  752. } elsif ($c eq $open) {
  753. $level++;
  754. }
  755. }
  756. if (!$outer || $level <= 1) {
  757. push(@res, $rawlines[$line]);
  758. }
  759. last if ($level == 0);
  760. }
  761. return ($level, @res);
  762. }
  763. sub ctx_block_outer {
  764. my ($linenr, $remain) = @_;
  765. my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
  766. return @r;
  767. }
  768. sub ctx_block {
  769. my ($linenr, $remain) = @_;
  770. my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
  771. return @r;
  772. }
  773. sub ctx_statement {
  774. my ($linenr, $remain, $off) = @_;
  775. my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
  776. return @r;
  777. }
  778. sub ctx_block_level {
  779. my ($linenr, $remain) = @_;
  780. return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
  781. }
  782. sub ctx_statement_level {
  783. my ($linenr, $remain, $off) = @_;
  784. return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
  785. }
  786. sub ctx_locate_comment {
  787. my ($first_line, $end_line) = @_;
  788. # Catch a comment on the end of the line itself.
  789. my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
  790. return $current_comment if (defined $current_comment);
  791. # Look through the context and try and figure out if there is a
  792. # comment.
  793. my $in_comment = 0;
  794. $current_comment = '';
  795. for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
  796. my $line = $rawlines[$linenr - 1];
  797. #warn " $line\n";
  798. if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
  799. $in_comment = 1;
  800. }
  801. if ($line =~ m@/\*@) {
  802. $in_comment = 1;
  803. }
  804. if (!$in_comment && $current_comment ne '') {
  805. $current_comment = '';
  806. }
  807. $current_comment .= $line . "\n" if ($in_comment);
  808. if ($line =~ m@\*/@) {
  809. $in_comment = 0;
  810. }
  811. }
  812. chomp($current_comment);
  813. return($current_comment);
  814. }
  815. sub ctx_has_comment {
  816. my ($first_line, $end_line) = @_;
  817. my $cmt = ctx_locate_comment($first_line, $end_line);
  818. ##print "LINE: $rawlines[$end_line - 1 ]\n";
  819. ##print "CMMT: $cmt\n";
  820. return ($cmt ne '');
  821. }
  822. sub raw_line {
  823. my ($linenr, $cnt) = @_;
  824. my $offset = $linenr - 1;
  825. $cnt++;
  826. my $line;
  827. while ($cnt) {
  828. $line = $rawlines[$offset++];
  829. next if (defined($line) && $line =~ /^-/);
  830. $cnt--;
  831. }
  832. return $line;
  833. }
  834. sub cat_vet {
  835. my ($vet) = @_;
  836. my ($res, $coded);
  837. $res = '';
  838. while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
  839. $res .= $1;
  840. if ($2 ne '') {
  841. $coded = sprintf("^%c", unpack('C', $2) + 64);
  842. $res .= $coded;
  843. }
  844. }
  845. $res =~ s/$/\$/;
  846. return $res;
  847. }
  848. my $av_preprocessor = 0;
  849. my $av_pending;
  850. my @av_paren_type;
  851. my $av_pend_colon;
  852. sub annotate_reset {
  853. $av_preprocessor = 0;
  854. $av_pending = '_';
  855. @av_paren_type = ('E');
  856. $av_pend_colon = 'O';
  857. }
  858. sub annotate_values {
  859. my ($stream, $type) = @_;
  860. my $res;
  861. my $var = '_' x length($stream);
  862. my $cur = $stream;
  863. print "$stream\n" if ($dbg_values > 1);
  864. while (length($cur)) {
  865. @av_paren_type = ('E') if ($#av_paren_type < 0);
  866. print " <" . join('', @av_paren_type) .
  867. "> <$type> <$av_pending>" if ($dbg_values > 1);
  868. if ($cur =~ /^(\s+)/o) {
  869. print "WS($1)\n" if ($dbg_values > 1);
  870. if ($1 =~ /\n/ && $av_preprocessor) {
  871. $type = pop(@av_paren_type);
  872. $av_preprocessor = 0;
  873. }
  874. } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
  875. print "CAST($1)\n" if ($dbg_values > 1);
  876. push(@av_paren_type, $type);
  877. $type = 'c';
  878. } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
  879. print "DECLARE($1)\n" if ($dbg_values > 1);
  880. $type = 'T';
  881. } elsif ($cur =~ /^($Modifier)\s*/) {
  882. print "MODIFIER($1)\n" if ($dbg_values > 1);
  883. $type = 'T';
  884. } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
  885. print "DEFINE($1,$2)\n" if ($dbg_values > 1);
  886. $av_preprocessor = 1;
  887. push(@av_paren_type, $type);
  888. if ($2 ne '') {
  889. $av_pending = 'N';
  890. }
  891. $type = 'E';
  892. } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
  893. print "UNDEF($1)\n" if ($dbg_values > 1);
  894. $av_preprocessor = 1;
  895. push(@av_paren_type, $type);
  896. } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
  897. print "PRE_START($1)\n" if ($dbg_values > 1);
  898. $av_preprocessor = 1;
  899. push(@av_paren_type, $type);
  900. push(@av_paren_type, $type);
  901. $type = 'E';
  902. } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
  903. print "PRE_RESTART($1)\n" if ($dbg_values > 1);
  904. $av_preprocessor = 1;
  905. push(@av_paren_type, $av_paren_type[$#av_paren_type]);
  906. $type = 'E';
  907. } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
  908. print "PRE_END($1)\n" if ($dbg_values > 1);
  909. $av_preprocessor = 1;
  910. # Assume all arms of the conditional end as this
  911. # one does, and continue as if the #endif was not here.
  912. pop(@av_paren_type);
  913. push(@av_paren_type, $type);
  914. $type = 'E';
  915. } elsif ($cur =~ /^(\\\n)/o) {
  916. print "PRECONT($1)\n" if ($dbg_values > 1);
  917. } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
  918. print "ATTR($1)\n" if ($dbg_values > 1);
  919. $av_pending = $type;
  920. $type = 'N';
  921. } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
  922. print "SIZEOF($1)\n" if ($dbg_values > 1);
  923. if (defined $2) {
  924. $av_pending = 'V';
  925. }
  926. $type = 'N';
  927. } elsif ($cur =~ /^(if|while|for)\b/o) {
  928. print "COND($1)\n" if ($dbg_values > 1);
  929. $av_pending = 'E';
  930. $type = 'N';
  931. } elsif ($cur =~/^(case)/o) {
  932. print "CASE($1)\n" if ($dbg_values > 1);
  933. $av_pend_colon = 'C';
  934. $type = 'N';
  935. } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
  936. print "KEYWORD($1)\n" if ($dbg_values > 1);
  937. $type = 'N';
  938. } elsif ($cur =~ /^(\()/o) {
  939. print "PAREN('$1')\n" if ($dbg_values > 1);
  940. push(@av_paren_type, $av_pending);
  941. $av_pending = '_';
  942. $type = 'N';
  943. } elsif ($cur =~ /^(\))/o) {
  944. my $new_type = pop(@av_paren_type);
  945. if ($new_type ne '_') {
  946. $type = $new_type;
  947. print "PAREN('$1') -> $type\n"
  948. if ($dbg_values > 1);
  949. } else {
  950. print "PAREN('$1')\n" if ($dbg_values > 1);
  951. }
  952. } elsif ($cur =~ /^($Ident)\s*\(/o) {
  953. print "FUNC($1)\n" if ($dbg_values > 1);
  954. $type = 'V';
  955. $av_pending = 'V';
  956. } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
  957. if (defined $2 && $type eq 'C' || $type eq 'T') {
  958. $av_pend_colon = 'B';
  959. } elsif ($type eq 'E') {
  960. $av_pend_colon = 'L';
  961. }
  962. print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
  963. $type = 'V';
  964. } elsif ($cur =~ /^($Ident|$Constant)/o) {
  965. print "IDENT($1)\n" if ($dbg_values > 1);
  966. $type = 'V';
  967. } elsif ($cur =~ /^($Assignment)/o) {
  968. print "ASSIGN($1)\n" if ($dbg_values > 1);
  969. $type = 'N';
  970. } elsif ($cur =~/^(;|{|})/) {
  971. print "END($1)\n" if ($dbg_values > 1);
  972. $type = 'E';
  973. $av_pend_colon = 'O';
  974. } elsif ($cur =~/^(,)/) {
  975. print "COMMA($1)\n" if ($dbg_values > 1);
  976. $type = 'C';
  977. } elsif ($cur =~ /^(\?)/o) {
  978. print "QUESTION($1)\n" if ($dbg_values > 1);
  979. $type = 'N';
  980. } elsif ($cur =~ /^(:)/o) {
  981. print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
  982. substr($var, length($res), 1, $av_pend_colon);
  983. if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
  984. $type = 'E';
  985. } else {
  986. $type = 'N';
  987. }
  988. $av_pend_colon = 'O';
  989. } elsif ($cur =~ /^(\[)/o) {
  990. print "CLOSE($1)\n" if ($dbg_values > 1);
  991. $type = 'N';
  992. } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
  993. my $variant;
  994. print "OPV($1)\n" if ($dbg_values > 1);
  995. if ($type eq 'V') {
  996. $variant = 'B';
  997. } else {
  998. $variant = 'U';
  999. }
  1000. substr($var, length($res), 1, $variant);
  1001. $type = 'N';
  1002. } elsif ($cur =~ /^($Operators)/o) {
  1003. print "OP($1)\n" if ($dbg_values > 1);
  1004. if ($1 ne '++' && $1 ne '--') {
  1005. $type = 'N';
  1006. }
  1007. } elsif ($cur =~ /(^.)/o) {
  1008. print "C($1)\n" if ($dbg_values > 1);
  1009. }
  1010. if (defined $1) {
  1011. $cur = substr($cur, length($1));
  1012. $res .= $type x length($1);
  1013. }
  1014. }
  1015. return ($res, $var);
  1016. }
  1017. sub possible {
  1018. my ($possible, $line) = @_;
  1019. my $notPermitted = qr{(?:
  1020. ^(?:
  1021. $Modifier|
  1022. $Storage|
  1023. $Type|
  1024. DEFINE_\S+
  1025. )$|
  1026. ^(?:
  1027. goto|
  1028. return|
  1029. case|
  1030. else|
  1031. asm|__asm__|
  1032. do|
  1033. \#|
  1034. \#\#|
  1035. )(?:\s|$)|
  1036. ^(?:typedef|struct|enum)\b
  1037. )}x;
  1038. warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
  1039. if ($possible !~ $notPermitted) {
  1040. # Check for modifiers.
  1041. $possible =~ s/\s*$Storage\s*//g;
  1042. $possible =~ s/\s*$Sparse\s*//g;
  1043. if ($possible =~ /^\s*$/) {
  1044. } elsif ($possible =~ /\s/) {
  1045. $possible =~ s/\s*$Type\s*//g;
  1046. for my $modifier (split(' ', $possible)) {
  1047. if ($modifier !~ $notPermitted) {
  1048. warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
  1049. push(@modifierList, $modifier);
  1050. }
  1051. }
  1052. } else {
  1053. warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
  1054. push(@typeList, $possible);
  1055. }
  1056. build_types();
  1057. } else {
  1058. warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
  1059. }
  1060. }
  1061. my $prefix = '';
  1062. sub show_type {
  1063. return !defined $ignore_type{$_[0]};
  1064. }
  1065. sub report {
  1066. if (!show_type($_[1]) ||
  1067. (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) {
  1068. return 0;
  1069. }
  1070. my $line;
  1071. if ($show_types) {
  1072. $line = "$prefix$_[0]:$_[1]: $_[2]\n";
  1073. } else {
  1074. $line = "$prefix$_[0]: $_[2]\n";
  1075. }
  1076. $line = (split('\n', $line))[0] . "\n" if ($terse);
  1077. push(our @report, $line);
  1078. return 1;
  1079. }
  1080. sub report_dump {
  1081. our @report;
  1082. }
  1083. sub ERROR {
  1084. if (report("ERROR", $_[0], $_[1])) {
  1085. our $clean = 0;
  1086. our $cnt_error++;
  1087. }
  1088. }
  1089. sub WARN {
  1090. if (report("WARNING", $_[0], $_[1])) {
  1091. our $clean = 0;
  1092. our $cnt_warn++;
  1093. }
  1094. }
  1095. sub CHK {
  1096. if ($check && report("CHECK", $_[0], $_[1])) {
  1097. our $clean = 0;
  1098. our $cnt_chk++;
  1099. }
  1100. }
  1101. sub check_absolute_file {
  1102. my ($absolute, $herecurr) = @_;
  1103. my $file = $absolute;
  1104. ##print "absolute<$absolute>\n";
  1105. # See if any suffix of this path is a path within the tree.
  1106. while ($file =~ s@^[^/]*/@@) {
  1107. if (-f "$root/$file") {
  1108. ##print "file<$file>\n";
  1109. last;
  1110. }
  1111. }
  1112. if (! -f _) {
  1113. return 0;
  1114. }
  1115. # It is, so see if the prefix is acceptable.
  1116. my $prefix = $absolute;
  1117. substr($prefix, -length($file)) = '';
  1118. ##print "prefix<$prefix>\n";
  1119. if ($prefix ne ".../") {
  1120. WARN("USE_RELATIVE_PATH",
  1121. "use relative pathname instead of absolute in changelog text\n" . $herecurr);
  1122. }
  1123. }
  1124. sub process {
  1125. my $filename = shift;
  1126. my $linenr=0;
  1127. my $prevline="";
  1128. my $prevrawline="";
  1129. my $stashline="";
  1130. my $stashrawline="";
  1131. my $length;
  1132. my $indent;
  1133. my $previndent=0;
  1134. my $stashindent=0;
  1135. our $clean = 1;
  1136. my $signoff = 0;
  1137. my $is_patch = 0;
  1138. my $in_header_lines = 1;
  1139. my $in_commit_log = 0; #Scanning lines before patch
  1140. our @report = ();
  1141. our $cnt_lines = 0;
  1142. our $cnt_error = 0;
  1143. our $cnt_warn = 0;
  1144. our $cnt_chk = 0;
  1145. # Trace the real file/line as we go.
  1146. my $realfile = '';
  1147. my $realline = 0;
  1148. my $realcnt = 0;
  1149. my $here = '';
  1150. my $in_comment = 0;
  1151. my $comment_edge = 0;
  1152. my $first_line = 0;
  1153. my $p1_prefix = '';
  1154. my $prev_values = 'E';
  1155. # suppression flags
  1156. my %suppress_ifbraces;
  1157. my %suppress_whiletrailers;
  1158. my %suppress_export;
  1159. my $suppress_statement = 0;
  1160. # Pre-scan the patch sanitizing the lines.
  1161. # Pre-scan the patch looking for any __setup documentation.
  1162. #
  1163. my @setup_docs = ();
  1164. my $setup_docs = 0;
  1165. sanitise_line_reset();
  1166. my $line;
  1167. foreach my $rawline (@rawlines) {
  1168. $linenr++;
  1169. $line = $rawline;
  1170. if ($rawline=~/^\+\+\+\s+(\S+)/) {
  1171. $setup_docs = 0;
  1172. if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
  1173. $setup_docs = 1;
  1174. }
  1175. #next;
  1176. }
  1177. if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
  1178. $realline=$1-1;
  1179. if (defined $2) {
  1180. $realcnt=$3+1;
  1181. } else {
  1182. $realcnt=1+1;
  1183. }
  1184. $in_comment = 0;
  1185. # Guestimate if this is a continuing comment. Run
  1186. # the context looking for a comment "edge". If this
  1187. # edge is a close comment then we must be in a comment
  1188. # at context start.
  1189. my $edge;
  1190. my $cnt = $realcnt;
  1191. for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
  1192. next if (defined $rawlines[$ln - 1] &&
  1193. $rawlines[$ln - 1] =~ /^-/);
  1194. $cnt--;
  1195. #print "RAW<$rawlines[$ln - 1]>\n";
  1196. last if (!defined $rawlines[$ln - 1]);
  1197. if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
  1198. $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
  1199. ($edge) = $1;
  1200. last;
  1201. }
  1202. }
  1203. if (defined $edge && $edge eq '*/') {
  1204. $in_comment = 1;
  1205. }
  1206. # Guestimate if this is a continuing comment. If this
  1207. # is the start of a diff block and this line starts
  1208. # ' *' then it is very likely a comment.
  1209. if (!defined $edge &&
  1210. $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
  1211. {
  1212. $in_comment = 1;
  1213. }
  1214. ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
  1215. sanitise_line_reset($in_comment);
  1216. } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
  1217. # Standardise the strings and chars within the input to
  1218. # simplify matching -- only bother with positive lines.
  1219. $line = sanitise_line($rawline);
  1220. }
  1221. push(@lines, $line);
  1222. if ($realcnt > 1) {
  1223. $realcnt-- if ($line =~ /^(?:\+| |$)/);
  1224. } else {
  1225. $realcnt = 0;
  1226. }
  1227. #print "==>$rawline\n";
  1228. #print "-->$line\n";
  1229. if ($setup_docs && $line =~ /^\+/) {
  1230. push(@setup_docs, $line);
  1231. }
  1232. }
  1233. $prefix = '';
  1234. $realcnt = 0;
  1235. $linenr = 0;
  1236. foreach my $line (@lines) {
  1237. $linenr++;
  1238. my $rawline = $rawlines[$linenr - 1];
  1239. #extract the line range in the file after the patch is applied
  1240. if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
  1241. $is_patch = 1;
  1242. $first_line = $linenr + 1;
  1243. $realline=$1-1;
  1244. if (defined $2) {
  1245. $realcnt=$3+1;
  1246. } else {
  1247. $realcnt=1+1;
  1248. }
  1249. annotate_reset();
  1250. $prev_values = 'E';
  1251. %suppress_ifbraces = ();
  1252. %suppress_whiletrailers = ();
  1253. %suppress_export = ();
  1254. $suppress_statement = 0;
  1255. next;
  1256. # track the line number as we move through the hunk, note that
  1257. # new versions of GNU diff omit the leading space on completely
  1258. # blank context lines so we need to count that too.
  1259. } elsif ($line =~ /^( |\+|$)/) {
  1260. $realline++;
  1261. $realcnt-- if ($realcnt != 0);
  1262. # Measure the line length and indent.
  1263. ($length, $indent) = line_stats($rawline);
  1264. # Track the previous line.
  1265. ($prevline, $stashline) = ($stashline, $line);
  1266. ($previndent, $stashindent) = ($stashindent, $indent);
  1267. ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
  1268. #warn "line<$line>\n";
  1269. } elsif ($realcnt == 1) {
  1270. $realcnt--;
  1271. }
  1272. my $hunk_line = ($realcnt != 0);
  1273. #make up the handle for any error we report on this line
  1274. $prefix = "$filename:$realline: " if ($emacs && $file);
  1275. $prefix = "$filename:$linenr: " if ($emacs && !$file);
  1276. $here = "#$linenr: " if (!$file);
  1277. $here = "#$realline: " if ($file);
  1278. # extract the filename as it passes
  1279. if ($line =~ /^diff --git.*?(\S+)$/) {
  1280. $realfile = $1;
  1281. $realfile =~ s@^([^/]*)/@@;
  1282. $in_commit_log = 0;
  1283. } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
  1284. $realfile = $1;
  1285. $realfile =~ s@^([^/]*)/@@;
  1286. $in_commit_log = 0;
  1287. $p1_prefix = $1;
  1288. if (!$file && $tree && $p1_prefix ne '' &&
  1289. -e "$root/$p1_prefix") {
  1290. WARN("PATCH_PREFIX",
  1291. "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
  1292. }
  1293. if ($realfile =~ m@^include/asm/@) {
  1294. ERROR("MODIFIED_INCLUDE_ASM",
  1295. "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
  1296. }
  1297. next;
  1298. }
  1299. $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
  1300. my $hereline = "$here\n$rawline\n";
  1301. my $herecurr = "$here\n$rawline\n";
  1302. my $hereprev = "$here\n$prevrawline\n$rawline\n";
  1303. $cnt_lines++ if ($realcnt != 0);
  1304. # Check for incorrect file permissions
  1305. if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
  1306. my $permhere = $here . "FILE: $realfile\n";
  1307. if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
  1308. ERROR("EXECUTE_PERMISSIONS",
  1309. "do not set execute permissions for source files\n" . $permhere);
  1310. }
  1311. }
  1312. # Check the patch for a signoff:
  1313. if ($line =~ /^\s*signed-off-by:/i) {
  1314. $signoff++;
  1315. $in_commit_log = 0;
  1316. }
  1317. # Check signature styles
  1318. if (!$in_header_lines &&
  1319. $line =~ /^(\s*)($signature_tags)(\s*)(.*)/) {
  1320. my $space_before = $1;
  1321. my $sign_off = $2;
  1322. my $space_after = $3;
  1323. my $email = $4;
  1324. my $ucfirst_sign_off = ucfirst(lc($sign_off));
  1325. if (defined $space_before && $space_before ne "") {
  1326. WARN("BAD_SIGN_OFF",
  1327. "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr);
  1328. }
  1329. if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
  1330. WARN("BAD_SIGN_OFF",
  1331. "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr);
  1332. }
  1333. if (!defined $space_after || $space_after ne " ") {
  1334. WARN("BAD_SIGN_OFF",
  1335. "Use a single space after $ucfirst_sign_off\n" . $herecurr);
  1336. }
  1337. my ($email_name, $email_address, $comment) = parse_email($email);
  1338. my $suggested_email = format_email(($email_name, $email_address));
  1339. if ($suggested_email eq "") {
  1340. ERROR("BAD_SIGN_OFF",
  1341. "Unrecognized email address: '$email'\n" . $herecurr);
  1342. } else {
  1343. my $dequoted = $suggested_email;
  1344. $dequoted =~ s/^"//;
  1345. $dequoted =~ s/" </ </;
  1346. # Don't force email to have quotes
  1347. # Allow just an angle bracketed address
  1348. if ("$dequoted$comment" ne $email &&
  1349. "<$email_address>$comment" ne $email &&
  1350. "$suggested_email$comment" ne $email) {
  1351. WARN("BAD_SIGN_OFF",
  1352. "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
  1353. }
  1354. }
  1355. }
  1356. # Check for wrappage within a valid hunk of the file
  1357. if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
  1358. ERROR("CORRUPTED_PATCH",
  1359. "patch seems to be corrupt (line wrapped?)\n" .
  1360. $herecurr) if (!$emitted_corrupt++);
  1361. }
  1362. # Check for absolute kernel paths.
  1363. if ($tree) {
  1364. while ($line =~ m{(?:^|\s)(/\S*)}g) {
  1365. my $file = $1;
  1366. if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
  1367. check_absolute_file($1, $herecurr)) {
  1368. #
  1369. } else {
  1370. check_absolute_file($file, $herecurr);
  1371. }
  1372. }
  1373. }
  1374. # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
  1375. if (($realfile =~ /^$/ || $line =~ /^\+/) &&
  1376. $rawline !~ m/^$UTF8*$/) {
  1377. my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
  1378. my $blank = copy_spacing($rawline);
  1379. my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
  1380. my $hereptr = "$hereline$ptr\n";
  1381. CHK("INVALID_UTF8",
  1382. "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
  1383. }
  1384. # Check if it's the start of a commit log
  1385. # (not a header line and we haven't seen the patch filename)
  1386. if ($in_header_lines && $realfile =~ /^$/ &&
  1387. $rawline !~ /^(commit\b|from\b|[\w-]+:).+$/i) {
  1388. $in_header_lines = 0;
  1389. $in_commit_log = 1;
  1390. }
  1391. # Still not yet in a patch, check for any UTF-8
  1392. if ($in_commit_log && $realfile =~ /^$/ &&
  1393. $rawline =~ /$NON_ASCII_UTF8/) {
  1394. CHK("UTF8_BEFORE_PATCH",
  1395. "8-bit UTF-8 used in possible commit log\n" . $herecurr);
  1396. }
  1397. # ignore non-hunk lines and lines being removed
  1398. next if (!$hunk_line || $line =~ /^-/);
  1399. #trailing whitespace
  1400. if ($line =~ /^\+.*\015/) {
  1401. my $herevet = "$here\n" . cat_vet($rawline) . "\n";
  1402. ERROR("DOS_LINE_ENDINGS",
  1403. "DOS line endings\n" . $herevet);
  1404. } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
  1405. my $herevet = "$here\n" . cat_vet($rawline) . "\n";
  1406. ERROR("TRAILING_WHITESPACE",
  1407. "trailing whitespace\n" . $herevet);
  1408. $rpt_cleaners = 1;
  1409. }
  1410. # check for Kconfig help text having a real description
  1411. # Only applies when adding the entry originally, after that we do not have
  1412. # sufficient context to determine whether it is indeed long enough.
  1413. if ($realfile =~ /Kconfig/ &&
  1414. $line =~ /.\s*config\s+/) {
  1415. my $length = 0;
  1416. my $cnt = $realcnt;
  1417. my $ln = $linenr + 1;
  1418. my $f;
  1419. my $is_start = 0;
  1420. my $is_end = 0;
  1421. for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
  1422. $f = $lines[$ln - 1];
  1423. $cnt-- if ($lines[$ln - 1] !~ /^-/);
  1424. $is_end = $lines[$ln - 1] =~ /^\+/;
  1425. next if ($f =~ /^-/);
  1426. if ($lines[$ln - 1] =~ /.\s*(?:bool|tristate)\s*\"/) {
  1427. $is_start = 1;
  1428. } elsif ($lines[$ln - 1] =~ /.\s*(?:---)?help(?:---)?$/) {
  1429. $length = -1;
  1430. }
  1431. $f =~ s/^.//;
  1432. $f =~ s/#.*//;
  1433. $f =~ s/^\s+//;
  1434. next if ($f =~ /^$/);
  1435. if ($f =~ /^\s*config\s/) {
  1436. $is_end = 1;
  1437. last;
  1438. }
  1439. $length++;
  1440. }
  1441. WARN("CONFIG_DESCRIPTION",
  1442. "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_start && $is_end && $length < 4);
  1443. #print "is_start<$is_start> is_end<$is_end> length<$length>\n";
  1444. }
  1445. if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
  1446. ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
  1447. my $flag = $1;
  1448. my $replacement = {
  1449. 'EXTRA_AFLAGS' => 'asflags-y',
  1450. 'EXTRA_CFLAGS' => 'ccflags-y',
  1451. 'EXTRA_CPPFLAGS' => 'cppflags-y',
  1452. 'EXTRA_LDFLAGS' => 'ldflags-y',
  1453. };
  1454. WARN("DEPRECATED_VARIABLE",
  1455. "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
  1456. }
  1457. # check we are in a valid source file if not then ignore this hunk
  1458. next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
  1459. #80 column limit
  1460. if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
  1461. $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
  1462. !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
  1463. $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
  1464. $length > 80)
  1465. {
  1466. WARN("LONG_LINE",
  1467. "line over 80 characters\n" . $herecurr);
  1468. }
  1469. # check for spaces before a quoted newline
  1470. if ($rawline =~ /^.*\".*\s\\n/) {
  1471. WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
  1472. "unnecessary whitespace before a quoted newline\n" . $herecurr);
  1473. }
  1474. # check for adding lines without a newline.
  1475. if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
  1476. WARN("MISSING_EOF_NEWLINE",
  1477. "adding a line without newline at end of file\n" . $herecurr);
  1478. }
  1479. # Blackfin: use hi/lo macros
  1480. if ($realfile =~ m@arch/blackfin/.*\.S$@) {
  1481. if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
  1482. my $herevet = "$here\n" . cat_vet($line) . "\n";
  1483. ERROR("LO_MACRO",
  1484. "use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
  1485. }
  1486. if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
  1487. my $herevet = "$here\n" . cat_vet($line) . "\n";
  1488. ERROR("HI_MACRO",
  1489. "use the HI() macro, not (... >> 16)\n" . $herevet);
  1490. }
  1491. }
  1492. # check we are in a valid source file C or perl if not then ignore this hunk
  1493. next if ($realfile !~ /\.(h|c|pl)$/);
  1494. # at the beginning of a line any tabs must come first and anything
  1495. # more than 8 must use tabs.
  1496. if ($rawline =~ /^\+\s* \t\s*\S/ ||
  1497. $rawline =~ /^\+\s* \s*/) {
  1498. my $herevet = "$here\n" . cat_vet($rawline) . "\n";
  1499. ERROR("CODE_INDENT",
  1500. "code indent should use tabs where possible\n" . $herevet);
  1501. $rpt_cleaners = 1;
  1502. }
  1503. # check for space before tabs.
  1504. if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
  1505. my $herevet = "$here\n" . cat_vet($rawline) . "\n";
  1506. WARN("SPACE_BEFORE_TAB",
  1507. "please, no space before tabs\n" . $herevet);
  1508. }
  1509. # check for spaces at the beginning of a line.
  1510. # Exceptions:
  1511. # 1) within comments
  1512. # 2) indented preprocessor commands
  1513. # 3) hanging labels
  1514. if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
  1515. my $herevet = "$here\n" . cat_vet($rawline) . "\n";
  1516. WARN("LEADING_SPACE",
  1517. "please, no spaces at the start of a line\n" . $herevet);
  1518. }
  1519. # check we are in a valid C source file if not then ignore this hunk
  1520. next if ($realfile !~ /\.(h|c)$/);
  1521. # check for RCS/CVS revision markers
  1522. if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
  1523. WARN("CVS_KEYWORD",
  1524. "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
  1525. }
  1526. # Blackfin: don't use __builtin_bfin_[cs]sync
  1527. if ($line =~ /__builtin_bfin_csync/) {
  1528. my $herevet = "$here\n" . cat_vet($line) . "\n";
  1529. ERROR("CSYNC",
  1530. "use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
  1531. }
  1532. if ($line =~ /__builtin_bfin_ssync/) {
  1533. my $herevet = "$here\n" . cat_vet($line) . "\n";
  1534. ERROR("SSYNC",
  1535. "use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
  1536. }
  1537. # Check for potential 'bare' types
  1538. my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
  1539. $realline_next);
  1540. #print "LINE<$line>\n";
  1541. if ($linenr >= $suppress_statement &&
  1542. $realcnt && $line =~ /.\s*\S/) {
  1543. ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
  1544. ctx_statement_block($linenr, $realcnt, 0);
  1545. $stat =~ s/\n./\n /g;
  1546. $cond =~ s/\n./\n /g;
  1547. #print "linenr<$linenr> <$stat>\n";
  1548. # If this statement has no statement boundaries within
  1549. # it there is no point in retrying a statement scan
  1550. # until we hit end of it.
  1551. my $frag = $stat; $frag =~ s/;+\s*$//;
  1552. if ($frag !~ /(?:{|;)/) {
  1553. #print "skip<$line_nr_next>\n";
  1554. $suppress_statement = $line_nr_next;
  1555. }
  1556. # Find the real next line.
  1557. $realline_next = $line_nr_next;
  1558. if (defined $realline_next &&
  1559. (!defined $lines[$realline_next - 1] ||
  1560. substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
  1561. $realline_next++;
  1562. }
  1563. my $s = $stat;
  1564. $s =~ s/{.*$//s;
  1565. # Ignore goto labels.
  1566. if ($s =~ /$Ident:\*$/s) {
  1567. # Ignore functions being called
  1568. } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
  1569. } elsif ($s =~ /^.\s*else\b/s) {
  1570. # declarations always start with types
  1571. } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
  1572. my $type = $1;
  1573. $type =~ s/\s+/ /g;
  1574. possible($type, "A:" . $s);
  1575. # definitions in global scope can only start with types
  1576. } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
  1577. possible($1, "B:" . $s);
  1578. }
  1579. # any (foo ... *) is a pointer cast, and foo is a type
  1580. while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
  1581. possible($1, "C:" . $s);
  1582. }
  1583. # Check for any sort of function declaration.
  1584. # int foo(something bar, other baz);
  1585. # void (*store_gdt)(x86_descr_ptr *);
  1586. if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
  1587. my ($name_len) = length($1);
  1588. my $ctx = $s;
  1589. substr($ctx, 0, $name_len + 1, '');
  1590. $ctx =~ s/\)[^\)]*$//;
  1591. for my $arg (split(/\s*,\s*/, $ctx)) {
  1592. if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
  1593. possible($1, "D:" . $s);
  1594. }
  1595. }
  1596. }
  1597. }
  1598. #
  1599. # Checks which may be anchored in the context.
  1600. #
  1601. # Check for switch () and associated case and default
  1602. # statements should be at the same indent.
  1603. if ($line=~/\bswitch\s*\(.*\)/) {
  1604. my $err = '';
  1605. my $sep = '';
  1606. my @ctx = ctx_block_outer($linenr, $realcnt);
  1607. shift(@ctx);
  1608. for my $ctx (@ctx) {
  1609. my ($clen, $cindent) = line_stats($ctx);
  1610. if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
  1611. $indent != $cindent) {
  1612. $err .= "$sep$ctx\n";
  1613. $sep = '';
  1614. } else {
  1615. $sep = "[...]\n";
  1616. }
  1617. }
  1618. if ($err ne '') {
  1619. ERROR("SWITCH_CASE_INDENT_LEVEL",
  1620. "switch and case should be at the same indent\n$hereline$err");
  1621. }
  1622. }
  1623. # if/while/etc brace do not go on next line, unless defining a do while loop,
  1624. # or if that brace on the next line is for something else
  1625. if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
  1626. my $pre_ctx = "$1$2";
  1627. my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
  1628. my $ctx_cnt = $realcnt - $#ctx - 1;
  1629. my $ctx = join("\n", @ctx);
  1630. my $ctx_ln = $linenr;
  1631. my $ctx_skip = $realcnt;
  1632. while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
  1633. defined $lines[$ctx_ln - 1] &&
  1634. $lines[$ctx_ln - 1] =~ /^-/)) {
  1635. ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
  1636. $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
  1637. $ctx_ln++;
  1638. }
  1639. #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
  1640. #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
  1641. if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
  1642. ERROR("OPEN_BRACE",
  1643. "that open brace { should be on the previous line\n" .
  1644. "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
  1645. }
  1646. if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
  1647. $ctx =~ /\)\s*\;\s*$/ &&
  1648. defined $lines[$ctx_ln - 1])
  1649. {
  1650. my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
  1651. if ($nindent > $indent) {
  1652. WARN("TRAILING_SEMICOLON",
  1653. "trailing semicolon indicates no statements, indent implies otherwise\n" .
  1654. "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
  1655. }
  1656. }
  1657. }
  1658. # Check relative indent for conditionals and blocks.
  1659. if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
  1660. ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
  1661. ctx_statement_block($linenr, $realcnt, 0)
  1662. if (!defined $stat);
  1663. my ($s, $c) = ($stat, $cond);
  1664. substr($s, 0, length($c), '');
  1665. # Make sure we remove the line prefixes as we have
  1666. # none on the first line, and are going to readd them
  1667. # where necessary.
  1668. $s =~ s/\n./\n/gs;
  1669. # Find out how long the conditional actually is.
  1670. my @newlines = ($c =~ /\n/gs);
  1671. my $cond_lines = 1 + $#newlines;
  1672. # We want to check the first line inside the block
  1673. # starting at the end of the conditional, so remove:
  1674. # 1) any blank line termination
  1675. # 2) any opening brace { on end of the line
  1676. # 3) any do (...) {
  1677. my $continuation = 0;
  1678. my $check = 0;
  1679. $s =~ s/^.*\bdo\b//;
  1680. $s =~ s/^\s*{//;
  1681. if ($s =~ s/^\s*\\//) {
  1682. $continuation = 1;
  1683. }
  1684. if ($s =~ s/^\s*?\n//) {
  1685. $check = 1;
  1686. $cond_lines++;
  1687. }
  1688. # Also ignore a loop construct at the end of a
  1689. # preprocessor statement.
  1690. if (($prevline =~ /^.\s*#\s*define\s/ ||
  1691. $prevline =~ /\\\s*$/) && $continuation == 0) {
  1692. $check = 0;
  1693. }
  1694. my $cond_ptr = -1;
  1695. $continuation = 0;
  1696. while ($cond_ptr != $cond_lines) {
  1697. $cond_ptr = $cond_lines;
  1698. # If we see an #else/#elif then the code
  1699. # is not linear.
  1700. if ($s =~ /^\s*\#\s*(?:else|elif)/) {
  1701. $check = 0;
  1702. }
  1703. # Ignore:
  1704. # 1) blank lines, they should be at 0,
  1705. # 2) preprocessor lines, and
  1706. # 3) labels.
  1707. if ($continuation ||
  1708. $s =~ /^\s*?\n/ ||
  1709. $s =~ /^\s*#\s*?/ ||
  1710. $s =~ /^\s*$Ident\s*:/) {
  1711. $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
  1712. if ($s =~ s/^.*?\n//) {
  1713. $cond_lines++;
  1714. }
  1715. }
  1716. }
  1717. my (undef, $sindent) = line_stats("+" . $s);
  1718. my $stat_real = raw_line($linenr, $cond_lines);
  1719. # Check if either of these lines are modified, else
  1720. # this is not this patch's fault.
  1721. if (!defined($stat_real) ||
  1722. $stat !~ /^\+/ && $stat_real !~ /^\+/) {
  1723. $check = 0;
  1724. }
  1725. if (defined($stat_real) && $cond_lines > 1) {
  1726. $stat_real = "[...]\n$stat_real";
  1727. }
  1728. #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
  1729. if ($check && (($sindent % 8) != 0 ||
  1730. ($sindent <= $indent && $s ne ''))) {
  1731. WARN("SUSPECT_CODE_INDENT",
  1732. "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
  1733. }
  1734. }
  1735. # Track the 'values' across context and added lines.
  1736. my $opline = $line; $opline =~ s/^./ /;
  1737. my ($curr_values, $curr_vars) =
  1738. annotate_values($opline . "\n", $prev_values);
  1739. $curr_values = $prev_values . $curr_values;
  1740. if ($dbg_values) {
  1741. my $outline = $opline; $outline =~ s/\t/ /g;
  1742. print "$linenr > .$outline\n";
  1743. print "$linenr > $curr_values\n";
  1744. print "$linenr > $curr_vars\n";
  1745. }
  1746. $prev_values = substr($curr_values, -1);
  1747. #ignore lines not being added
  1748. if ($line=~/^[^\+]/) {next;}
  1749. # TEST: allow direct testing of the type matcher.
  1750. if ($dbg_type) {
  1751. if ($line =~ /^.\s*$Declare\s*$/) {
  1752. ERROR("TEST_TYPE",
  1753. "TEST: is type\n" . $herecurr);
  1754. } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
  1755. ERROR("TEST_NOT_TYPE",
  1756. "TEST: is not type ($1 is)\n". $herecurr);
  1757. }
  1758. next;
  1759. }
  1760. # TEST: allow direct testing of the attribute matcher.
  1761. if ($dbg_attr) {
  1762. if ($line =~ /^.\s*$Modifier\s*$/) {
  1763. ERROR("TEST_ATTR",
  1764. "TEST: is attr\n" . $herecurr);
  1765. } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
  1766. ERROR("TEST_NOT_ATTR",
  1767. "TEST: is not attr ($1 is)\n". $herecurr);
  1768. }
  1769. next;
  1770. }
  1771. # check for initialisation to aggregates open brace on the next line
  1772. if ($line =~ /^.\s*{/ &&
  1773. $prevline =~ /(?:^|[^=])=\s*$/) {
  1774. ERROR("OPEN_BRACE",
  1775. "that open brace { should be on the previous line\n" . $hereprev);
  1776. }
  1777. #
  1778. # Checks which are anchored on the added line.
  1779. #
  1780. # check for malformed paths in #include statements (uses RAW line)
  1781. if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
  1782. my $path = $1;
  1783. if ($path =~ m{//}) {
  1784. ERROR("MALFORMED_INCLUDE",
  1785. "malformed #include filename\n" .
  1786. $herecurr);
  1787. }
  1788. }
  1789. # no C99 // comments
  1790. if ($line =~ m{//}) {
  1791. ERROR("C99_COMMENTS",
  1792. "do not use C99 // comments\n" . $herecurr);
  1793. }
  1794. # Remove C99 comments.
  1795. $line =~ s@//.*@@;
  1796. $opline =~ s@//.*@@;
  1797. # EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
  1798. # the whole statement.
  1799. #print "APW <$lines[$realline_next - 1]>\n";
  1800. if (defined $realline_next &&
  1801. exists $lines[$realline_next - 1] &&
  1802. !defined $suppress_export{$realline_next} &&
  1803. ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
  1804. $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
  1805. # Handle definitions which produce identifiers with
  1806. # a prefix:
  1807. # XXX(foo);
  1808. # EXPORT_SYMBOL(something_foo);
  1809. my $name = $1;
  1810. if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
  1811. $name =~ /^${Ident}_$2/) {
  1812. #print "FOO C name<$name>\n";
  1813. $suppress_export{$realline_next} = 1;
  1814. } elsif ($stat !~ /(?:
  1815. \n.}\s*$|
  1816. ^.DEFINE_$Ident\(\Q$name\E\)|
  1817. ^.DECLARE_$Ident\(\Q$name\E\)|
  1818. ^.LIST_HEAD\(\Q$name\E\)|
  1819. ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
  1820. \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
  1821. )/x) {
  1822. #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
  1823. $suppress_export{$realline_next} = 2;
  1824. } else {
  1825. $suppress_export{$realline_next} = 1;
  1826. }
  1827. }
  1828. if (!defined $suppress_export{$linenr} &&
  1829. $prevline =~ /^.\s*$/ &&
  1830. ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
  1831. $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
  1832. #print "FOO B <$lines[$linenr - 1]>\n";
  1833. $suppress_export{$linenr} = 2;
  1834. }
  1835. if (defined $suppress_export{$linenr} &&
  1836. $suppress_export{$linenr} == 2) {
  1837. WARN("EXPORT_SYMBOL",
  1838. "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
  1839. }
  1840. # check for global initialisers.
  1841. if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
  1842. ERROR("GLOBAL_INITIALISERS",
  1843. "do not initialise globals to 0 or NULL\n" .
  1844. $herecurr);
  1845. }
  1846. # check for static initialisers.
  1847. if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
  1848. ERROR("INITIALISED_STATIC",
  1849. "do not initialise statics to 0 or NULL\n" .
  1850. $herecurr);
  1851. }
  1852. # check for static const char * arrays.
  1853. if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
  1854. WARN("STATIC_CONST_CHAR_ARRAY",
  1855. "static const char * array should probably be static const char * const\n" .
  1856. $herecurr);
  1857. }
  1858. # check for static char foo[] = "bar" declarations.
  1859. if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
  1860. WARN("STATIC_CONST_CHAR_ARRAY",
  1861. "static char array declaration should probably be static const char\n" .
  1862. $herecurr);
  1863. }
  1864. # check for declarations of struct pci_device_id
  1865. if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) {
  1866. WARN("DEFINE_PCI_DEVICE_TABLE",
  1867. "Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr);
  1868. }
  1869. # check for new typedefs, only function parameters and sparse annotations
  1870. # make sense.
  1871. if ($line =~ /\btypedef\s/ &&
  1872. $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
  1873. $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
  1874. $line !~ /\b$typeTypedefs\b/ &&
  1875. $line !~ /\b__bitwise(?:__|)\b/) {
  1876. WARN("NEW_TYPEDEFS",
  1877. "do not add new typedefs\n" . $herecurr);
  1878. }
  1879. # * goes on variable not on type
  1880. # (char*[ const])
  1881. while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
  1882. #print "AA<$1>\n";
  1883. my ($from, $to) = ($2, $2);
  1884. # Should start with a space.
  1885. $to =~ s/^(\S)/ $1/;
  1886. # Should not end with a space.
  1887. $to =~ s/\s+$//;
  1888. # '*'s should not have spaces between.
  1889. while ($to =~ s/\*\s+\*/\*\*/) {
  1890. }
  1891. #print "from<$from> to<$to>\n";
  1892. if ($from ne $to) {
  1893. ERROR("POINTER_LOCATION",
  1894. "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
  1895. }
  1896. }
  1897. while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
  1898. #print "BB<$1>\n";
  1899. my ($from, $to, $ident) = ($2, $2, $3);
  1900. # Should start with a space.
  1901. $to =~ s/^(\S)/ $1/;
  1902. # Should not end with a space.
  1903. $to =~ s/\s+$//;
  1904. # '*'s should not have spaces between.
  1905. while ($to =~ s/\*\s+\*/\*\*/) {
  1906. }
  1907. # Modifiers should have spaces.
  1908. $to =~ s/(\b$Modifier$)/$1 /;
  1909. #print "from<$from> to<$to> ident<$ident>\n";
  1910. if ($from ne $to && $ident !~ /^$Modifier$/) {
  1911. ERROR("POINTER_LOCATION",
  1912. "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr);
  1913. }
  1914. }
  1915. # # no BUG() or BUG_ON()
  1916. # if ($line =~ /\b(BUG|BUG_ON)\b/) {
  1917. # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
  1918. # print "$herecurr";
  1919. # $clean = 0;
  1920. # }
  1921. if ($line =~ /\bLINUX_VERSION_CODE\b/) {
  1922. WARN("LINUX_VERSION_CODE",
  1923. "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
  1924. }
  1925. # check for uses of printk_ratelimit
  1926. if ($line =~ /\bprintk_ratelimit\s*\(/) {
  1927. WARN("PRINTK_RATELIMITED",
  1928. "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
  1929. }
  1930. # printk should use KERN_* levels. Note that follow on printk's on the
  1931. # same line do not need a level, so we use the current block context
  1932. # to try and find and validate the current printk. In summary the current
  1933. # printk includes all preceding printk's which have no newline on the end.
  1934. # we assume the first bad printk is the one to report.
  1935. if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
  1936. my $ok = 0;
  1937. for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
  1938. #print "CHECK<$lines[$ln - 1]\n";
  1939. # we have a preceding printk if it ends
  1940. # with "\n" ignore it, else it is to blame
  1941. if ($lines[$ln - 1] =~ m{\bprintk\(}) {
  1942. if ($rawlines[$ln - 1] !~ m{\\n"}) {
  1943. $ok = 1;
  1944. }
  1945. last;
  1946. }
  1947. }
  1948. if ($ok == 0) {
  1949. WARN("PRINTK_WITHOUT_KERN_LEVEL",
  1950. "printk() should include KERN_ facility level\n" . $herecurr);
  1951. }
  1952. }
  1953. # function brace can't be on same line, except for #defines of do while,
  1954. # or if closed on same line
  1955. if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
  1956. !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
  1957. ERROR("OPEN_BRACE",
  1958. "open brace '{' following function declarations go on the next line\n" . $herecurr);
  1959. }
  1960. # open braces for enum, union and struct go on the same line.
  1961. if ($line =~ /^.\s*{/ &&
  1962. $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
  1963. ERROR("OPEN_BRACE",
  1964. "open brace '{' following $1 go on the same line\n" . $hereprev);
  1965. }
  1966. # missing space after union, struct or enum definition
  1967. if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
  1968. WARN("SPACING",
  1969. "missing space after $1 definition\n" . $herecurr);
  1970. }
  1971. # check for spacing round square brackets; allowed:
  1972. # 1. with a type on the left -- int [] a;
  1973. # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
  1974. # 3. inside a curly brace -- = { [0...10] = 5 }
  1975. while ($line =~ /(.*?\s)\[/g) {
  1976. my ($where, $prefix) = ($-[1], $1);
  1977. if ($prefix !~ /$Type\s+$/ &&
  1978. ($where != 0 || $prefix !~ /^.\s+$/) &&
  1979. $prefix !~ /{\s+$/) {
  1980. ERROR("BRACKET_SPACE",
  1981. "space prohibited before open square bracket '['\n" . $herecurr);
  1982. }
  1983. }
  1984. # check for spaces between functions and their parentheses.
  1985. while ($line =~ /($Ident)\s+\(/g) {
  1986. my $name = $1;
  1987. my $ctx_before = substr($line, 0, $-[1]);
  1988. my $ctx = "$ctx_before$name";
  1989. # Ignore those directives where spaces _are_ permitted.
  1990. if ($name =~ /^(?:
  1991. if|for|while|switch|return|case|
  1992. volatile|__volatile__|
  1993. __attribute__|format|__extension__|
  1994. asm|__asm__)$/x)
  1995. {
  1996. # cpp #define statements have non-optional spaces, ie
  1997. # if there is a space between the name and the open
  1998. # parenthesis it is simply not a parameter group.
  1999. } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
  2000. # cpp #elif statement condition may start with a (
  2001. } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
  2002. # If this whole things ends with a type its most
  2003. # likely a typedef for a function.
  2004. } elsif ($ctx =~ /$Type$/) {
  2005. } else {
  2006. WARN("SPACING",
  2007. "space prohibited between function name and open parenthesis '('\n" . $herecurr);
  2008. }
  2009. }
  2010. # Check operator spacing.
  2011. if (!($line=~/\#\s*include/)) {
  2012. my $ops = qr{
  2013. <<=|>>=|<=|>=|==|!=|
  2014. \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
  2015. =>|->|<<|>>|<|>|=|!|~|
  2016. &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
  2017. \?|:
  2018. }x;
  2019. my @elements = split(/($ops|;)/, $opline);
  2020. my $off = 0;
  2021. my $blank = copy_spacing($opline);
  2022. for (my $n = 0; $n < $#elements; $n += 2) {
  2023. $off += length($elements[$n]);
  2024. # Pick up the preceding and succeeding characters.
  2025. my $ca = substr($opline, 0, $off);
  2026. my $cc = '';
  2027. if (length($opline) >= ($off + length($elements[$n + 1]))) {
  2028. $cc = substr($opline, $off + length($elements[$n + 1]));
  2029. }
  2030. my $cb = "$ca$;$cc";
  2031. my $a = '';
  2032. $a = 'V' if ($elements[$n] ne '');
  2033. $a = 'W' if ($elements[$n] =~ /\s$/);
  2034. $a = 'C' if ($elements[$n] =~ /$;$/);
  2035. $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
  2036. $a = 'O' if ($elements[$n] eq '');
  2037. $a = 'E' if ($ca =~ /^\s*$/);
  2038. my $op = $elements[$n + 1];
  2039. my $c = '';
  2040. if (defined $elements[$n + 2]) {
  2041. $c = 'V' if ($elements[$n + 2] ne '');
  2042. $c = 'W' if ($elements[$n + 2] =~ /^\s/);
  2043. $c = 'C' if ($elements[$n + 2] =~ /^$;/);
  2044. $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
  2045. $c = 'O' if ($elements[$n + 2] eq '');
  2046. $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
  2047. } else {
  2048. $c = 'E';
  2049. }
  2050. my $ctx = "${a}x${c}";
  2051. my $at = "(ctx:$ctx)";
  2052. my $ptr = substr($blank, 0, $off) . "^";
  2053. my $hereptr = "$hereline$ptr\n";
  2054. # Pull out the value of this operator.
  2055. my $op_type = substr($curr_values, $off + 1, 1);
  2056. # Get the full operator variant.
  2057. my $opv = $op . substr($curr_vars, $off, 1);
  2058. # Ignore operators passed as parameters.
  2059. if ($op_type ne 'V' &&
  2060. $ca =~ /\s$/ && $cc =~ /^\s*,/) {
  2061. # # Ignore comments
  2062. # } elsif ($op =~ /^$;+$/) {
  2063. # ; should have either the end of line or a space or \ after it
  2064. } elsif ($op eq ';') {
  2065. if ($ctx !~ /.x[WEBC]/ &&
  2066. $cc !~ /^\\/ && $cc !~ /^;/) {
  2067. ERROR("SPACING",
  2068. "space required after that '$op' $at\n" . $hereptr);
  2069. }
  2070. # // is a comment
  2071. } elsif ($op eq '//') {
  2072. # No spaces for:
  2073. # ->
  2074. # : when part of a bitfield
  2075. } elsif ($op eq '->' || $opv eq ':B') {
  2076. if ($ctx =~ /Wx.|.xW/) {
  2077. ERROR("SPACING",
  2078. "spaces prohibited around that '$op' $at\n" . $hereptr);
  2079. }
  2080. # , must have a space on the right.
  2081. } elsif ($op eq ',') {
  2082. if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
  2083. ERROR("SPACING",
  2084. "space required after that '$op' $at\n" . $hereptr);
  2085. }
  2086. # '*' as part of a type definition -- reported already.
  2087. } elsif ($opv eq '*_') {
  2088. #warn "'*' is part of type\n";
  2089. # unary operators should have a space before and
  2090. # none after. May be left adjacent to another
  2091. # unary operator, or a cast
  2092. } elsif ($op eq '!' || $op eq '~' ||
  2093. $opv eq '*U' || $opv eq '-U' ||
  2094. $opv eq '&U' || $opv eq '&&U') {
  2095. if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
  2096. ERROR("SPACING",
  2097. "space required before that '$op' $at\n" . $hereptr);
  2098. }
  2099. if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
  2100. # A unary '*' may be const
  2101. } elsif ($ctx =~ /.xW/) {
  2102. ERROR("SPACING",
  2103. "space prohibited after that '$op' $at\n" . $hereptr);
  2104. }
  2105. # unary ++ and unary -- are allowed no space on one side.
  2106. } elsif ($op eq '++' or $op eq '--') {
  2107. if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
  2108. ERROR("SPACING",
  2109. "space required one side of that '$op' $at\n" . $hereptr);
  2110. }
  2111. if ($ctx =~ /Wx[BE]/ ||
  2112. ($ctx =~ /Wx./ && $cc =~ /^;/)) {
  2113. ERROR("SPACING",
  2114. "space prohibited before that '$op' $at\n" . $hereptr);
  2115. }
  2116. if ($ctx =~ /ExW/) {
  2117. ERROR("SPACING",
  2118. "space prohibited after that '$op' $at\n" . $hereptr);
  2119. }
  2120. # << and >> may either have or not have spaces both sides
  2121. } elsif ($op eq '<<' or $op eq '>>' or
  2122. $op eq '&' or $op eq '^' or $op eq '|' or
  2123. $op eq '+' or $op eq '-' or
  2124. $op eq '*' or $op eq '/' or
  2125. $op eq '%')
  2126. {
  2127. if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
  2128. ERROR("SPACING",
  2129. "need consistent spacing around '$op' $at\n" .
  2130. $hereptr);
  2131. }
  2132. # A colon needs no spaces before when it is
  2133. # terminating a case value or a label.
  2134. } elsif ($opv eq ':C' || $opv eq ':L') {
  2135. if ($ctx =~ /Wx./) {
  2136. ERROR("SPACING",
  2137. "space prohibited before that '$op' $at\n" . $hereptr);
  2138. }
  2139. # All the others need spaces both sides.
  2140. } elsif ($ctx !~ /[EWC]x[CWE]/) {
  2141. my $ok = 0;
  2142. # Ignore email addresses <foo@bar>
  2143. if (($op eq '<' &&
  2144. $cc =~ /^\S+\@\S+>/) ||
  2145. ($op eq '>' &&
  2146. $ca =~ /<\S+\@\S+$/))
  2147. {
  2148. $ok = 1;
  2149. }
  2150. # Ignore ?:
  2151. if (($opv eq ':O' && $ca =~ /\?$/) ||
  2152. ($op eq '?' && $cc =~ /^:/)) {
  2153. $ok = 1;
  2154. }
  2155. if ($ok == 0) {
  2156. ERROR("SPACING",
  2157. "spaces required around that '$op' $at\n" . $hereptr);
  2158. }
  2159. }
  2160. $off += length($elements[$n + 1]);
  2161. }
  2162. }
  2163. # check for multiple assignments
  2164. if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
  2165. CHK("MULTIPLE_ASSIGNMENTS",
  2166. "multiple assignments should be avoided\n" . $herecurr);
  2167. }
  2168. ## # check for multiple declarations, allowing for a function declaration
  2169. ## # continuation.
  2170. ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
  2171. ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
  2172. ##
  2173. ## # Remove any bracketed sections to ensure we do not
  2174. ## # falsly report the parameters of functions.
  2175. ## my $ln = $line;
  2176. ## while ($ln =~ s/\([^\(\)]*\)//g) {
  2177. ## }
  2178. ## if ($ln =~ /,/) {
  2179. ## WARN("MULTIPLE_DECLARATION",
  2180. ## "declaring multiple variables together should be avoided\n" . $herecurr);
  2181. ## }
  2182. ## }
  2183. #need space before brace following if, while, etc
  2184. if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
  2185. $line =~ /do{/) {
  2186. ERROR("SPACING",
  2187. "space required before the open brace '{'\n" . $herecurr);
  2188. }
  2189. # closing brace should have a space following it when it has anything
  2190. # on the line
  2191. if ($line =~ /}(?!(?:,|;|\)))\S/) {
  2192. ERROR("SPACING",
  2193. "space required after that close brace '}'\n" . $herecurr);
  2194. }
  2195. # check spacing on square brackets
  2196. if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
  2197. ERROR("SPACING",
  2198. "space prohibited after that open square bracket '['\n" . $herecurr);
  2199. }
  2200. if ($line =~ /\s\]/) {
  2201. ERROR("SPACING",
  2202. "space prohibited before that close square bracket ']'\n" . $herecurr);
  2203. }
  2204. # check spacing on parentheses
  2205. if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
  2206. $line !~ /for\s*\(\s+;/) {
  2207. ERROR("SPACING",
  2208. "space prohibited after that open parenthesis '('\n" . $herecurr);
  2209. }
  2210. if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
  2211. $line !~ /for\s*\(.*;\s+\)/ &&
  2212. $line !~ /:\s+\)/) {
  2213. ERROR("SPACING",
  2214. "space prohibited before that close parenthesis ')'\n" . $herecurr);
  2215. }
  2216. #goto labels aren't indented, allow a single space however
  2217. if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
  2218. !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
  2219. WARN("INDENTED_LABEL",
  2220. "labels should not be indented\n" . $herecurr);
  2221. }
  2222. # Return is not a function.
  2223. if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) {
  2224. my $spacing = $1;
  2225. my $value = $2;
  2226. # Flatten any parentheses
  2227. $value =~ s/\(/ \(/g;
  2228. $value =~ s/\)/\) /g;
  2229. while ($value =~ s/\[[^\[\]]*\]/1/ ||
  2230. $value !~ /(?:$Ident|-?$Constant)\s*
  2231. $Compare\s*
  2232. (?:$Ident|-?$Constant)/x &&
  2233. $value =~ s/\([^\(\)]*\)/1/) {
  2234. }
  2235. #print "value<$value>\n";
  2236. if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
  2237. ERROR("RETURN_PARENTHESES",
  2238. "return is not a function, parentheses are not required\n" . $herecurr);
  2239. } elsif ($spacing !~ /\s+/) {
  2240. ERROR("SPACING",
  2241. "space required before the open parenthesis '('\n" . $herecurr);
  2242. }
  2243. }
  2244. # Return of what appears to be an errno should normally be -'ve
  2245. if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
  2246. my $name = $1;
  2247. if ($name ne 'EOF' && $name ne 'ERROR') {
  2248. WARN("USE_NEGATIVE_ERRNO",
  2249. "return of an errno should typically be -ve (return -$1)\n" . $herecurr);
  2250. }
  2251. }
  2252. # Need a space before open parenthesis after if, while etc
  2253. if ($line=~/\b(if|while|for|switch)\(/) {
  2254. ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr);
  2255. }
  2256. # Check for illegal assignment in if conditional -- and check for trailing
  2257. # statements after the conditional.
  2258. if ($line =~ /do\s*(?!{)/) {
  2259. ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
  2260. ctx_statement_block($linenr, $realcnt, 0)
  2261. if (!defined $stat);
  2262. my ($stat_next) = ctx_statement_block($line_nr_next,
  2263. $remain_next, $off_next);
  2264. $stat_next =~ s/\n./\n /g;
  2265. ##print "stat<$stat> stat_next<$stat_next>\n";
  2266. if ($stat_next =~ /^\s*while\b/) {
  2267. # If the statement carries leading newlines,
  2268. # then count those as offsets.
  2269. my ($whitespace) =
  2270. ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
  2271. my $offset =
  2272. statement_rawlines($whitespace) - 1;
  2273. $suppress_whiletrailers{$line_nr_next +
  2274. $offset} = 1;
  2275. }
  2276. }
  2277. if (!defined $suppress_whiletrailers{$linenr} &&
  2278. $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
  2279. my ($s, $c) = ($stat, $cond);
  2280. if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
  2281. ERROR("ASSIGN_IN_IF",
  2282. "do not use assignment in if condition\n" . $herecurr);
  2283. }
  2284. # Find out what is on the end of the line after the
  2285. # conditional.
  2286. substr($s, 0, length($c), '');
  2287. $s =~ s/\n.*//g;
  2288. $s =~ s/$;//g; # Remove any comments
  2289. if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
  2290. $c !~ /}\s*while\s*/)
  2291. {
  2292. # Find out how long the conditional actually is.
  2293. my @newlines = ($c =~ /\n/gs);
  2294. my $cond_lines = 1 + $#newlines;
  2295. my $stat_real = '';
  2296. $stat_real = raw_line($linenr, $cond_lines)
  2297. . "\n" if ($cond_lines);
  2298. if (defined($stat_real) && $cond_lines > 1) {
  2299. $stat_real = "[...]\n$stat_real";
  2300. }
  2301. ERROR("TRAILING_STATEMENTS",
  2302. "trailing statements should be on next line\n" . $herecurr . $stat_real);
  2303. }
  2304. }
  2305. # Check for bitwise tests written as boolean
  2306. if ($line =~ /
  2307. (?:
  2308. (?:\[|\(|\&\&|\|\|)
  2309. \s*0[xX][0-9]+\s*
  2310. (?:\&\&|\|\|)
  2311. |
  2312. (?:\&\&|\|\|)
  2313. \s*0[xX][0-9]+\s*
  2314. (?:\&\&|\|\||\)|\])
  2315. )/x)
  2316. {
  2317. WARN("HEXADECIMAL_BOOLEAN_TEST",
  2318. "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
  2319. }
  2320. # if and else should not have general statements after it
  2321. if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
  2322. my $s = $1;
  2323. $s =~ s/$;//g; # Remove any comments
  2324. if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
  2325. ERROR("TRAILING_STATEMENTS",
  2326. "trailing statements should be on next line\n" . $herecurr);
  2327. }
  2328. }
  2329. # if should not continue a brace
  2330. if ($line =~ /}\s*if\b/) {
  2331. ERROR("TRAILING_STATEMENTS",
  2332. "trailing statements should be on next line\n" .
  2333. $herecurr);
  2334. }
  2335. # case and default should not have general statements after them
  2336. if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
  2337. $line !~ /\G(?:
  2338. (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
  2339. \s*return\s+
  2340. )/xg)
  2341. {
  2342. ERROR("TRAILING_STATEMENTS",
  2343. "trailing statements should be on next line\n" . $herecurr);
  2344. }
  2345. # Check for }<nl>else {, these must be at the same
  2346. # indent level to be relevant to each other.
  2347. if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
  2348. $previndent == $indent) {
  2349. ERROR("ELSE_AFTER_BRACE",
  2350. "else should follow close brace '}'\n" . $hereprev);
  2351. }
  2352. if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
  2353. $previndent == $indent) {
  2354. my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
  2355. # Find out what is on the end of the line after the
  2356. # conditional.
  2357. substr($s, 0, length($c), '');
  2358. $s =~ s/\n.*//g;
  2359. if ($s =~ /^\s*;/) {
  2360. ERROR("WHILE_AFTER_BRACE",
  2361. "while should follow close brace '}'\n" . $hereprev);
  2362. }
  2363. }
  2364. #studly caps, commented out until figure out how to distinguish between use of existing and adding new
  2365. # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
  2366. # print "No studly caps, use _\n";
  2367. # print "$herecurr";
  2368. # $clean = 0;
  2369. # }
  2370. #no spaces allowed after \ in define
  2371. if ($line=~/\#\s*define.*\\\s$/) {
  2372. WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
  2373. "Whitepspace after \\ makes next lines useless\n" . $herecurr);
  2374. }
  2375. #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
  2376. if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
  2377. my $file = "$1.h";
  2378. my $checkfile = "include/linux/$file";
  2379. if (-f "$root/$checkfile" &&
  2380. $realfile ne $checkfile &&
  2381. $1 !~ /$allowed_asm_includes/)
  2382. {
  2383. if ($realfile =~ m{^arch/}) {
  2384. CHK("ARCH_INCLUDE_LINUX",
  2385. "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
  2386. } else {
  2387. WARN("INCLUDE_LINUX",
  2388. "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
  2389. }
  2390. }
  2391. }
  2392. # multi-statement macros should be enclosed in a do while loop, grab the
  2393. # first statement and ensure its the whole macro if its not enclosed
  2394. # in a known good container
  2395. if ($realfile !~ m@/vmlinux.lds.h$@ &&
  2396. $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
  2397. my $ln = $linenr;
  2398. my $cnt = $realcnt;
  2399. my ($off, $dstat, $dcond, $rest);
  2400. my $ctx = '';
  2401. ($dstat, $dcond, $ln, $cnt, $off) =
  2402. ctx_statement_block($linenr, $realcnt, 0);
  2403. $ctx = $dstat;
  2404. #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
  2405. #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
  2406. $dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//;
  2407. $dstat =~ s/$;//g;
  2408. $dstat =~ s/\\\n.//g;
  2409. $dstat =~ s/^\s*//s;
  2410. $dstat =~ s/\s*$//s;
  2411. # Flatten any parentheses and braces
  2412. while ($dstat =~ s/\([^\(\)]*\)/1/ ||
  2413. $dstat =~ s/\{[^\{\}]*\}/1/ ||
  2414. $dstat =~ s/\[[^\[\]]*\]/1/)
  2415. {
  2416. }
  2417. my $exceptions = qr{
  2418. $Declare|
  2419. module_param_named|
  2420. MODULE_PARAM_DESC|
  2421. DECLARE_PER_CPU|
  2422. DEFINE_PER_CPU|
  2423. __typeof__\(|
  2424. union|
  2425. struct|
  2426. \.$Ident\s*=\s*|
  2427. ^\"|\"$
  2428. }x;
  2429. #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
  2430. if ($dstat ne '' &&
  2431. $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
  2432. $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
  2433. $dstat !~ /^(?:$Ident|-?$Constant)$/ && # 10 // foo()
  2434. $dstat !~ /$exceptions/ &&
  2435. $dstat !~ /^\.$Ident\s*=/ && # .foo =
  2436. $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
  2437. $dstat !~ /^for\s*$Constant$/ && # for (...)
  2438. $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
  2439. $dstat !~ /^do\s*{/ && # do {...
  2440. $dstat !~ /^\({/) # ({...
  2441. {
  2442. $ctx =~ s/\n*$//;
  2443. my $herectx = $here . "\n";
  2444. my $cnt = statement_rawlines($ctx);
  2445. for (my $n = 0; $n < $cnt; $n++) {
  2446. $herectx .= raw_line($linenr, $n) . "\n";
  2447. }
  2448. if ($dstat =~ /;/) {
  2449. ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
  2450. "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
  2451. } else {
  2452. ERROR("COMPLEX_MACRO",
  2453. "Macros with complex values should be enclosed in parenthesis\n" . "$herectx");
  2454. }
  2455. }
  2456. }
  2457. # make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
  2458. # all assignments may have only one of the following with an assignment:
  2459. # .
  2460. # ALIGN(...)
  2461. # VMLINUX_SYMBOL(...)
  2462. if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
  2463. WARN("MISSING_VMLINUX_SYMBOL",
  2464. "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
  2465. }
  2466. # check for redundant bracing round if etc
  2467. if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
  2468. my ($level, $endln, @chunks) =
  2469. ctx_statement_full($linenr, $realcnt, 1);
  2470. #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
  2471. #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
  2472. if ($#chunks > 0 && $level == 0) {
  2473. my $allowed = 0;
  2474. my $seen = 0;
  2475. my $herectx = $here . "\n";
  2476. my $ln = $linenr - 1;
  2477. for my $chunk (@chunks) {
  2478. my ($cond, $block) = @{$chunk};
  2479. # If the condition carries leading newlines, then count those as offsets.
  2480. my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
  2481. my $offset = statement_rawlines($whitespace) - 1;
  2482. #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
  2483. # We have looked at and allowed this specific line.
  2484. $suppress_ifbraces{$ln + $offset} = 1;
  2485. $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
  2486. $ln += statement_rawlines($block) - 1;
  2487. substr($block, 0, length($cond), '');
  2488. $seen++ if ($block =~ /^\s*{/);
  2489. #print "cond<$cond> block<$block> allowed<$allowed>\n";
  2490. if (statement_lines($cond) > 1) {
  2491. #print "APW: ALLOWED: cond<$cond>\n";
  2492. $allowed = 1;
  2493. }
  2494. if ($block =~/\b(?:if|for|while)\b/) {
  2495. #print "APW: ALLOWED: block<$block>\n";
  2496. $allowed = 1;
  2497. }
  2498. if (statement_block_size($block) > 1) {
  2499. #print "APW: ALLOWED: lines block<$block>\n";
  2500. $allowed = 1;
  2501. }
  2502. }
  2503. if ($seen && !$allowed) {
  2504. WARN("BRACES",
  2505. "braces {} are not necessary for any arm of this statement\n" . $herectx);
  2506. }
  2507. }
  2508. }
  2509. if (!defined $suppress_ifbraces{$linenr - 1} &&
  2510. $line =~ /\b(if|while|for|else)\b/) {
  2511. my $allowed = 0;
  2512. # Check the pre-context.
  2513. if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
  2514. #print "APW: ALLOWED: pre<$1>\n";
  2515. $allowed = 1;
  2516. }
  2517. my ($level, $endln, @chunks) =
  2518. ctx_statement_full($linenr, $realcnt, $-[0]);
  2519. # Check the condition.
  2520. my ($cond, $block) = @{$chunks[0]};
  2521. #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
  2522. if (defined $cond) {
  2523. substr($block, 0, length($cond), '');
  2524. }
  2525. if (statement_lines($cond) > 1) {
  2526. #print "APW: ALLOWED: cond<$cond>\n";
  2527. $allowed = 1;
  2528. }
  2529. if ($block =~/\b(?:if|for|while)\b/) {
  2530. #print "APW: ALLOWED: block<$block>\n";
  2531. $allowed = 1;
  2532. }
  2533. if (statement_block_size($block) > 1) {
  2534. #print "APW: ALLOWED: lines block<$block>\n";
  2535. $allowed = 1;
  2536. }
  2537. # Check the post-context.
  2538. if (defined $chunks[1]) {
  2539. my ($cond, $block) = @{$chunks[1]};
  2540. if (defined $cond) {
  2541. substr($block, 0, length($cond), '');
  2542. }
  2543. if ($block =~ /^\s*\{/) {
  2544. #print "APW: ALLOWED: chunk-1 block<$block>\n";
  2545. $allowed = 1;
  2546. }
  2547. }
  2548. if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
  2549. my $herectx = $here . "\n";
  2550. my $cnt = statement_rawlines($block);
  2551. for (my $n = 0; $n < $cnt; $n++) {
  2552. $herectx .= raw_line($linenr, $n) . "\n";
  2553. }
  2554. WARN("BRACES",
  2555. "braces {} are not necessary for single statement blocks\n" . $herectx);
  2556. }
  2557. }
  2558. # don't include deprecated include files (uses RAW line)
  2559. for my $inc (@dep_includes) {
  2560. if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) {
  2561. ERROR("DEPRECATED_INCLUDE",
  2562. "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
  2563. }
  2564. }
  2565. # don't use deprecated functions
  2566. for my $func (@dep_functions) {
  2567. if ($line =~ /\b$func\b/) {
  2568. ERROR("DEPRECATED_FUNCTION",
  2569. "Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
  2570. }
  2571. }
  2572. # no volatiles please
  2573. my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
  2574. if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
  2575. WARN("VOLATILE",
  2576. "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
  2577. }
  2578. # warn about #if 0
  2579. if ($line =~ /^.\s*\#\s*if\s+0\b/) {
  2580. CHK("REDUNDANT_CODE",
  2581. "if this code is redundant consider removing it\n" .
  2582. $herecurr);
  2583. }
  2584. # check for needless kfree() checks
  2585. if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
  2586. my $expr = $1;
  2587. if ($line =~ /\bkfree\(\Q$expr\E\);/) {
  2588. WARN("NEEDLESS_KFREE",
  2589. "kfree(NULL) is safe this check is probably not required\n" . $hereprev);
  2590. }
  2591. }
  2592. # check for needless usb_free_urb() checks
  2593. if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
  2594. my $expr = $1;
  2595. if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) {
  2596. WARN("NEEDLESS_USB_FREE_URB",
  2597. "usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev);
  2598. }
  2599. }
  2600. # prefer usleep_range over udelay
  2601. if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
  2602. # ignore udelay's < 10, however
  2603. if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
  2604. CHK("USLEEP_RANGE",
  2605. "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
  2606. }
  2607. }
  2608. # warn about unexpectedly long msleep's
  2609. if ($line =~ /\bmsleep\s*\((\d+)\);/) {
  2610. if ($1 < 20) {
  2611. WARN("MSLEEP",
  2612. "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
  2613. }
  2614. }
  2615. # warn about #ifdefs in C files
  2616. # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
  2617. # print "#ifdef in C files should be avoided\n";
  2618. # print "$herecurr";
  2619. # $clean = 0;
  2620. # }
  2621. # warn about spacing in #ifdefs
  2622. if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
  2623. ERROR("SPACING",
  2624. "exactly one space required after that #$1\n" . $herecurr);
  2625. }
  2626. # check for spinlock_t definitions without a comment.
  2627. if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
  2628. $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
  2629. my $which = $1;
  2630. if (!ctx_has_comment($first_line, $linenr)) {
  2631. CHK("UNCOMMENTED_DEFINITION",
  2632. "$1 definition without comment\n" . $herecurr);
  2633. }
  2634. }
  2635. # check for memory barriers without a comment.
  2636. if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
  2637. if (!ctx_has_comment($first_line, $linenr)) {
  2638. CHK("MEMORY_BARRIER",
  2639. "memory barrier without comment\n" . $herecurr);
  2640. }
  2641. }
  2642. # check of hardware specific defines
  2643. if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
  2644. CHK("ARCH_DEFINES",
  2645. "architecture specific defines should be avoided\n" . $herecurr);
  2646. }
  2647. # Check that the storage class is at the beginning of a declaration
  2648. if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
  2649. WARN("STORAGE_CLASS",
  2650. "storage class should be at the beginning of the declaration\n" . $herecurr)
  2651. }
  2652. # check the location of the inline attribute, that it is between
  2653. # storage class and type.
  2654. if ($line =~ /\b$Type\s+$Inline\b/ ||
  2655. $line =~ /\b$Inline\s+$Storage\b/) {
  2656. ERROR("INLINE_LOCATION",
  2657. "inline keyword should sit between storage class and type\n" . $herecurr);
  2658. }
  2659. # Check for __inline__ and __inline, prefer inline
  2660. if ($line =~ /\b(__inline__|__inline)\b/) {
  2661. WARN("INLINE",
  2662. "plain inline is preferred over $1\n" . $herecurr);
  2663. }
  2664. # Check for __attribute__ packed, prefer __packed
  2665. if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
  2666. WARN("PREFER_PACKED",
  2667. "__packed is preferred over __attribute__((packed))\n" . $herecurr);
  2668. }
  2669. # Check for __attribute__ aligned, prefer __aligned
  2670. if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
  2671. WARN("PREFER_ALIGNED",
  2672. "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
  2673. }
  2674. # Check for __attribute__ format(printf, prefer __printf
  2675. if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
  2676. WARN("PREFER_PRINTF",
  2677. "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr);
  2678. }
  2679. # check for sizeof(&)
  2680. if ($line =~ /\bsizeof\s*\(\s*\&/) {
  2681. WARN("SIZEOF_ADDRESS",
  2682. "sizeof(& should be avoided\n" . $herecurr);
  2683. }
  2684. # check for line continuations in quoted strings with odd counts of "
  2685. if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
  2686. WARN("LINE_CONTINUATIONS",
  2687. "Avoid line continuations in quoted strings\n" . $herecurr);
  2688. }
  2689. # Check for misused memsets
  2690. if (defined $stat &&
  2691. $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
  2692. my $ms_addr = $2;
  2693. my $ms_val = $8;
  2694. my $ms_size = $14;
  2695. if ($ms_size =~ /^(0x|)0$/i) {
  2696. ERROR("MEMSET",
  2697. "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
  2698. } elsif ($ms_size =~ /^(0x|)1$/i) {
  2699. WARN("MEMSET",
  2700. "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
  2701. }
  2702. }
  2703. # typecasts on min/max could be min_t/max_t
  2704. if (defined $stat &&
  2705. $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
  2706. if (defined $2 || defined $8) {
  2707. my $call = $1;
  2708. my $cast1 = deparenthesize($2);
  2709. my $arg1 = $3;
  2710. my $cast2 = deparenthesize($8);
  2711. my $arg2 = $9;
  2712. my $cast;
  2713. if ($cast1 ne "" && $cast2 ne "") {
  2714. $cast = "$cast1 or $cast2";
  2715. } elsif ($cast1 ne "") {
  2716. $cast = $cast1;
  2717. } else {
  2718. $cast = $cast2;
  2719. }
  2720. WARN("MINMAX",
  2721. "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
  2722. }
  2723. }
  2724. # check for new externs in .c files.
  2725. if ($realfile =~ /\.c$/ && defined $stat &&
  2726. $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
  2727. {
  2728. my $function_name = $1;
  2729. my $paren_space = $2;
  2730. my $s = $stat;
  2731. if (defined $cond) {
  2732. substr($s, 0, length($cond), '');
  2733. }
  2734. if ($s =~ /^\s*;/ &&
  2735. $function_name ne 'uninitialized_var')
  2736. {
  2737. WARN("AVOID_EXTERNS",
  2738. "externs should be avoided in .c files\n" . $herecurr);
  2739. }
  2740. if ($paren_space =~ /\n/) {
  2741. WARN("FUNCTION_ARGUMENTS",
  2742. "arguments for function declarations should follow identifier\n" . $herecurr);
  2743. }
  2744. } elsif ($realfile =~ /\.c$/ && defined $stat &&
  2745. $stat =~ /^.\s*extern\s+/)
  2746. {
  2747. WARN("AVOID_EXTERNS",
  2748. "externs should be avoided in .c files\n" . $herecurr);
  2749. }
  2750. # checks for new __setup's
  2751. if ($rawline =~ /\b__setup\("([^"]*)"/) {
  2752. my $name = $1;
  2753. if (!grep(/$name/, @setup_docs)) {
  2754. CHK("UNDOCUMENTED_SETUP",
  2755. "__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
  2756. }
  2757. }
  2758. # check for pointless casting of kmalloc return
  2759. if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
  2760. WARN("UNNECESSARY_CASTS",
  2761. "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
  2762. }
  2763. # check for multiple semicolons
  2764. if ($line =~ /;\s*;\s*$/) {
  2765. WARN("ONE_SEMICOLON",
  2766. "Statements terminations use 1 semicolon\n" . $herecurr);
  2767. }
  2768. # check for gcc specific __FUNCTION__
  2769. if ($line =~ /__FUNCTION__/) {
  2770. WARN("USE_FUNC",
  2771. "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
  2772. }
  2773. # check for semaphores initialized locked
  2774. if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
  2775. WARN("CONSIDER_COMPLETION",
  2776. "consider using a completion\n" . $herecurr);
  2777. }
  2778. # recommend kstrto* over simple_strto* and strict_strto*
  2779. if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
  2780. WARN("CONSIDER_KSTRTO",
  2781. "$1 is obsolete, use k$3 instead\n" . $herecurr);
  2782. }
  2783. # check for __initcall(), use device_initcall() explicitly please
  2784. if ($line =~ /^.\s*__initcall\s*\(/) {
  2785. WARN("USE_DEVICE_INITCALL",
  2786. "please use device_initcall() instead of __initcall()\n" . $herecurr);
  2787. }
  2788. # check for various ops structs, ensure they are const.
  2789. my $struct_ops = qr{acpi_dock_ops|
  2790. address_space_operations|
  2791. backlight_ops|
  2792. block_device_operations|
  2793. dentry_operations|
  2794. dev_pm_ops|
  2795. dma_map_ops|
  2796. extent_io_ops|
  2797. file_lock_operations|
  2798. file_operations|
  2799. hv_ops|
  2800. ide_dma_ops|
  2801. intel_dvo_dev_ops|
  2802. item_operations|
  2803. iwl_ops|
  2804. kgdb_arch|
  2805. kgdb_io|
  2806. kset_uevent_ops|
  2807. lock_manager_operations|
  2808. microcode_ops|
  2809. mtrr_ops|
  2810. neigh_ops|
  2811. nlmsvc_binding|
  2812. pci_raw_ops|
  2813. pipe_buf_operations|
  2814. platform_hibernation_ops|
  2815. platform_suspend_ops|
  2816. proto_ops|
  2817. rpc_pipe_ops|
  2818. seq_operations|
  2819. snd_ac97_build_ops|
  2820. soc_pcmcia_socket_ops|
  2821. stacktrace_ops|
  2822. sysfs_ops|
  2823. tty_operations|
  2824. usb_mon_operations|
  2825. wd_ops}x;
  2826. if ($line !~ /\bconst\b/ &&
  2827. $line =~ /\bstruct\s+($struct_ops)\b/) {
  2828. WARN("CONST_STRUCT",
  2829. "struct $1 should normally be const\n" .
  2830. $herecurr);
  2831. }
  2832. # use of NR_CPUS is usually wrong
  2833. # ignore definitions of NR_CPUS and usage to define arrays as likely right
  2834. if ($line =~ /\bNR_CPUS\b/ &&
  2835. $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
  2836. $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
  2837. $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
  2838. $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
  2839. $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
  2840. {
  2841. WARN("NR_CPUS",
  2842. "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
  2843. }
  2844. # check for %L{u,d,i} in strings
  2845. my $string;
  2846. while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
  2847. $string = substr($rawline, $-[1], $+[1] - $-[1]);
  2848. $string =~ s/%%/__/g;
  2849. if ($string =~ /(?<!%)%L[udi]/) {
  2850. WARN("PRINTF_L",
  2851. "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
  2852. last;
  2853. }
  2854. }
  2855. # whine mightly about in_atomic
  2856. if ($line =~ /\bin_atomic\s*\(/) {
  2857. if ($realfile =~ m@^drivers/@) {
  2858. ERROR("IN_ATOMIC",
  2859. "do not use in_atomic in drivers\n" . $herecurr);
  2860. } elsif ($realfile !~ m@^kernel/@) {
  2861. WARN("IN_ATOMIC",
  2862. "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
  2863. }
  2864. }
  2865. # check for lockdep_set_novalidate_class
  2866. if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
  2867. $line =~ /__lockdep_no_validate__\s*\)/ ) {
  2868. if ($realfile !~ m@^kernel/lockdep@ &&
  2869. $realfile !~ m@^include/linux/lockdep@ &&
  2870. $realfile !~ m@^drivers/base/core@) {
  2871. ERROR("LOCKDEP",
  2872. "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
  2873. }
  2874. }
  2875. if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
  2876. $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
  2877. WARN("EXPORTED_WORLD_WRITABLE",
  2878. "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
  2879. }
  2880. }
  2881. # If we have no input at all, then there is nothing to report on
  2882. # so just keep quiet.
  2883. if ($#rawlines == -1) {
  2884. exit(0);
  2885. }
  2886. # In mailback mode only produce a report in the negative, for
  2887. # things that appear to be patches.
  2888. if ($mailback && ($clean == 1 || !$is_patch)) {
  2889. exit(0);
  2890. }
  2891. # This is not a patch, and we are are in 'no-patch' mode so
  2892. # just keep quiet.
  2893. if (!$chk_patch && !$is_patch) {
  2894. exit(0);
  2895. }
  2896. if (!$is_patch) {
  2897. ERROR("NOT_UNIFIED_DIFF",
  2898. "Does not appear to be a unified-diff format patch\n");
  2899. }
  2900. if ($is_patch && $chk_signoff && $signoff == 0) {
  2901. ERROR("MISSING_SIGN_OFF",
  2902. "Missing Signed-off-by: line(s)\n");
  2903. }
  2904. print report_dump();
  2905. if ($summary && !($clean == 1 && $quiet == 1)) {
  2906. print "$filename " if ($summary_file);
  2907. print "total: $cnt_error errors, $cnt_warn warnings, " .
  2908. (($check)? "$cnt_chk checks, " : "") .
  2909. "$cnt_lines lines checked\n";
  2910. print "\n" if ($quiet == 0);
  2911. }
  2912. if ($quiet == 0) {
  2913. # If there were whitespace errors which cleanpatch can fix
  2914. # then suggest that.
  2915. if ($rpt_cleaners) {
  2916. print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
  2917. print " scripts/cleanfile\n\n";
  2918. $rpt_cleaners = 0;
  2919. }
  2920. }
  2921. if (keys %ignore_type) {
  2922. print "NOTE: Ignored message types:";
  2923. foreach my $ignore (sort keys %ignore_type) {
  2924. print " $ignore";
  2925. }
  2926. print "\n";
  2927. print "\n" if ($quiet == 0);
  2928. }
  2929. if ($clean == 1 && $quiet == 0) {
  2930. print "$vname has no obvious style problems and is ready for submission.\n"
  2931. }
  2932. if ($clean == 0 && $quiet == 0) {
  2933. print << "EOM";
  2934. $vname has style problems, please review.
  2935. If any of these errors are false positives, please report
  2936. them to the maintainer, see CHECKPATCH in MAINTAINERS.
  2937. EOM
  2938. }
  2939. return $clean;
  2940. }