Commit graph

269 commits

Author SHA1 Message Date
Matt Wagantall
67d11beed2 checkpatch: Excuse reverts from "summary line over 75 characters" check
Rather than forcing authors of reverts to truncate the summary line
because the "Revert" prefix added pushes it over the character limit,
excuse reverts from this rule.

Change-Id: I395dfff3327e360ef935d4a685c38df6577e3867
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
(cherry picked from commit 3c09aeb415d542b08257021992aadd965fcb3902)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
(cherry picked from commit 952824addcec8487b8c800b0ef18ede547711381)
2013-03-07 15:20:03 -08:00
David Brown
137d1b2b4c checkpatch: strlen and strcmp should not be banned
Software security is an important issue, in general, but it is
especially important in Linux kernel code.  Buffer overflows can have
wide-reaching ramifications and can often be readily exploited to
compromise the entire system.  It is important for every developer to
be aware of security issues while writing code.

However, I've noticed a few "rules" about coding that are resulting in
code that isn't any more secure, and has the disadvantage of obscuring
what the code is doing.  In most instances, the "corrected" code is
actually wrong: we've traded a perceived lack of safety for incorrect
behavior.  These obfuscations also make this code more distant from
upstream kernel standards.

I'm only going to focus here on strcmp/strncmp and strlen/strnlen.  I
choose these two, because in the context of the kernel, it's not easy
to make a general rule, such as "always use the 'n' variant".  These
function have different behavior, and the 'n' isn't just a blanket fix
that makes them better.  In many instances, the correct call is the
plain variant (strcpy has a strlcpy variant which is usually helpful).

Let's start with strlen/strnlen.

	size_t strlen(const char *);
	size_t strnlen(const char *, size_t);

The strlen() function scans for a NUL byte within a string, and
returns the number of characters that had to be skipped to get there.

The strnlen() call is similar, but will stop after after a maximal
number of characters, and return that result.  This variant was
intended for storing variable length strings in fixed-sized buffers,
where the full-length case did not have a trailing NUL.  This storage
model is very uncommon, as is the use of strnlen().

The question becomes, what is the maximal length you should be giving
to strnlen().  If the string is truly variable length (allocated and
filled), there really isn't a meaningful value to use for this.  The
only time that a max length makes sense is when you have something
like:

	char name[MAX_NAME_LENGTH];

but, in this case, strnlen() is still probably not what you want to be
using.  It would be safe to use, if you check the result, and if it is
MAX_NAME_LENGTH, raise some kind of error case.  If later code assumes
there is a NUL at the end, there will still be a buffer overflow.  In
this case, it is much better to check the length before storing it in
this field, and make sure there is room for the NUL.

If the string is a constant, passing in a length doesn't make sense,
since you would have to know the length of the string to check that.
There is no safety issue with calling strlen() on a constant.

So, the simple rule for strnlen()/strlen() is:

  - If the string doesn't have an obvious bound length, such as an
    allocated string, use strlen().

  - If the string is a constant, use strlen().

  - If there is a fixed buffer, strnlen() might make sense, but it is
    probably better to change the design to avoid these types of
    strings.

The only case where strnlen really makes sense is when you have a
string that is passed in from the user.  In this case, it is very
important to check the result, and if the length is at the maximum,
return an error, and don't try to do any processing on the string.

Moving on to strcmp/strncmp.  These functions are similar, except that
they take two string arguments, which gives a lot more combinations.

	int strcmp(const char *, const char *);
	int strncmp(const char *, const char *, size_t);

These will walk both strings (at the same time), and stop when
reaching the first difference between them.  This means that they will
never go further than the length of the shortest string being
compared.  As in strnlen, the max argument to strncmp sets a limit on
the comparison.  Similar to strnlen, the results are unusual when the
limit is reached, but in a sense, even worse, since it may consider
the strings equal without ever reaching the end of either.

Looking over the 200 some uses of strncmp in the msm code, almost all
of them do something akin to:

	strncmp(value, constant, strlen(constant))

If the call has added 1 to the 'strlen' result, the strncmp would just
become an inefficient, but otherwise identical version of strcmp.
However, without the +1, this compares the prefix of 'value' instead
of the entire string.  Only one instance of strncmp in the code
appears to be intentionally checking for a prefix.  The rest have
changed a simple string compare into an unintentional prefix match.

