diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 42 | ||||
| -rw-r--r-- | scripts/mod/modpost.c | 54 |
2 files changed, 77 insertions, 19 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index bd88f11b0953..2039acdf5122 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -195,7 +195,7 @@ our $typeTypedefs = qr{(?x: | |||
| 195 | our $logFunctions = qr{(?x: | 195 | our $logFunctions = qr{(?x: |
| 196 | printk| | 196 | printk| |
| 197 | pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| | 197 | pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| |
| 198 | dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| | 198 | (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| |
| 199 | WARN| | 199 | WARN| |
| 200 | panic | 200 | panic |
| 201 | )}; | 201 | )}; |
| @@ -224,6 +224,12 @@ our @modifierList = ( | |||
| 224 | qr{fastcall}, | 224 | qr{fastcall}, |
| 225 | ); | 225 | ); |
| 226 | 226 | ||
| 227 | our $allowed_asm_includes = qr{(?x: | ||
| 228 | irq| | ||
| 229 | memory | ||
| 230 | )}; | ||
| 231 | # memory.h: ARM has a custom one | ||
| 232 | |||
| 227 | sub build_types { | 233 | sub build_types { |
| 228 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; | 234 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; |
| 229 | my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; | 235 | my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; |
| @@ -552,6 +558,9 @@ sub ctx_statement_block { | |||
| 552 | $type = ($level != 0)? '{' : ''; | 558 | $type = ($level != 0)? '{' : ''; |
| 553 | 559 | ||
| 554 | if ($level == 0) { | 560 | if ($level == 0) { |
| 561 | if (substr($blk, $off + 1, 1) eq ';') { | ||
| 562 | $off++; | ||
| 563 | } | ||
| 555 | last; | 564 | last; |
| 556 | } | 565 | } |
| 557 | } | 566 | } |
| @@ -1403,7 +1412,8 @@ sub process { | |||
| 1403 | #80 column limit | 1412 | #80 column limit |
| 1404 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && | 1413 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && |
| 1405 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && | 1414 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && |
| 1406 | $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && | 1415 | !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ || |
| 1416 | $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && | ||
| 1407 | $length > 80) | 1417 | $length > 80) |
| 1408 | { | 1418 | { |
| 1409 | WARN("line over 80 characters\n" . $herecurr); | 1419 | WARN("line over 80 characters\n" . $herecurr); |
| @@ -1448,6 +1458,13 @@ sub process { | |||
| 1448 | WARN("please, no space before tabs\n" . $herevet); | 1458 | WARN("please, no space before tabs\n" . $herevet); |
| 1449 | } | 1459 | } |
| 1450 | 1460 | ||
| 1461 | # check for spaces at the beginning of a line. | ||
| 1462 | if ($rawline =~ /^\+ / && $rawline !~ /\+ +\*/) { | ||
| 1463 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | ||
| 1464 | WARN("please, no space for starting a line, \ | ||
| 1465 | excluding comments\n" . $herevet); | ||
| 1466 | } | ||
| 1467 | |||
| 1451 | # check we are in a valid C source file if not then ignore this hunk | 1468 | # check we are in a valid C source file if not then ignore this hunk |
| 1452 | next if ($realfile !~ /\.(h|c)$/); | 1469 | next if ($realfile !~ /\.(h|c)$/); |
| 1453 | 1470 | ||
| @@ -1778,9 +1795,9 @@ sub process { | |||
| 1778 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); | 1795 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); |
| 1779 | } | 1796 | } |
| 1780 | 1797 | ||
| 1781 | # check for external initialisers. | 1798 | # check for global initialisers. |
| 1782 | if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { | 1799 | if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { |
| 1783 | ERROR("do not initialise externals to 0 or NULL\n" . | 1800 | ERROR("do not initialise globals to 0 or NULL\n" . |
| 1784 | $herecurr); | 1801 | $herecurr); |
| 1785 | } | 1802 | } |
| 1786 | # check for static initialisers. | 1803 | # check for static initialisers. |
| @@ -2308,7 +2325,7 @@ sub process { | |||
| 2308 | my $checkfile = "include/linux/$file"; | 2325 | my $checkfile = "include/linux/$file"; |
| 2309 | if (-f "$root/$checkfile" && | 2326 | if (-f "$root/$checkfile" && |
| 2310 | $realfile ne $checkfile && | 2327 | $realfile ne $checkfile && |
| 2311 | $1 ne 'irq') | 2328 | $1 !~ /$allowed_asm_includes/) |
| 2312 | { | 2329 | { |
| 2313 | if ($realfile =~ m{^arch/}) { | 2330 | if ($realfile =~ m{^arch/}) { |
| 2314 | CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); | 2331 | CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); |
| @@ -2570,6 +2587,21 @@ sub process { | |||
| 2570 | } | 2587 | } |
| 2571 | } | 2588 | } |
| 2572 | 2589 | ||
| 2590 | # prefer usleep_range over udelay | ||
| 2591 | if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { | ||
| 2592 | # ignore udelay's < 10, however | ||
| 2593 | if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { | ||
| 2594 | CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); | ||
| 2595 | } | ||
| 2596 | } | ||
| 2597 | |||
| 2598 | # warn about unexpectedly long msleep's | ||
| 2599 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { | ||
| 2600 | if ($1 < 20) { | ||
| 2601 | WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); | ||
| 2602 | } | ||
| 2603 | } | ||
| 2604 | |||
| 2573 | # warn about #ifdefs in C files | 2605 | # warn about #ifdefs in C files |
| 2574 | # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { | 2606 | # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { |
| 2575 | # print "#ifdef in C files should be avoided\n"; | 2607 | # print "#ifdef in C files should be avoided\n"; |
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index c827309c29cf..1ce655dde99e 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
| @@ -1245,6 +1245,8 @@ static void report_sec_mismatch(const char *modname, | |||
| 1245 | { | 1245 | { |
| 1246 | const char *from, *from_p; | 1246 | const char *from, *from_p; |
| 1247 | const char *to, *to_p; | 1247 | const char *to, *to_p; |
| 1248 | char *prl_from; | ||
| 1249 | char *prl_to; | ||
| 1248 | 1250 | ||
| 1249 | switch (from_is_func) { | 1251 | switch (from_is_func) { |
| 1250 | case 0: from = "variable"; from_p = ""; break; | 1252 | case 0: from = "variable"; from_p = ""; break; |
| @@ -1268,16 +1270,21 @@ static void report_sec_mismatch(const char *modname, | |||
| 1268 | 1270 | ||
| 1269 | switch (mismatch->mismatch) { | 1271 | switch (mismatch->mismatch) { |
| 1270 | case TEXT_TO_ANY_INIT: | 1272 | case TEXT_TO_ANY_INIT: |
| 1273 | prl_from = sec2annotation(fromsec); | ||
| 1274 | prl_to = sec2annotation(tosec); | ||
| 1271 | fprintf(stderr, | 1275 | fprintf(stderr, |
| 1272 | "The function %s%s() references\n" | 1276 | "The function %s%s() references\n" |
| 1273 | "the %s %s%s%s.\n" | 1277 | "the %s %s%s%s.\n" |
| 1274 | "This is often because %s lacks a %s\n" | 1278 | "This is often because %s lacks a %s\n" |
| 1275 | "annotation or the annotation of %s is wrong.\n", | 1279 | "annotation or the annotation of %s is wrong.\n", |
| 1276 | sec2annotation(fromsec), fromsym, | 1280 | prl_from, fromsym, |
| 1277 | to, sec2annotation(tosec), tosym, to_p, | 1281 | to, prl_to, tosym, to_p, |
| 1278 | fromsym, sec2annotation(tosec), tosym); | 1282 | fromsym, prl_to, tosym); |
| 1283 | free(prl_from); | ||
| 1284 | free(prl_to); | ||
| 1279 | break; | 1285 | break; |
| 1280 | case DATA_TO_ANY_INIT: { | 1286 | case DATA_TO_ANY_INIT: { |
| 1287 | prl_to = sec2annotation(tosec); | ||
| 1281 | const char *const *s = mismatch->symbol_white_list; | 1288 | const char *const *s = mismatch->symbol_white_list; |
| 1282 | fprintf(stderr, | 1289 | fprintf(stderr, |
| 1283 | "The variable %s references\n" | 1290 | "The variable %s references\n" |
| @@ -1285,20 +1292,24 @@ static void report_sec_mismatch(const char *modname, | |||
| 1285 | "If the reference is valid then annotate the\n" | 1292 | "If the reference is valid then annotate the\n" |
| 1286 | "variable with __init* or __refdata (see linux/init.h) " | 1293 | "variable with __init* or __refdata (see linux/init.h) " |
| 1287 | "or name the variable:\n", | 1294 | "or name the variable:\n", |
| 1288 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1295 | fromsym, to, prl_to, tosym, to_p); |
| 1289 | while (*s) | 1296 | while (*s) |
| 1290 | fprintf(stderr, "%s, ", *s++); | 1297 | fprintf(stderr, "%s, ", *s++); |
| 1291 | fprintf(stderr, "\n"); | 1298 | fprintf(stderr, "\n"); |
| 1299 | free(prl_to); | ||
| 1292 | break; | 1300 | break; |
| 1293 | } | 1301 | } |
| 1294 | case TEXT_TO_ANY_EXIT: | 1302 | case TEXT_TO_ANY_EXIT: |
| 1303 | prl_to = sec2annotation(tosec); | ||
| 1295 | fprintf(stderr, | 1304 | fprintf(stderr, |
| 1296 | "The function %s() references a %s in an exit section.\n" | 1305 | "The function %s() references a %s in an exit section.\n" |
| 1297 | "Often the %s %s%s has valid usage outside the exit section\n" | 1306 | "Often the %s %s%s has valid usage outside the exit section\n" |
| 1298 | "and the fix is to remove the %sannotation of %s.\n", | 1307 | "and the fix is to remove the %sannotation of %s.\n", |
| 1299 | fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); | 1308 | fromsym, to, to, tosym, to_p, prl_to, tosym); |
| 1309 | free(prl_to); | ||
| 1300 | break; | 1310 | break; |
| 1301 | case DATA_TO_ANY_EXIT: { | 1311 | case DATA_TO_ANY_EXIT: { |
| 1312 | prl_to = sec2annotation(tosec); | ||
| 1302 | const char *const *s = mismatch->symbol_white_list; | 1313 | const char *const *s = mismatch->symbol_white_list; |
| 1303 | fprintf(stderr, | 1314 | fprintf(stderr, |
| 1304 | "The variable %s references\n" | 1315 | "The variable %s references\n" |
| @@ -1306,24 +1317,31 @@ static void report_sec_mismatch(const char *modname, | |||
| 1306 | "If the reference is valid then annotate the\n" | 1317 | "If the reference is valid then annotate the\n" |
| 1307 | "variable with __exit* (see linux/init.h) or " | 1318 | "variable with __exit* (see linux/init.h) or " |
| 1308 | "name the variable:\n", | 1319 | "name the variable:\n", |
| 1309 | fromsym, to, sec2annotation(tosec), tosym, to_p); | 1320 | fromsym, to, prl_to, tosym, to_p); |
| 1310 | while (*s) | 1321 | while (*s) |
| 1311 | fprintf(stderr, "%s, ", *s++); | 1322 | fprintf(stderr, "%s, ", *s++); |
| 1312 | fprintf(stderr, "\n"); | 1323 | fprintf(stderr, "\n"); |
| 1324 | free(prl_to); | ||
| 1313 | break; | 1325 | break; |
| 1314 | } | 1326 | } |
| 1315 | case XXXINIT_TO_SOME_INIT: | 1327 | case XXXINIT_TO_SOME_INIT: |
| 1316 | case XXXEXIT_TO_SOME_EXIT: | 1328 | case XXXEXIT_TO_SOME_EXIT: |
| 1329 | prl_from = sec2annotation(fromsec); | ||
| 1330 | prl_to = sec2annotation(tosec); | ||
| 1317 | fprintf(stderr, | 1331 | fprintf(stderr, |
| 1318 | "The %s %s%s%s references\n" | 1332 | "The %s %s%s%s references\n" |
| 1319 | "a %s %s%s%s.\n" | 1333 | "a %s %s%s%s.\n" |
| 1320 | "If %s is only used by %s then\n" | 1334 | "If %s is only used by %s then\n" |
| 1321 | "annotate %s with a matching annotation.\n", | 1335 | "annotate %s with a matching annotation.\n", |
| 1322 | from, sec2annotation(fromsec), fromsym, from_p, | 1336 | from, prl_from, fromsym, from_p, |
| 1323 | to, sec2annotation(tosec), tosym, to_p, | 1337 | to, prl_to, tosym, to_p, |
| 1324 | tosym, fromsym, tosym); | 1338 | tosym, fromsym, tosym); |
| 1339 | free(prl_from); | ||
| 1340 | free(prl_to); | ||
| 1325 | break; | 1341 | break; |
| 1326 | case ANY_INIT_TO_ANY_EXIT: | 1342 | case ANY_INIT_TO_ANY_EXIT: |
| 1343 | prl_from = sec2annotation(fromsec); | ||
| 1344 | prl_to = sec2annotation(tosec); | ||
| 1327 | fprintf(stderr, | 1345 | fprintf(stderr, |
| 1328 | "The %s %s%s%s references\n" | 1346 | "The %s %s%s%s references\n" |
| 1329 | "a %s %s%s%s.\n" | 1347 | "a %s %s%s%s.\n" |
| @@ -1332,11 +1350,15 @@ static void report_sec_mismatch(const char *modname, | |||
| 1332 | "uses functionality in the exit path.\n" | 1350 | "uses functionality in the exit path.\n" |
| 1333 | "The fix is often to remove the %sannotation of\n" | 1351 | "The fix is often to remove the %sannotation of\n" |
| 1334 | "%s%s so it may be used outside an exit section.\n", | 1352 | "%s%s so it may be used outside an exit section.\n", |
| 1335 | from, sec2annotation(fromsec), fromsym, from_p, | 1353 | from, prl_from, fromsym, from_p, |
| 1336 | to, sec2annotation(tosec), tosym, to_p, | 1354 | to, prl_to, tosym, to_p, |
| 1337 | sec2annotation(tosec), tosym, to_p); | 1355 | sec2annotation(tosec), tosym, to_p); |
| 1356 | free(prl_from); | ||
| 1357 | free(prl_to); | ||
| 1338 | break; | 1358 | break; |
| 1339 | case ANY_EXIT_TO_ANY_INIT: | 1359 | case ANY_EXIT_TO_ANY_INIT: |
| 1360 | prl_from = sec2annotation(fromsec); | ||
| 1361 | prl_to = sec2annotation(tosec); | ||
| 1340 | fprintf(stderr, | 1362 | fprintf(stderr, |
| 1341 | "The %s %s%s%s references\n" | 1363 | "The %s %s%s%s references\n" |
| 1342 | "a %s %s%s%s.\n" | 1364 | "a %s %s%s%s.\n" |
| @@ -1345,16 +1367,20 @@ static void report_sec_mismatch(const char *modname, | |||
| 1345 | "uses functionality in the init path.\n" | 1367 | "uses functionality in the init path.\n" |
| 1346 | "The fix is often to remove the %sannotation of\n" | 1368 | "The fix is often to remove the %sannotation of\n" |
| 1347 | "%s%s so it may be used outside an init section.\n", | 1369 | "%s%s so it may be used outside an init section.\n", |
| 1348 | from, sec2annotation(fromsec), fromsym, from_p, | 1370 | from, prl_from, fromsym, from_p, |
| 1349 | to, sec2annotation(tosec), tosym, to_p, | 1371 | to, prl_to, tosym, to_p, |
| 1350 | sec2annotation(tosec), tosym, to_p); | 1372 | prl_to, tosym, to_p); |
| 1373 | free(prl_from); | ||
| 1374 | free(prl_to); | ||
| 1351 | break; | 1375 | break; |
| 1352 | case EXPORT_TO_INIT_EXIT: | 1376 | case EXPORT_TO_INIT_EXIT: |
| 1377 | prl_to = sec2annotation(tosec); | ||
| 1353 | fprintf(stderr, | 1378 | fprintf(stderr, |
| 1354 | "The symbol %s is exported and annotated %s\n" | 1379 | "The symbol %s is exported and annotated %s\n" |
| 1355 | "Fix this by removing the %sannotation of %s " | 1380 | "Fix this by removing the %sannotation of %s " |
| 1356 | "or drop the export.\n", | 1381 | "or drop the export.\n", |
| 1357 | tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); | 1382 | tosym, prl_to, prl_to, tosym); |
| 1383 | free(prl_to); | ||
| 1358 | break; | 1384 | break; |
| 1359 | } | 1385 | } |
| 1360 | fprintf(stderr, "\n"); | 1386 | fprintf(stderr, "\n"); |
