Commit Graph

458 Commits

Author SHA1 Message Date
Kees Cook 26e98ee685 checkpatch: look for common misspellings
Check for misspellings, based on Debian's lintian list.  Several false
positives were removed, and several additional words added that were
common in the kernel:

	backword backwords
	invalide valide
	recieves
	singed unsinged

While going back and fixing existing spelling mistakes isn't a high
priority, it'd be nice to try to catch them before they hit the tree.

In the 13830 commits between 3.15 and 3.16, the script would have noticed
560 spelling mistakes. The top 25 are shown here:

$ git log --pretty=oneline v3.15..v3.16 | wc -l
13830
$ git log --format='%H' v3.15..v3.16 | \
   while read commit ; do \
     echo "commit $commit" ; \
     git log --format=email --stat -p -1 $commit | \
       ./scripts/checkpatch.pl --types=typo_spelling --no-summary - ; \
   done | tee spell_v3.15..v3.16.txt | grep "may be misspelled" | \
   awk '{print $2}' | tr A-Z a-z | sort | uniq -c | sort -rn
     21 'seperate'
     17 'endianess'
     15 'sucess'
     13 'noticable'
     11 'occured'
     11 'accomodate'
     10 'interrup'
      9 'prefered'
      8 'unecessary'
      8 'explicitely'
      7 'supress'
      7 'overriden'
      7 'immediatly'
      7 'funtion'
      7 'defult'
      7 'childs'
      6 'succesful'
      6 'splitted'
      6 'specifc'
      6 'reseting'
      6 'recieve'
      6 'changable'
      5 'tmis'
      5 'singed'
      5 'preceeding'

Thanks to Joe Perches for rewrites, suggestions, additional misspelling
entries, and testing.

Change-Id: I449f512eda763dfeddd212bba24de723297d7004
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Joe Perches <joe@perches.com>
Cc: Masanari Iida <standby24x7@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 66b47b4a9dad00e45c049d79966de9a3a1f4d337
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:57 -07:00
Joe Perches dc6e2c6d06 checkpatch: warn on macros with flow control statements
Macros with flow control statements (goto and return) are not very nice to
read as any flow movement is unexpected.

Try to highlight them and emit a warning on their definition.

Avoid warning on macros that use argument concatenation as those macros
commonly create another function where the concatenation is used in the
function name definition like:

	#define FOO_FUNC(name, rtn_type)	\
	rtn_type func##name(arg1, ...)		\
	{					\
		rtn_type rtn;			\
		[code...]			\
		return rtn;			\
	}

Change-Id: I8eb96e09a088a16d219a082de5ef9575060e367a
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 08a2843e77fc581d204c1e83de4678b746cdbd6e
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:55 -07:00
Joe Perches 0ec9c96ac1 checkpatch: remove unnecessary + after {8,8}
There's a useless "+" use that needs to be removed as perl 5.20 emits a
"Useless use of greediness modifier '+'" message each time it's hit.

Change-Id: I7789c81968e840f36aa4f526a4280ff3a7131b8b
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Greg KH <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: d2207ccbc59900311c88bb9150b24253cd4ddd49
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:53 -07:00
Joe Perches a96cdd33e0 checkpatch: add --strict test for concatenated string elements
Using a space between concatenated string elements is easier for a human
to read.

ie:
	"String"FOO"bar"

is easier to read as:

	"String" FOO "bar"

So suggest this style with a --strict command line option.

Change-Id: I1fd78a48f948a940e3cbd6a5b2aa4f5c1bb7d419
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: f17dba4fc0496eb0daf018074fccebdc85993c75
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:52 -07:00
Vadim Bendebury 23397a057f checkpatch: allow optional shorter config descriptions
This script is used by many other projects, and in some of them the
requirement of at least 4 line long description for all Kconfig items is
excessive.  This patch adds a command line option to control the required
minimum length.

Tested running this script over a patch including a two line config
description.  The script generated a warning when invoked as is, and did
not generate it when invoked with --min-conf-desc-length=2.