Because there are two strings, it is a little more complex to
determine which to use, but it is very similar.  It might seem that
strncmp() would be useful for checking an unknown buffer (say from
userspace).  However, since strncmp()'s result doesn't distinguish
between finding the end of the string, or hitting the max, there's no
way to know.  Some guidelines:

  - If one of the strings has a known bound length (such as a
    constant, or another string whose length has already been
    checked), AND this bound length is within the expected buffer of
    the other string, it is safe to use strcmp().

  - Otherwise, you may need to use something like strnlen() to
    determine a maximum length before calling strcmp().

  - strncmp() is useful to test a string for a prefix.  No other uses
    make sense.

To facilitate fixing these, remove strlen(), strcmp(), and
strcasecmp() from the list of calls that are banned.  Problems with
these calls need to be caught at a higher level (such as review), and
replacing them with the 'n' variants doesn't help anything.

This will be followed by some patches that fixup the incorrect code
introduced by this "ban".

Change-Id: I77dfe1f2f58e8c951e4b38b23f4ec79f8209b1dc
Signed-off-by: David Brown <davidb@codeaurora.org>
2013-02-27 18:19:30 -08:00
Steve Muckle
b657cc0ec7 checkpatch: add new message type string
Many messsages are missing the new message type parameter, which
causes warning messages and a lack of the line number from the
offending line in the patch.

Change-Id: I69f2283c3dc27edd66fd2676c8be45664699dba6
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
2013-02-27 18:10:43 -08:00
Rohit Vaswani
b45143752d scripts/checkpatch.pl: fixup
Change-Id: I76a7f5fd446a9f40d8294f03d2c355273af59905
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
2013-02-20 02:50:06 -08:00
Olav Haugan
fa79a44270 checkpatch: Check for unsafe string functions
There are many string based functions that are unsafe
to use. Some of the functions are unsafe to use because
of the possibility of overflow while others cannot
guarantee that the resultant string is NULL-terminated.

Add check for these functions and log message indicating
which safe functions can be used instead.

Change-Id: Id305d98df241e3fd257529529739dcd4f3659186
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
(cherry picked from commit 665be0da353f69f85cb1acea19279adf6ccb5b52)
2013-02-20 02:50:05 -08:00
Steve Muckle
097d733966 checkpatch: recognize only specific tags when ending commit text
There are some very frequently used tags that checkpatch can look
for as an ending to the commit text rather than using a pattern,
which can generate false positives in the "no commit text" rule.

Change-Id: I5b4400017b8273bcd9f5a59b3e28965c0062bef4
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
(cherry picked from commit 336a3ae6253031d6a0de11882ac24a11f83d3323)
2013-02-20 02:50:05 -08:00
Steve Muckle
87c8e7d5be checkpatch: require commit text
Commit text is almost always necessary to explain why a change is
needed. Exceptions are rare enough that these can be granted through
manual checkpatch overrides.

Change-Id: I926b2276f717940c2fec77a6709fa3088b1bf0c3
Signed-off-by: Steve Muckle <smuckle@codeaurora.org>
(cherry picked from commit d3b3b64c907dbf2244250fc4b389562f2efedee2)
2013-02-20 02:50:04 -08:00
Pankaj Kumar
3f3f761f9c checkpatch: Add check for vreg_xxx api in opensource drivers
Vreg API implementation is deprecated. We are using
Linux regulator framework now. Hence vreg API should
not be used.

Change-Id: I8e31dac66592d2d195d190b770a436e93206cf8b
Signed-off-by: Pankaj Kumar <pakuma@codeaurora.org>
(cherry picked from commit adfb933a24911e3514a2f1b6fe1b1a9151fec56d)
2013-02-20 02:50:04 -08:00
Rohit Vaswani
26ec0b6b5d checkpatch: Add check for gpiomux usage in msm board files
MSM has a board-*-gpiomux file where all the gpiomux configs reside.
Warn if a non gpiomux board file tries to add gpiomux configs.
The camera board file is an exception to this rule.

Change-Id: Ibab190dcbd7ea78e7ca150142c68c5ae881e4e06
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
(cherry picked from commit 60d78bb9809e7d4d1c3dc1425cbfd9e649e87c1c)
2013-02-20 02:50:03 -08:00
Gregory Bean
d8ac9d4585 checkpatch: repair faulty executable-bit check.
Existing executable-bit test only works on second and later files
contained in the patch.  Correct this so all patches in the file
are tested.

