Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
checkpatch: don't require kernel style __attribute__ shortcuts in uap…
Browse files Browse the repository at this point in the history
…i paths

Avoid prescribing kernel styled shortcuts for gcc extensions of
__attribute__((foo)) in the uapi include paths.

Fix $realfile filename when using -f/--file to not remove first level
directory as if the filename was used in a -P1 patch.  Only strip the
first level directory (typically a or b) for P1 patches.

Signed-off-by: Joe Perches <joe@perches.com>
Cc: "Dixit, Ashutosh" <ashutosh.dixit@intel.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: 2b7ab45
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
  • Loading branch information
JoePerches authored and Stepan Moskovchenko committed Oct 10, 2014
1 parent 7b87814 commit 58aa5a9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1769,11 +1769,11 @@ sub process {
# extract the filename as it passes
if ($line =~ /^diff --git.*?(\S+)$/) {
$realfile = $1;
$realfile =~ s@^([^/]*)/@@;
$realfile =~ s@^([^/]*)/@@ if (!$file);
$in_commit_log = 0;
} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
$realfile = $1;
$realfile =~ s@^([^/]*)/@@;
$realfile =~ s@^([^/]*)/@@ if (!$file);
$in_commit_log = 0;

$p1_prefix = $1;
Expand Down Expand Up @@ -3877,7 +3877,8 @@ sub process {
}

# Check for __inline__ and __inline, prefer inline
if ($line =~ /\b(__inline__|__inline)\b/) {
if ($realfile !~ m@\binclude/uapi/@ &&
$line =~ /\b(__inline__|__inline)\b/) {
if (WARN("INLINE",
"plain inline is preferred over $1\n" . $herecurr) &&
$fix) {
Expand All @@ -3887,19 +3888,22 @@ sub process {
}

# Check for __attribute__ packed, prefer __packed
if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
if ($realfile !~ m@\binclude/uapi/@ &&
$line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
WARN("PREFER_PACKED",
"__packed is preferred over __attribute__((packed))\n" . $herecurr);
}

# Check for __attribute__ aligned, prefer __aligned
if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
if ($realfile !~ m@\binclude/uapi/@ &&
$line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
WARN("PREFER_ALIGNED",
"__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
}

# Check for __attribute__ format(printf, prefer __printf
if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
if ($realfile !~ m@\binclude/uapi/@ &&
$line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
if (WARN("PREFER_PRINTF",
"__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
$fix) {
Expand All @@ -3909,7 +3913,8 @@ sub process {
}

# Check for __attribute__ format(scanf, prefer __scanf
if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
if ($realfile !~ m@\binclude/uapi/@ &&
$line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
if (WARN("PREFER_SCANF",
"__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
$fix) {
Expand Down

0 comments on commit 58aa5a9

Please sign in to comment.