Change-Id: I5983651d1bda56438451a40f55872e8965f2ef08
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Acked-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 56193274ef54265afc93fd282655836595fcff9d
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:50 -07:00
Geert Uytterhoeven 2dda6389f9 checkpatch: enable whitespace checks for DTS files
When run on *.dtsi or *.dts files, the whitespace checks were skipped,
while they are valid for DTS files.  Hence stop skipping them.

I ran checkpatch on all in-tree DTS files, and didn't notice any error or
warning messages that are inappropriate for DTS files.

Change-Id: Icf4ab7fe8a1eaa18dac8faa281aa88ba5ca6b260
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: de4c924c265049e576036d1ee6fc9dfefeb5ae87
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:48 -07:00
Sergey Ryazanov 63c037275e checkpatch: update $allowed_asm_includes macros, add reboot.h and time.h
Several architectures (e.g.  x86, MIPS, Blackfin) have asm/reboot.h and
asm/time.h header files, which are not included in linux/reboot.h and
linux/time.h headers.  This lead to generation of false positive errors.

Change-Id: Ia6138ec1802b8ac5876db7cae825b27971bddb2a
Signed-off-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: cdcee686ee9047185b7a484614f6c2faa5c4a7bb
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:46 -07:00
Joe Perches 087de3116e checkpatch: remove debugging message
An unnecessary --fix debugging left-over is removed.

Change-Id: I9fe0a94f67a64b1e0305d35cb522bfcef4ba3e65
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 72c231cb70eddb56e7e532f64dc22301044486dc
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:45 -07:00
Andrew Morton 49409c28fa checkpatch: fix spello
The plural of parenthesis is parentheses.

Change-Id: Idc465d5505ff00ebc4fce76b2ae1b798f1e9b0e4
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 388982b55e3290d4970e4c2951f3f6348fd0c54b
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:43 -07:00
Joe Perches e3089bac9f checkpatch: allow commit descriptions on separate line from commit id
The general form for commit id and description is

  'Commit <12+hexdigits> ("commit description/subject line")'

but commit logs often have relatively long commit ids and the commit
description emds on the next line like:

  Some explanation as to why commit <12+hexdigits>
  ("commit foo description/subject line") is improved.

Allow this form.

Change-Id: Idaa70aa9410c83c955a78595419d9435a6dc951a
Signed-off-by: Joe Perches <joe@perches.com>
Suggested-by: Joe Lawrence <joe.lawrence@stratus.com>
Tested-by: Joe Lawrence <joe.lawrence@stratus.com>
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 66881735071e54283df38ffbd9584c63e3661b9f
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:41 -07:00
Joe Perches 297d63bb12 checkpatch: relax check for length of git commit IDs
Checkpatch currently warns if a git commit ID (in the changelog,
usually) is less than 12 characters or more than 16.  The "more than 16"
is excessive.  Change the check so we accept IDs from 12 to 40 chars in
length.

Change-Id: I8529e7f66be94a576a6185c54c954384624050b7
Cc: Geert Uytterhoeven <geert@linux-m68k.org
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 3f6316b4378e64e96acfe55b499648dc0e6b9603
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:39 -07:00
Joe Perches db1341aef5 checkpatch: update $declaration_macros, add uninitialized_var
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_<FOO> and DEFINE_<BAR>
macro declarations to allow forms like:
	MLX4_DECLARE_DOORBELL_LOCK

Change-Id: I32098b9c57ac153b220df02d7434047d14675e85
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Dotan Barak <dotanb@mellanox.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: f84223087402c45179be5e7060c5736c17a7b271
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:37 -07:00
Dan Carpenter 7fba05be25 checkpatch: warn on missing spaces in broken up quoted
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.

Change-Id: I9f5c001db68543ede41cc435b4abd7b60006a99a
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andy Whitcroft <apw@canonical.com>
Acked-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: ece9659f16e369d344fe4325d87fab3bb50d1fe2
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:36 -07:00
Joe Perches e0daf82540 checkpatch: fix false positives for --strict "space after cast" test
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.

Change-Id: I1d406f90b16aaeac0fa6f4d8d2ee5bdf5cb368da
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Hartley Sweeten <HartleyS@visionengravers.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 308cc8d8f0deab2c5a5162316277ced556acc71f
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:34 -07:00
Joe Perches 5eae304120 checkpatch: fix false positive MISSING_BREAK warnings with --file
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.

Change-Id: I3611d1aa76fa38cc9c8070c6d4322aac53b4c75d
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: e81f239b4db2ad6c4b029ed92f0222601ce42abe
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:32 -07:00
Joe Perches 99ec6ca7fd checkpatch: add test for native c90 types in unusual order
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;").

Change-Id: If90e05d793270095d9b71148866335ca277a7966
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 1813087dbc54ff1485bcc84b66d34052eaf23387
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:31 -07:00
Joe Perches 5a0c503893 checkpatch: add signed generic types
Current generic types are unsigned or unspecified.  Add signed to the
types.

Reorder the types to find the longest match first.

Change-Id: I6e902db549ff258537fc72fe73c162016cc07695
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 0c773d9d66684aefd919c4b4550fe16003c54c0e
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:29 -07:00
Joe Perches 9b98368fbd checkpatch: add short int to c variable types
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.

Change-Id: I4b81aea32a4587ff956c033564bc56bbac8b4e40
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Hartley Sweeten <HartleyS@visionengravers.com>
Acked-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 3f7bc4e1fcfab05f3e8b49134cfb3e16b8876aae
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:27 -07:00
Joe Perches ed4080dd23 checkpatch: add for_each tests to indentation and brace tests
All the various for_each loop macros were not tested for trailing brace
on the following lines and for bad indentation.

Add them.

Change-Id: Ie70972cc131d0e5070fc8fbf0016fa4d292ec4f8
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Greg KH <gregkh@linuxfoundation.org>
Cc: Andy Whitcroft <apw@canonical.com
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 0fe3dc2bc554b849c27c0ebc36daedf032514200
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:26 -07:00
Joe Perches 92522066d2 checkpatch: fix brace style misuses of else and while
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);

Change-Id: I3ab9ffb674cfffeab40449b9da3144ca9312ac66
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 8b8856f4b102ce148611322465f2ff8932664411
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:24 -07:00
Joe Perches 0dcab23748 checkpatch: add --fix option for a couple OPEN_BRACE misuses
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;
  }

Change-Id: I0cf1de43d14eafae626938e624c80229c684fb28
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 8d1824780f2f1786db5e0e7a54bbae75340c655c
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:22 -07:00
Joe Perches f0d1750bb7 checkpatch: use the correct indentation for which()
I copied the which subroutine from get_maintainer.pl.

Unfortunately, get_maintainer uses a 4 space indentation so use the
proper tab indentation instead.

Change-Id: I5950f5a1acd5bbe8882a4bafe67103c1df661065
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: bd474ca076af8ac6fa8c5f4167f6024b446a08c8
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:21 -07:00
Joe Perches 41f42c1660 checkpatch: add fix_insert_line and fix_delete_line helpers
Neaten the uses of patch/file line insertions or deletions.  Hide the
mechanism used.

Change-Id: Ied1415b7310273ea0e62d5c5350bf433ea91048f
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: f2d7e4d4398092d14fb039cb4d38e502d3f019ee
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:19 -07:00
Joe Perches 235a2c5e06 checkpatch: add ability to insert and delete lines to patch/file
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.

Change-Id: I077cb73b0fe227ede4aa1fdbc7be64b8b6e2042e
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: d752fcc88b7dddc0bbe6d43b658b306a9d7d1dae
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:17 -07:00
Joe Perches 396787014f checkpatch: add an index variable for fixed lines
Make the fix code a bit easier to read.

This should also start to allow an easier mechanism to insert/delete
lines eventually too.

Change-Id: I864889064c07c70695d435f012921a02b5057437
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 194f66fc9567367b3fa2dcbc1b87b091330ef186
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:16 -07:00
Joe Perches 827c035ad1 checkpatch: warn on break after goto or return with same tab indentation
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;
	}

Change-Id: I09bfa7a9636d4785d05cfc13070e5d8179baf78d
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: c00df19a5026f2cb08f1770dcc29226512f4d099
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:14 -07:00
Joe Perches 474d963efb checkpatch: emit a warning on file add/move/delete
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.