Change-Id: Ie9363473f0d2fc067f9c593c86495d15e8e5d546
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit 246e1f183dd3c2bfe63722ca5b207473cb9a0219)

Conflicts:

	scripts/checkpatch.pl
2013-02-20 02:50:02 -08:00
Gregory Bean
ec9255dbf8 checkpatch: complain about the use of dsb().
Now that mb() does what we want, dsb() should be discouraged.

Change-Id: Ib8fe8f44f669753c3d91fac3c6e598e117d6d90e
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit 9c0619be7b93ad114d6f33a749d905ddff93df7d)
2013-02-20 02:50:02 -08:00
Gregory Bean
136c5a1cd0 checkpatch: close filp_open loophole.
filp_open allows people to get around the ban on sys_open.
Close the loophole.

Change-Id: I6e2be62e848cbc064e07008d0886c0d003c8be4b
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit bb181a18a813a70176f71a0c64aa572fcfbef0f0)
2013-02-20 02:50:01 -08:00
Gregory Bean
4409ccd825 checkpatch: Handle long multi-line macros better.
Improve parsing of multiline macros which run beyond the available
diff context.  These beyond-the-horizon macros previously caused
two distinct naughty behaviors:
  - The scanner, confused by the trailing backslash, would grab
    the header of the next context hunk and treat it as the last
    line of the preceding macro.
  - The analyzer, unable to fully reduce the macro, would blame
    the patch for submitting an unbalanced or unprotected macro.

Change-Id: I6b7dd3d577c524d30b59dff7b20393bb5135f16d
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit ddd028c47b4d91aa9c0e97445eb584b2de367769)
2013-02-20 02:50:01 -08:00
Gregory Bean
3a4c8c77cc checkpatch: deprecate unbounded string functions.
Unbounded string functions are overflow risks.  The 'n'
versions of those functions should be used instead.

Change-Id: Ice0fb3ebdae9aa88cc7e764ffdf68cbed857febf
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit 15e1e97d66dd6a6039c1ec2bd549a632fe361128)
2013-02-20 02:50:00 -08:00
Gregory Bean
55bb2c050a checkpatch: forbid implied-barrier I/O functions.
Forbid read[bwl], write[bwl], in[bwl], and out[bwl], as they
contain a 'stealth barrier' which can harm performance.
Developers are expected to call appropriate __raw_* or *_relaxed
APIs and manage barriers explicitly.

Change-Id: Ie4da221c91a0505917199db9e2fdb704c3e47d44
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit 032fd4ba09e195d9913c08f460130da9905936ef)
2013-02-20 02:49:59 -08:00
Gregory Bean
20a44b003b checkpatch: Merge continuation-header handling from .38.
This commit is a cherry pick and squash of commits:
85c2ee62d37c19456c6dc83db262123956f010ac
4bc7c6001daba7d4037f54f67bae7fa90f759402

  checkpatch: Handle continuation headers.

  Continuation headers baffle checkpatch, as it can only operate
  on one line of context at a time.  When continuation headers are found,
  put them up with the header they're continuing so the whole thing
  can be parsed in a single line of context.

  checkpatch: Don't treat diffs as patches.

  The patch-header cleanup code assumed that it would only ever
  see patches, which was of course hogwash.  This lead to crazy
  results as it tried to wrap what it thought were continuation
  lines at the beginnings of raw diffs.

Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit 57d50ae730a057ee1099a94a397475bfd147d97b)

Conflicts:

	scripts/checkpatch.pl

Change-Id: I60b2d914ada9a8690b89ffb8c1e32a8b81a5e715
2013-02-20 02:49:59 -08:00
Gregory Bean
5bc97df95b checkpatch: forbid filesystem accesses from within the kernel.
Use of the sys_open/close/read/write system calls from within
kernel code is inappropriate, and now triggers errors.

Change-Id: I98e20513c257d0664684b7144585853f617d771a
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit ee62f2afcac1bcb180b2f0dddf2c8f5cda54bc5b)
2013-02-20 02:49:58 -08:00
David Brown
d0d4b63246 Revert "checkpatch: reject unrelaxed readl/writel."
This reverts commit 66b2a3733e7219e5291c633eb5778bec6500b74d.

Possibly can happen after necessary code changes are in place.

