07 Aug, 2014
31 commits
-
Using uninitialized_var reports a false positive for "Missing blank line
after declarations".Fix it by adding uninitialized_var to the $declaration_macros exceptions
list.Move the macro list after $Type is declared.
Add optional prefixes to DECLARE_ and DEFINE_
macro declarations to allow forms like:
MLX4_DECLARE_DOORBELL_LOCKSigned-off-by: Joe Perches
Reported-by: Dotan Barak
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Checkpatch already complains when people break up quoted strings but
it's still pretty common. One mistake that people often make is they
leave out the space character between the two strings.This check adds around 450 new warnings and has a low rate of false
positives.Signed-off-by: Dan Carpenter
Cc: Andy Whitcroft
Acked-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Commit 89da401f6cff ("checkpatch: improve "no space after cast" test")
in -next improved the cast test for non pointer types, but also
introduced false positives for some types of static inlines.Add a test for an open brace to the exclusions to avoid these false
positives.Signed-off-by: Joe Perches
Reported-by: Hartley Sweeten
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Using --file mode can give false positives with MISSING_BREAK
fall-through warnings on simple but long multiple consecutive case
statements.Look for all lines before a case statement for a switch or a statement
when using --file mode.Fix a misspelling of preceded while there.
Signed-off-by: Joe Perches
Reported-by: Lee Jones
Acked-by: Lee Jones
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
c90 section "6.7.2 Type Specifiers" says:
"type specifiers may occur in any order"That means that:
short int is the same as int short
unsigned short int is the same as int unsigned short
etc...checkpatch currently parses only a subset of these allowed types.
For instance: "unsigned short" and "signed short" are found by
checkpatch as a specific type, but none of the or "int short" or "int
signed short" variants are found.Add another table for the "kernel style misordered" variants.
Add this misordered table to the findable types.
Warn when the misordered style is used.
This improves the "Missing a blank line after declarations" test as it
depends on the correct parsing of the $Declare variable which looks for
"$Type $Ident;" (ie: declarations like "int foo;").Signed-off-by: Joe Perches
Acked-by: Andy Whitcroft
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Current generic types are unsigned or unspecified. Add signed to the
types.Reorder the types to find the longest match first.
Signed-off-by: Joe Perches
Acked-by: Andy Whitcroft
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
short int is one of the 6.7.2 c90 types.
Find it appropriately.This fixes a defect in checkpatch where it suggests that a line break
after declaration is required using an input like:int foo;
short int bar;Without this change, it warns on the short int line.
Signed-off-by: Joe Perches
Reported-by: Hartley Sweeten
Acked-by: Andy Whitcroft
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
All the various for_each loop macros were not tested for trailing brace
on the following lines and for bad indentation.Add them.
Signed-off-by: Joe Perches
Reported-by: Greg KH
Cc: Andy Whitcroft
Signed-off-by: Linus Torvalds -
Add --fix corrections for ELSE_AFTER_BRACE and WHILE_AFTER_BRACE
misuses.if (x) {
...
}
else {
...
}is corrected to
if (x) {
...
} else {
...
}and
do {
...
}
while (x);is corrected to
do {
...
} while (x);Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Style misuses of these types are corrected:
typedef struct foo
{
int bar;
};int foo(int bar) { return bar+1;
}int foo(int bar) {
return bar+1;
}Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
I copied the which subroutine from get_maintainer.pl.
Unfortunately, get_maintainer uses a 4 space indentation so use the
proper tab indentation instead.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Neaten the uses of patch/file line insertions or deletions. Hide the
mechanism used.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
This can be valuable to insert or delete blank lines as well as fix
misplaced brace or else uses.Store indexes of lines to be added/deleted and the new lines.
When creating the --fix file, insert or delete the appropriate lines and
update the patch range information.Signed-off-by: Joe Perches
Cc: Andy Whitcroft
Cc: Dan Carpenter
Cc: Josh Triplett
Cc: Greg Kroah-Hartman
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Make the fix code a bit easier to read.
This should also start to allow an easier mechanism to insert/delete
lines eventually too.Signed-off-by: Joe Perches
Cc: Andy Whitcroft
Cc: Dan Carpenter
Cc: Josh Triplett
Cc: Greg Kroah-Hartman
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Using break; after a goto or return is unnecessary so emit a warning
when the break is at the same indent level.So this emits a warning on:
switch (foo) {
case 1:
goto err;
break;
}but not on:
switch (foo) {
case 1:
if (bar())
goto err;
break;
}Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Whenever files are added, moved, or deleted, the MAINTAINERS file
patterns can be out of sync or outdated.To try to keep MAINTAINERS more up-to-date, add a one-time warning
whenever a patch does any of those.Signed-off-by: Joe Perches
Acked-by: Andy Whitcroft
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Commit logs have various forms of commit id references.
Try to standardize on a 12 character long lower case commit id along
with a description of parentheses and the quoted subject line.ie: commit 0123456789ab ("commit description")
If git and a git tree exists, look up the commit id and emit the
appropriate line as part of the message.Signed-off-by: Joe Perches
Requested-by: Andrew Morton
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Avoid matching allocs that appear to be known small multiplications of a
sizeof with a constant because gcc as of 4.8 cannot optimize the code in
a calloc() exactly the same way as an alloc().Look for numeric constants or what appear to be upper case only macro
#defines.Signed-off-by: Joe Perches
Reported-by: Theodore Ts'o
Original-patch-by: Fabian Frederick
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
This --strict test previously worked only for what appeared to be cast
to pointer types.Make it work for all casts.
Also, there's no reason to show the previous line for this type of
message, so don't.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
checkpatch's $Type variable does not match declarations of multiple
const * types.This can produce false positives for things like:
$ ./scripts/checkpatch.pl -f drivers/staging/comedi/comedidev.h
WARNING: Missing a blank line after declarations
#60: FILE: drivers/staging/comedi/comedidev.h:60:
+ const struct comedi_lrange *range_table;
+ const struct comedi_lrange *const *range_table_list;Fix the $Type variable to support matching multiple "* const" uses.
Signed-off-by: Joe Perches
Reported-by: Hartley Sweeten
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Parentheses around &(foo->bar) and *(foo->bar) are unnecessary. Emit a
--strict only message on these uses.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Editing Kconfig dependencies can emit unnecessary messages about missing
or too short help entries.Only emit the message when adding help sections to Kconfig files.
Signed-off-by: Joe Perches
Reported-by: Jean Delvare
Tested-by: Jean Delvare
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Make it consistent with the other missing or multiple blank line tests.
Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Multiple consecutive blank lines waste screen space. Emit a --strict
only message with these blank lines.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Add a --strict test asking for a blank line after
function/struct/union/enum declarations.Allow exceptions for several attributes and macro uses.
Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
This might help a kernel hacker think twice before blindly adding a
newline.Signed-off-by: Rasmus Villemoes
Acked-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
There are some patches created by git format-patch that when scanned by
checkpatch report errors on lines likeTo: address.tld
This is a checkpatch false positive.
Improve the logic a bit to ignore folded email headers to avoid emitting
these messages.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Add a function pointer declaration check to the test for blank line
needed after declarations.Signed-off-by: Joe Perches
Reported-by: Bruce W Allan
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
A single escaped constant char is not a complex macro.
Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Using an else following a break or return can unnecessarily indent code
blocks.ie:
for (i = 0; i < 100; i++) {
int foo = bar();
if (foo < 1)
break;
else
usleep(1);
}is generally better written as:
for (i = 0; i < 100; i++) {
int foo = bar();
if (foo < 1)
break;
usleep(1);
}Warn when a bare else statement is preceded by a break or return
indented 1 tab more than the else.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Logging messages that show some type of "out of memory" error are
generally unnecessary as there is a generic message and a stack dump
done by the memory subsystem.These messages generally increase kernel size without much added value.
Emit a warning on these types of messages.
This test looks for any inserted message function, then looks at the
previous line for an "if (!foo)" or "if (foo == NULL)" test and then
looks at the preceding statement for an allocation function like "foo =
kmalloc()"ie: this code matches:
foo = kmalloc();
if (foo == NULL) {
printk("Out of memory\n");
return -ENOMEM;
}This test is very crude and incomplete.
This test can miss quite a lot of of OOM messages that do not have this
specific form.ie: this code does not match:
foo = kmalloc();
if (!foo) {
rtn = -ENOMEM;
printk("Out of memory!\n");
goto out;
}This test could also be a false positive when the logging message itself
does not specify anything about memory, but I did not find any false
positives in my limited testing.spatch could be a better solution but correctness seems non-trivial for
that tool too.Signed-off-by: Joe Perches
Acked-by: Dan Carpenter
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds
24 Jun, 2014
1 commit
-
The previous patch had a few too many false positives on styles that
should be acceptable.Signed-off-by: Joe Perches
Tested-by: Anish Bhatt
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds
05 Jun, 2014
8 commits
-
This patch adds a link to init.h to find appropriate initcall function to
replace obsolete __initcallSigned-off-by: Fabian Frederick
Cc: Andy Whitcroft
Cc: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
It should be stable@vger.kernel.org, not stable@kernel.org.
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
void function lines that use a single tab then "return;" are generally
unnecessary.Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Use the kstrto functions in preference to sscanf.
Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Protect against sizeof overflows by preferring kmalloc_array/kcalloc over
kmalloc/kzalloc with a sizeof multiply.Signed-off-by: Joe Perches
Cc: Andy Whitcroft
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Using a #define ending in a semicolon is poor style and can lead to
unexpected code paths being executed.Warn on uses of these #define types:
#define foo[(...)] bar;
#define foo[(...)] \
bar;Based on a patch from Borislav Petkov.
Signed-off-by: Joe Perches
Cc: Borislav Petkov
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Networking files are generally more strictly conformant to linux-kernel
style so make checkpatch more verbose by default for patches to files or
when checking files in these directories.Signed-off-by: Joe Perches
Cc: Andy Whitcroft
Cc: David Miller
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds -
Make the test system wide, modify the message too.
Signed-off-by: Joe Perches
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds