Checkpatch: Backport changes from 2.6.35

Backport a series of checkpatch changes from 2.6.35; having
these checks in our tree now will help with upstreaming
efforts.

A summary of the changes:

(trivial) remove Dave Jones' email
Add initconst attribute
Switch printk exception to logFunctions
check for spaces before a quoted newline
check for space before tabs
improved check spacing on parentheses
improved conditional checking
add some exceptions to multi-statement macro exceptions
Check that the storage class is at the beginning of a declaration
check for sizeof(&)
check for various ops structs, ensure they are const.
check for lockdep_set_novalidate_class

The following commits are included:

commit dbf004d788
Author: Dave Jones <davej@redhat.com>
Date:   Tue Jan 12 16:59:52 2010 -0500

    remove my email address from checkpatch.

    Maybe this will stop people emailing me about it.

    Signed-off-by: Dave Jones <davej@redhat.com>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 52131292c0
Author: Wolfram Sang <w.sang@pengutronix.de>
Date:   Fri Mar 5 13:43:51 2010 -0800

    checkpatch: fix false positive on __initconst

    checkpatch falsely complained about '__initconst' because it thought the
    'const' needed a space before.  Fix this by changing the list of
    attributes:

    - add '__initconst'
    - force plain 'init' to contain a word-boundary at the end

    Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 691e669ba8
Author: Joe Perches <joe@perches.com>
Date:   Fri Mar 5 13:43:51 2010 -0800

    checkpatch.pl: allow > 80 char lines for logging functions not just printk

    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>

commit 3354957a4f
Author: Andi Kleen <ak@linux.intel.com>
Date:   Mon May 24 14:33:29 2010 -0700

    checkpatch: add check for too short Kconfig descriptions

    I've seen various new Kconfigs with rather unhelpful one liner
    descriptions.  Add a Kconfig warning for a minimum length of the Kconfig
    help section.

    Right now I arbitarily chose 4. The exact value can be debated.

    [akpm@linux-foundation.org: coding-style fixes]
    Signed-off-by: Andi Kleen <ak@linux.intel.com>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 5e79d96eed
Author: Joe Perches <joe@perches.com>
Date:   Fri Mar 5 13:43:55 2010 -0800

    checkpatch: warn on unnecessary spaces before quoted newlines

    Signed-off-by: Joe Perches <joe@perches.com>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 08e4436566
Author: Alberto Panizzo <maramaopercheseimorto@gmail.com>
Date:   Fri Mar 5 13:43:54 2010 -0800

    checkpatch.pl: warn if an adding line introduce spaces before tabs.

    Signed-off-by: Alberto Panizzo <maramaopercheseimorto@gmail.com>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 42bdf74c95
Author: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Date:   Fri Mar 5 13:43:50 2010 -0800

    checkpatch: trivial fix for trailing statements check

    In case if the statement and the conditional are in one line, the line
    appears in the report doubly.

    And items of this check have no blank line before the next item.

    This patch fixes these trivial problems, to improve readability of the
    report.

    [sample.c]
      > if (cond1
      >        && cond2
      >        && cond3) func_foo();
      >
      > if (cond4) func_bar();

    Before:
      > ERROR: trailing statements should be on next line
      > #1: FILE: sample.c:1:
      > +if (cond1
      > [...]
      > +       && cond3) func_foo();
      > ERROR: trailing statements should be on next line
      > #5: FILE: sample.c:5:
      > +if (cond4) func_bar();
      > +if (cond4) func_bar();
      > total: 2 errors, 0 warnings, 5 lines checked

    After:
      > ERROR: trailing statements should be on next line
      > #1: FILE: sample.c:1:
      > +if (cond1
      > [...]
      > +       && cond3) func_foo();
      >
      > ERROR: trailing statements should be on next line
      > #5: FILE: sample.c:5:
      > +if (cond4) func_bar();
      >
      > total: 2 errors, 0 warnings, 5 lines checked

    Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.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>