Change-Id: I04e092158dda2b5f5ca029378d1e7dc863de6001
Signed-off-by: David Brown <davidb@codeaurora.org>
(cherry picked from commit 4235f0aeb789321b36eb01f29ffb329fc9d2169c)
2013-02-20 02:49:57 -08:00
Gregory Bean
31fbea03d9 checkpatch: reject unrelaxed readl/writel.
Change-Id: I9490245ba24df51f1b4a69e2bb46b27da13a333a
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit 66b2a3733e7219e5291c633eb5778bec6500b74d)
2013-02-20 02:49:57 -08:00
Gregory Bean
b4bea2d7a9 Don't complain about MIME headers.
When patches contain extended character sets, patches will contain
MIME headers after the subject line, which should not be confused
for a too-long summary line.

Signed-off-by: Gregory Bean <gbean@codeaurora.org>
Change-Id: If17d17cc7513eb644d75f486b9cdea3a09ba0dbe
(cherry picked from commit 8e6b9d3790595198a34320f1c3f4504cd258fed1)
2013-02-20 02:49:56 -08:00
Bryan Huntsman
fa3e178ef5 Revert "checkpatch: add check for too short Kconfig descriptions"
This reverts commit 3354957a4f.

Signed-off-by: Bryan Huntsman <bryanh@codeaurora.org>
(cherry picked from commit 6839bfe7291e24589884af37de8622ff2bea31e6)
2013-02-20 02:49:56 -08:00
Matt Wagantall
cc32440107 checkpatch: Import additional rules from android-msm-2.6.32 to msm-2.6.35
Several checkpatch enhancements are imported from android-msm-2.6.32.
These include:

commit 83ec26e869ac7e967fd5382f9e1979536897d42a
Author: Matt Wagantall <mattw@codeaurora.org>
Date:   Thu Jun 3 12:28:18 2010 -0700

    checkpatch: Exceptions for CLK_* macros and some spaces in macros

    Add CLK_* macros used in MSM clock drivers to the list of exceptions
    for the "Macros with complex values should be enclosed in parenthesis"
    test.

    Also, allow spaces following open branckets for macros where the
    macro is the first token on the line, the space preceds a decimal
    number, and the line ends with ")," or ")". Such arrangements can
    be useful for aligning numerical columns of tables when the rows
    are described by macros.

    Change-Id: I7701119ada2ea8fd646e5448eae51786bbf1e8fa
    Signed-off-by: Matt Wagantall <mattw@codeaurora.org>

commit d3ccf20187826d2cfbf41eda3f9e1a38e35b79bf
Author: Rick Adams <rgadams@codeaurora.org>
Date:   Mon Jan 4 13:06:09 2010 -0800

    checkpatch: warn on subject line not followed by blank line

    Fixed case when no warning generated for long subject line that is
    wrapped to more than one line, and all lines are less than line limit.

    New warning message added:
    "non-blank line after summary line"
    Now there are two warnings possible for the subject line, the original
    line over limit and the new one. Depending on the error(s) any
    combination of the two warnings are possible.

    Commit text requirements now:
    1) Must be less than 75 characters
    2) Must be followed by blank line.

    Change-Id: If7ee833339c5be947bb1dd2a52d5d1d9ddfe5de6
    Signed-off-by: Rick Adams <rgadams@codeaurora.org>

commit ae617dec94111b127c33ae9c979e51b5bd8b5292
Author: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Date:   Thu Oct 1 12:01:44 2009 -0700

    checkpatch: check for #if 0/#if 1

    Warn if #if 1 or #if 0 is present.

    Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

commit 168e8da627f99e421be9375ed572df6b1039854f
Author: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Date:   Thu Oct 1 12:01:44 2009 -0700

    checkpatch: check for execute permissions on non code files

    Make checkpatch.pl check execute permissions on non code files

    Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>

commit be24800e1cdd44d8b0e00f212c022f34e1402eb4
Author: Steve Muckle <smuckle@codeaurora.org>
Date:   Fri Apr 3 16:19:20 2009 -0700

    checkpatch: check new files for executable permissions

    Look for executable permissions on new files as well as in mode
    changes on existing files.

    Signed-off-by: Steve Muckle <smuckle@codeaurora.org>

commit b45a236b62928e0b11fbeff1471d9b1efc508884
Author: Steve Muckle <smuckle@codeaurora.org>
Date:   Fri Mar 13 15:46:36 2009 -0700

    checkpatch: warn on long summary, commit text lines

    Warn on summary or commit text lines greater than 75 characters.
    The summary and commit text are indented and may wrap on a terminal
    if they are longer than 75 characters.

    Signed-off-by: Steve Muckle <smuckle@codeaurora.org>