Change-Id: Ic2ae42f660243a0d2912382176b7d7fd6ff78156
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 13f1937ef33950b1112049972249e6191b82e6c9
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:13 -07:00
Joe Perches e7305f2f39 checkpatch: add test for commit id formatting style in commit log
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.

Change-Id: I6934c7a0c3f1dd752dafb281a7df9cffaf3e1592
Signed-off-by: Joe Perches <joe@perches.com>
Requested-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: d311cd44545f2f69749c68d6723360b4cc21cd02
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:11 -07:00
Joe Perches 143e917980 checkpatch: emit fewer kmalloc_array/kcalloc conversion warnings
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

Change-Id: I68df66937de3a76277e37add9e52bc989e6c627b
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Theodore Ts'o <tytso@mit.edu>
Original-patch-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: e367455a9f25b11e02b7ea7678a7b146bdd6667e
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:09 -07:00
Joe Perches 58518f9e87 checkpatch: improve "no space after cast" test
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.

Change-Id: I16a1b57d9ff8074d9ca9c9a09b12bc60f7e6cbc0
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: f27c95db1176b41c6c87d9d3480d15efbca8f3ff
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:08 -07:00
Joe Perches 3038e7a7b6 checkpatch: allow multiple const * types
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.

Change-Id: I4eb0e54b15531ad5dd7d029506368b5f002b61b8
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Hartley Sweeten <HartleyS@visionengravers.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 1574a29f8e769998fe3e55eb6030dc61e3d09ccd
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:06 -07:00
Joe Perches e8c796717a checkpatch: warn on unnecessary parentheses around references of foo->bar
Parentheses around &(foo->bar) and *(foo->bar) are unnecessary.  Emit a
--strict only message on these uses.

Change-Id: Ib518b0017e6d304196bd4b1b085dfda701cbc199
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: e2826fd07029e14285c178b41b18f6edc3b15a84
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:04 -07:00
Joe Perches 8f35939c3a checkpatch: quiet Kconfig help message checking
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.

Change-Id: I0972cf73000ad03617473621475dff296babcbac
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Jean Delvare <jdelvare@suse.de>
Tested-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 8d73e0e7dc18a39b120cb85ec675d59516e0af1a
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:03 -07:00
Joe Perches 42abd69a48 checkpatch: change blank line after declaration type to "LINE_SPACING"
Make it consistent with the other missing or multiple blank line tests.

Change-Id: Ifa1270ae3ce99bc848bd47f913cc35495c2d5572
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: fee0aa83d43ee65648778d48d47975c323fa0490
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:43:01 -07:00
Joe Perches e2cfdaa8e6 checkpatch: add a multiple blank lines test
Multiple consecutive blank lines waste screen space.  Emit a --strict
only message with these blank lines.

Change-Id: Ia6718a4612f8e4ed1d5b82aa38c7b9ae1208a94e
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 365dd4eaafa22d2c79913d5f057d636e8842c470
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:59 -07:00
Joe Perches edac29ec52 checkpatch: add test for blank lines after function/struct/union/enum
Add a --strict test asking for a blank line after
function/struct/union/enum declarations.

Allow exceptions for several attributes and macro uses.

Change-Id: Id963b84677ddeced75617af9302a780bb994a84b
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 7f61919144ca69ea29f29c3e60c5b7dbd2070aa6
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:58 -07:00
Rasmus Villemoes 4dd87d3c3f checkpatch.pl: also suggest 'else if' when if follows brace
This might help a kernel hacker think twice before blindly adding a
newline.

Change-Id: I6af4feefe202cbbd676167c443b6d7e931a5c5c5
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 048b123fad06f33169caa4afd6d56d58c31517e5
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:56 -07:00
Joe Perches 7e4970273c checkpatch: ignore email headers better
There are some patches created by git format-patch that when scanned by
checkpatch report errors on lines like

To:	address.tld

This is a checkpatch false positive.

Improve the logic a bit to ignore folded email headers to avoid emitting
these messages.

Change-Id: Ia0e8ee78b677ed9c8dc200a47abe59223d613f46
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 29ee1b0c67e0dd7dea8dd718e8326076bce5b6fe
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:54 -07:00
Joe Perches 5b1fc6f2d1 checkpatch: fix function pointers in blank line needed after declarations test
Add a function pointer declaration check to the test for blank line
needed after declarations.

Change-Id: I531e014d098fdb2b76dd951c7a09f4c931295306
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Bruce W Allan <bruce.w.allan@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 5a4e1fd37d0677755391e2e89e9386e072265157
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:53 -07:00
Joe Perches 179f8f410f checkpatch: fix complex macro false positive for escaped constant char
A single escaped constant char is not a complex macro.

Change-Id: I75c5bbd995dd231ec3a83fa7fc72ba29a8d8b3d2
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 356fd398135480363402cd334ac3218be56b7201
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:51 -07:00
Joe Perches 8a42608dcb checkpatch: warn on unnecessary else after return or break
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.

Change-Id: I04d1998fde9243b9717a415b239bec63c0f9146f
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 032a4c0f9a77ce565355c6e191553e853ba66f09
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:49 -07:00
Joe Perches b2d08d1ba9 checkpatch: attempt to find unnecessary 'out of memory' messages
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.

Change-Id: I4cf42758d2c546d5fa91f5f4659e42a1e3b9c341
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: ebfdc40969f24fc0cdd1349835d36e8ebae05374
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:48 -07:00
Joe Perches 95aa68449f checkpatch: reduce false positives when checking void function return statements
The previous patch had a few too many false positives on styles that
should be acceptable.

Change-Id: Id29462d26534c6e8d5fd5fff5a8212c134855de7
Signed-off-by: Joe Perches <joe@perches.com>
Tested-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: b43ae21bd1d8199df10548f3fc0d806052027f29
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:46 -07:00
Fabian Frederick bc61f5d18e scripts/checkpatch.pl: device_initcall is not the only __initcall substitute
This patch adds a link to init.h to find appropriate initcall function to
replace obsolete __initcall

Change-Id: Ifc9e8d3c1d7b02165bee707788f7cdad4b7da2c5
Signed-off-by: Fabian Frederick <fabf@skynet.be>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: ae3ccc4678fec2d270a4c54981831c7b8a2da9cd
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:44 -07:00
Joe Perches dda57b7a9e checkpatch: check stable email address
It should be stable@vger.kernel.org, not stable@kernel.org.

Change-Id: I67cee4be81d9c638313823046d8ba30f81b42727
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 9b3189eb424044e51c8847063b2ba314b57b6ed2
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:42 -07:00
Joe Perches 0dd150bcc3 checkpatch: warn on unnecessary void function return statements
void function lines that use a single tab then "return;" are generally
unnecessary.

Change-Id: Ib310bf8de9f2a58aefa3e54b8c903723394ac23c
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 9819cf252a0fad1bf46aac8a051cf30426e073ee
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:41 -07:00
Joe Perches 5078d74982 checkpatch: prefer kstrto<foo> to sscanf(buf, "%<lhuidx>", &bar);
Use the kstrto<foo> functions in preference to sscanf.

Change-Id: I9efad914bd1efbb9b4baf6df4e3658537a72a65c
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: afc819ab0293be3bd5c16d9eba26f9d57f61c42a
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:39 -07:00
Joe Perches a3f8de30e9 checkpatch: add warning for kmalloc/kzalloc with multiply
Protect against sizeof overflows by preferring kmalloc_array/kcalloc over
kmalloc/kzalloc with a sizeof multiply.

Change-Id: I30b4a314eb21c672d7096af1ef565a5b54d12777
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 60a55369aad3336e604218abf2057363f69c0722
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:38 -07:00
Joe Perches 32c5d34caf checkpatch: warn on #defines ending in semicolon
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.

Change-Id: Ie182f7a5edbc36ba0bf79b0c3e095832dc4209ca
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: f5ef95b12eb03ae4b3994cdb035612e127b630b9
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:36 -07:00
Joe Perches e34d61e5b6 checkpatch: make --strict a default for files in drivers/net and net/
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.

Change-Id: I498342b8a457082c10c115f790335cbb9c8c9ef6
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: David Miller <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Git-commit: 2ac73b4f685e699ccdfa6855e826df846999d577
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
2015-06-25 17:42:35 -07:00