commit 22fd2d3e4f
Author: Stefani Seibold <stefani@seibold.net>
Date:   Fri Mar 5 13:43:52 2010 -0800

    checkpatch.pl: add union and struct to the exceptions list

    Here is a small code snippet, which will be complained about by
    checkpatch.pl:

    #define __STRUCT_KFIFO_COMMON(recsize, ptrtype) \
        union { \
                struct { \
                        unsigned int    in; \
                        unsigned int    out; \
                }; \
                char            rectype[recsize]; \
                ptrtype         *ptr; \
                const ptrtype   *ptr_const; \
        };

    This construct is legal and safe, so checkpatch.pl should accept this.  It
    should be also true for struct defined in a macro.

    Add the `struct' and `union' keywords to the exceptions list of the
    checkpatch.pl script, to prevent error message "Macros with multiple
    statements should be enclosed in a do - while loop".  Otherwise it is not
    possible to build a struct or union with a macro.

    Signed-off-by: Stefani Seibold <stefani@seibold.net>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit d4977c78e9
Author: Tobias Klauser <tklauser@distanz.ch>
Date:   Mon May 24 14:33:30 2010 -0700

    checkpatch: warn on declaration with storage class not at the beginning

    The C99 specification states in section 6.11.5:

    The placement of a storage-class specifier other than at the beginning
    of the declaration specifiers in a declaration is an obsolescent
    feature.

    Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
    Acked-by: Jean Delvare <khali@linux-fr.org>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 8f53a9b80f
Author: Joe Perches <joe@perches.com>
Date:   Fri Mar 5 13:43:48 2010 -0800

    scripts/checkpatch.pl: add WARN on sizeof(&foo)

    sizeof(&foo) is frequently an error.  Warn on its use.

    Signed-off-by: Joe Perches <joe@perches.com>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 79404849e9
Author: Emese Revfy <re.emese@gmail.com>
Date:   Fri Mar 5 13:43:53 2010 -0800

    checkpatch.pl: extend list of expected-to-be-const structures

    Based on Arjan's suggestion, extend the list of ops structures that should
    be const.

    Signed-off-by: Emese Revfy <re.emese@gmail.com>
    Cc: Andy Whitcroft <apw@shadowen.org>
    Cc: Arjan van de Ven <arjan@infradead.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

commit 1704f47b50
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Fri Mar 19 01:37:42 2010 +0100

    lockdep: Add novalidate class for dev->mutex conversion

    The conversion of device->sem to device->mutex resulted in lockdep
    warnings. Create a novalidate class for now until the driver folks
    come up with separate classes. That way we have at least the basic
    mutex debugging coverage.

    Add a checkpatch error so the usage is reserved for device->mutex.

    [ tglx: checkpatch and compile fix for LOCKDEP=n ]

    Signed-off-by: Peter Zijlstra <peterz@infradead.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Change-Id: I11495554d7d393659e5e0d7188cdc1744e25b6ba
Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
(cherry picked from commit 4657bf482381583b08b34ed5ea6f7d3ad162807c)

Conflicts:

	scripts/checkpatch.pl
This commit is contained in:
Patrick Pannuto 2010-07-27 17:15:07 -07:00 committed by Stephen Boyd
parent e388f38442
commit d917e71c27

View file

@ -1842,6 +1842,21 @@ sub process {
"Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
}
# check for Kconfig help text having a real description
if ($realfile =~ /Kconfig/ &&
$line =~ /\+?\s*(---)?help(---)?$/) {
my $length = 0;
for (my $l = $linenr; defined($lines[$l]); $l++) {
my $f = $lines[$l];
$f =~ s/#.*//;
$f =~ s/^\s+//;
next if ($f =~ /^$/);
last if ($f =~ /^\s*config\s/);
$length++;
}
WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($length < 4);
}
# check we are in a valid source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
@ -1878,6 +1893,11 @@ sub process {
"unnecessary whitespace before a quoted newline\n" . $herecurr);
}
# check for spaces before a quoted newline
if ($rawline =~ /^.*\".*\s\\n/) {
WARN("unnecessary whitespace before a quoted newline\n" . $herecurr);
}
# check for adding lines without a newline.
if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
WARN("MISSING_EOF_NEWLINE",
@ -1965,6 +1985,12 @@ sub process {
"please, no spaces at the start of a line\n" . $herevet);
}
# check for space before tabs.
if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
WARN("please, no space before tabs\n" . $herevet);
}
# check we are in a valid C source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c)$/);
@ -3293,6 +3319,11 @@ sub process {
"storage class should be at the beginning of the declaration\n" . $herecurr)
}
# Check that the storage class is at the beginning of a declaration
if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
WARN("storage class should be at the beginning of the declaration\n" . $herecurr)
}
# check the location of the inline attribute, that it is between
# storage class and type.
if ($line =~ /\b$Type\s+$Inline\b/ ||