Change-Id: Iae92cdc8ffecc5315761bc91e883d8ea2f4877cc
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
(cherry picked from commit d17f580ee07441770498b54159e3322f8186fc3e)

Conflicts:

	scripts/checkpatch.pl
2013-02-20 02:49:55 -08:00
Patrick Pannuto
d917e71c27 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
2013-02-20 02:49:54 -08:00
Patrick Pannuto
e388f38442 Checkpatch: Print location when catching return code error
Display context so users can see where there error was

OLD:
	ERROR: illegal return value, please use an error code

NEW:
	ERROR: illegal return value, please use an error code
	#152: test.c:5:
	+	return -1;

Change-Id: I098004d9a5dbeb6c39b35b84ac94fd7a861849d7
Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
(cherry picked from commit 8d09803de5d629f3ebc9cb357a40b5937a5d171e)
2013-02-20 02:49:54 -08:00
Gregory Bean
45da08a85b Revert "checkpatch: Add warning for blank lines in header"
This reverts commit 8212698c653945d0fd0783829822917bf13a5aab.
The original commit incorrectly prevents the following:
  - Commit messages which cite other commit messages, which
    are commonly used for attribution;
  - Any use of checkpatch which doesn't contain a full mail header,
    such as 'show <ref> | checkpatch.pl -'

Change-Id: I681a97913432d05bf66290cf74972aaa4e03fe5d
Signed-off-by: Gregory Bean <gbean@codeaurora.org>
(cherry picked from commit c73e32b4a1a59e3a33e9c8975ab08b5475d30f3e)
2013-02-20 02:49:53 -08:00
Patrick Pannuto
dc4e47c544 checkpatch: Check for illegal return codes
The only legal integer return is 0, anything else
following "return" should be -ERRCODE or a function.

http://lkml.org/lkml/2010/7/23/318
  There's lots of "return -1;" statements in this patch - it's obscene
  that this is used to indicate "some error occurred" in kernel space
  rather than a real errno value - even when an existing function
  (eg, request_irq) gave you an error code already.

  Please note this for the future - and please review patches on this
  point internally first.

Change-Id: I16268b2ee034f0b3b899115e45c28acfa734ddec
Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
(cherry picked from commit 39531a47164294315b5a7256b520fe22d6e87013)
2013-02-20 02:49:53 -08:00
Israel Schlesinger
4be1c09bc3 checkpatch: remove column limit for checkpatch patches
Currently checkpatch is enforcing an 80 character column
limit. This should not be applied for patches modifying
checkpatch.

Change-Id: I8e8935e633d79a7ee535ce6a90e54447a22d9a91
Signed-off-by: Israel Schlesinger <israels@codeaurora.org>
(cherry picked from commit 4aa1b864119e2d0e49efefcd6dba7349f13c3939)

Conflicts:

	scripts/checkpatch.pl
2013-02-20 02:49:52 -08:00
Israel Schlesinger
7ee453e97d checkpatch: fix regex for catching mdelay()
upstream prefers this change for checkpatch:
http://lkml.org/lkml/2010/7/27/254

Signed-off-by: Israel Schlesinger <israels@codeaurora.org>
Change-Id: I61f8c1ff622994b37a79fed4b811115da2c108ad
(cherry picked from commit 76cc4ad08fe1d8912ce44ee2cc1f10373c2974d3)
2013-02-20 02:49:51 -08:00
Israel Schlesinger
864c6a2685 checkpatch: Add warning for blank lines in header
Signed-off-by: Israel Schlesinger <israels@codeaurora.org>
Change-Id: Ie0da3c2842b3d1f194f60c277ae9961dcb82cd59
(cherry picked from commit 8212698c653945d0fd0783829822917bf13a5aab)
2013-02-20 02:49:51 -08:00
Israel Schlesinger
eb3ce1b125 checkpatch: Add warnings for use of mdelay()
Signed-off-by: Israel Schlesinger <israels@codeaurora.org>
Change-Id: I9e5510a79d51b8f03e03ad8466246f93bf2c623a
(cherry picked from commit 084af58596758be6e51ef060aefa2cd622dc9205)
2013-02-20 02:49:50 -08:00
Israel Schlesinger
b9fd44f1a5 checkpatch: Add warning for qualcomm email
People should not be using their qualcomm email
when signing off patches or authoring them.

Signed-off-by: Israel Schlesinger <israels@codeaurora.org>
Change-Id: Ic09516564a6b60576d6fac95e3ce4ccc8c706b0d
(cherry picked from commit bde480639313a5de6c2019a93d96767fecceaa78)
2013-02-20 02:49:50 -08:00
Matt Wagantall
2a9af98acd checkpatch: Exceptions for CLK_* macros and some spaces in macros
Add CLK_* macros used in MSM clock drivers to the list of exceptions
for the "Macros with complex values should be enclosed in parenthesis"
test.

Also, allow spaces following open branckets for macros where the
macro is the first token on the line, the space preceds a decimal
number, and the line ends with ")," or ")". Such arrangements can
be useful for aligning numerical columns of tables when the rows
are described by macros.

Change-Id: I7701119ada2ea8fd646e5448eae51786bbf1e8fa
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
(cherry picked from commit ed6d6ed1c6b8f6016ea5676d075331e31b7ac1f8)

Conflicts:

	scripts/checkpatch.pl
2013-02-20 02:49:49 -08:00
Bryan Huntsman
7324a38d16 scripts/checkpatch.pl: warn on invalid credentials
@quicinc.com identities are not allowed.  Check the "From:" field in the
patch, equivalent to the author in the git commit, and the Signed-off-by
field.

Signed-off-by: Bryan Huntsman <bryanh@codeaurora.org>
(cherry picked from commit 374146d3656f815f45145861396df4ee35f60cec)
2013-02-20 02:49:48 -08:00
Richard Adams
5bdba0fdc2 checkpatch: warn on subject line not followed by blank line
Fixed case when no warning generated for long subject line that is
wrapped to more than one line, and all lines are less than line limit.

New warning message added:
"non-blank line after summary line"
Now there are two warnings possible for the subject line, the original
line over limit and the new one. Depending on the error(s) any
combination of the two warnings are possible.

Commit text requirements now:
1) Must be less than 75 characters
2) Must be followed by blank line.

Change-Id: If7ee833339c5be947bb1dd2a52d5d1d9ddfe5de6
Signed-off-by: Richard Adams <c_adams@quicinc.com>
(cherry picked from commit 78d0db4aa1212e00696e25b7daa9fc4ecd86f954)

Conflicts:

	scripts/checkpatch.pl
2013-02-20 02:49:48 -08:00
Abhijeet Dharmapurikar
cd04021bce checkpatch: check for #if 0/#if 1
Warn if #if 1 or #if 0 is present.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit a81f92c9abe442ad5b00e8df31172f145a14af3f)

Conflicts:

	scripts/checkpatch.pl

Change-Id: Id28c07eaa907351933e0450751b05e2f749d23d0
2013-02-20 02:49:47 -08:00
Abhijeet Dharmapurikar
eeec9b59b5 checkpatch: check for execute permissions on non code files
Make checkpatch.pl check execute permissions on non code files

Signed-off-by: Abhijeet Dharmapurikar <adharmap@quicinc.com>
(cherry picked from commit 315e124e887131124d184f1bf0778ebbb80282fb)
2013-02-20 02:49:47 -08:00
Steve Muckle
1cf404d212 checkpatch: check new files for executable permissions
Look for executable permissions on new files as well as in mode
changes on existing files.

Signed-off-by: Steve Muckle <smuckle@quicinc.com>
(cherry picked from commit 1ec31f0a5471d173b4d2eecb29f3526d77e7cc60)
2013-02-20 02:49:46 -08:00
Steve Muckle
7dab411f3d checkpatch: warn on long summary, commit text lines
Warn on summary or commit text lines greater than 75 characters.
The summary and commit text are indented and may wrap on a terminal
if they are longer than 75 characters.

Signed-off-by: Steve Muckle <smuckle@quicinc.com>
(cherry picked from commit e2638df6005402597085a58e01b6dd1cf2bdb8a4)

Conflicts:

	scripts/checkpatch.pl

Change-Id: I1546ba3b81031051fdbe6319842d6e2d96931416
2013-02-20 02:49:46 -08:00
Joe Perches
c06a9ebdb7 checkpatch: revert --strict test for net/ and drivers/net block comment style
Revert the --strict test for the old preferred block
comment style in drivers/net and net/

Reported-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-04-16 12:44:38 -07:00
Josh Triplett
ca56dc098c checkpatch: check for quoted strings broken across lines
checkpatch already makes an exception to the 80-column rule for quoted
strings, and Documentation/CodingStyle recommends not splitting quoted
strings across lines, because it breaks the ability to grep for the
string.  Rather than just permitting this, actively warn about quoted
strings split across lines.

Test case:

void context(void)
{
	struct { unsigned magic; const char *strdata; } foo[] = {
		{ 42, "these strings"
		      "do not produce warnings" },
		{ 256, "though perhaps"
		       "they should" },
	};
	pr_err("this string"
	       " should produce a warning\n");
	pr_err("this multi-line string\n"
	       "should not produce a warning\n");
	asm ("this asm\n\t"
	     "should not produce a warning");
}

Results of checkpatch on that test case:

WARNING: quoted string split across lines
+	       " should produce a warning\n");

total: 0 errors, 1 warnings, 15 lines checked

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Acked-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>
2012-03-23 16:58:37 -07:00
Joe Perches
6712d85852 checkpatch: whitespace - add/remove blank lines
Add blank lines between a few tests, remove an extraneous one.

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>
2012-03-23 16:58:37 -07:00
Joe Perches
2c92488ab2 checkpatch: warn on use of yield()
Using yield() is generally wrong.  Warn on its use.

Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23 16:58:37 -07:00
Joe Perches
aad4f61498 checkpatch: add --strict tests for braces, comments and casts
Add some more subjective --strict tests.

Add a test for block comments that start with a blank line followed only
by a line with just the comment block initiator.  Prefer a blank line
followed by /* comment...

Add a test for unnecessary spaces after a cast.

Add a test for symmetric uses of braces in if/else blocks.
If one branch needs braces, then all branches should use braces.

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>
2012-03-23 16:58:37 -07:00
Andy Whitcroft
b337d8b82f checkpatch: add [] to type extensions
Add [] to a type extensions.  Fixes false positives on:

    .attrs = (struct attribute *[]) {

Signed-off-by: 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>
2012-03-23 16:58:36 -07:00
Andy Whitcroft
fd1b57ac73 checkpatch: high precedence operators do not require additional parentheses in #defines
With any very high precedence operator it is not necessary to enforce
additional parentheses around simple negated expressions.  This prevents
us requesting further perentheses around the following:

    #define PMEM_IS_FREE(id, index) !(pmem[id].bitmap[index].allocated)

For now add logical and bitwise not and unary minus.

Signed-off-by: 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>
2012-03-23 16:58:36 -07:00
Andy Whitcroft
e45bab8ebf checkpatch: handle string concatenation in simple #defines
Adjacent strings indicate concatentation, therefore look at identifiers
directly adjacent to literal strings as strings too.  This allows us to
better detect the form below and accept it as a simple constant:

    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

Signed-off-by: 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>
2012-03-23 16:58:36 -07:00
Andy Whitcroft
b9df76ac76 checkpatch: allow simple character constants in #defines
Signed-off-by: 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>
2012-03-23 16:58:36 -07:00
Andy Whitcroft
daebc534ac checkpatch: catch [ ... ] usage when not at the beginning of definition
Handle the [ A ... B ] form deeper into a definition, for example:

    static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
	    {0, 0, 0, 0, 0, 0, 0, 27, 27, [9 ... PCI_MAX_DEVICES - 1] = 0 },
	    {0, 0, 0, 0, 0, 0, 0, 29, 29, [9 ... PCI_MAX_DEVICES - 1] = 0 },
    };

Reported-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: 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>
2012-03-23 16:58:36 -07:00
Artem Bityutskiy
11232688ec checkpatch.pl: be silent when -q and --ignore is given
Fix checkpatch.pl when both -q and --ignore are given and prevents it from
printing a

NOTE: Ignored message types: blah

messages.

E.g., if I use -q --ignore PREFER_PACKED,PREFER_ALIGNED, i see:

NOTE: Ignored message types: PREFER_ALIGNED PREFER_PACKED

It makes no sense to print this when -q is given.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.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>
2012-03-23 16:58:36 -07:00
Joe Perches
d1fe9c099c checkpatch: add some --strict coding style checks
Argument alignment across multiple lines should match the open
parenthesis.

Logical continuations should be at the end of the previous line, not the
start of a new line.

These are not required by CodingStyle so make the tests active only when
using --strict.

Improved by some examples from Bruce Allen.

Signed-off-by: Joe Perches <joe@perches.com>
Cc: "Bruce W. Allen" <bruce.w.allan@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-03-23 16:58:36 -07:00