From a3b81113fb6658629f4ebaabf8dd3067cd341020 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Wed, 6 Feb 2008 01:36:26 -0800 Subject: remove support for un-needed _extratext section When passing a zero address to kallsyms_lookup(), the kernel thought it was a valid kernel address, even if it is not. This is because is_ksym_addr() called is_kernel_extratext() and checked against labels that don't exist on many archs (which default as zero). Since PPC was the only kernel which defines _extra_text, (in 2005), and no longer needs it, this patch removes _extra_text support. For some history (provided by Jon): http://ozlabs.org/pipermail/linuxppc-dev/2005-September/019734.html http://ozlabs.org/pipermail/linuxppc-dev/2005-September/019736.html http://ozlabs.org/pipermail/linuxppc-dev/2005-September/019751.html [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Robin Getz Cc: David Woodhouse Cc: Jon Loeliger Cc: Paul Mackerras Cc: Benjamin Herrenschmidt Cc: Sam Ravnborg Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/kallsyms.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 1f11d848532a..8fb87003d5d3 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -41,7 +41,7 @@ struct sym_entry { static struct sym_entry *table; static unsigned int table_size, table_cnt; -static unsigned long long _text, _stext, _etext, _sinittext, _einittext, _sextratext, _eextratext; +static unsigned long long _text, _stext, _etext, _sinittext, _einittext; static int all_symbols = 0; static char symbol_prefix_char = '\0'; @@ -99,10 +99,6 @@ static int read_symbol(FILE *in, struct sym_entry *s) _sinittext = s->addr; else if (strcmp(sym, "_einittext") == 0) _einittext = s->addr; - else if (strcmp(sym, "_sextratext") == 0) - _sextratext = s->addr; - else if (strcmp(sym, "_eextratext") == 0) - _eextratext = s->addr; else if (toupper(stype) == 'A') { /* Keep these useful absolute symbols */ @@ -165,18 +161,18 @@ static int symbol_valid(struct sym_entry *s) * and inittext sections are discarded */ if (!all_symbols) { if ((s->addr < _stext || s->addr > _etext) - && (s->addr < _sinittext || s->addr > _einittext) - && (s->addr < _sextratext || s->addr > _eextratext)) + && (s->addr < _sinittext || s->addr > _einittext)) return 0; /* Corner case. Discard any symbols with the same value as - * _etext _einittext or _eextratext; they can move between pass - * 1 and 2 when the kallsyms data are added. If these symbols - * move then they may get dropped in pass 2, which breaks the - * kallsyms rules. + * _etext _einittext; they can move between pass 1 and 2 when + * the kallsyms data are added. If these symbols move then + * they may get dropped in pass 2, which breaks the kallsyms + * rules. */ - if ((s->addr == _etext && strcmp((char*)s->sym + offset, "_etext")) || - (s->addr == _einittext && strcmp((char*)s->sym + offset, "_einittext")) || - (s->addr == _eextratext && strcmp((char*)s->sym + offset, "_eextratext"))) + if ((s->addr == _etext && + strcmp((char *)s->sym + offset, "_etext")) || + (s->addr == _einittext && + strcmp((char *)s->sym + offset, "_einittext"))) return 0; } -- cgit v1.2.3 From f2df3f65d0b4337cfb5b19eab3ee28b177427c49 Mon Sep 17 00:00:00 2001 From: Paulo Marques Date: Wed, 6 Feb 2008 01:37:33 -0800 Subject: kallsyms should prefer non weak symbols When resolving symbol names from addresses with aliased symbol names, kallsyms_lookup always returns the first symbol, even if it is a weak symbol. This patch changes this by sorting the symbols with the weak symbols last before feeding them to the kernel. This way the kernel runtime isn't changed at all, only the kallsyms build system is changed. Another side effect is that the symbols get sorted by address, too. So, even if future binutils version have some bug in "nm" that makes it fail to correctly sort symbols by address, the kernel won't be affected by this. Mathieu says: I created a module in LTTng that uses kallsyms to get the symbol corresponding to a specific system call address. Unfortunately, all the unimplemented syscalls were all referring to the (same) weak symbol identifying an unrelated system call rather that sys_ni (or whatever non-weak symbol would be expected). Kallsyms was dumbly returning the first symbol that matched. This patch makes sure kallsyms returns the non-weak symbol when there is one, which seems to be the expected result. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Mathieu Desnoyers Looks-great-to: Rusty Russell Cc: Sam Ravnborg Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/kallsyms.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 8fb87003d5d3..c912137f80e2 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -31,14 +31,13 @@ #define KSYM_NAME_LEN 128 - struct sym_entry { unsigned long long addr; unsigned int len; + unsigned int start_pos; unsigned char *sym; }; - static struct sym_entry *table; static unsigned int table_size, table_cnt; static unsigned long long _text, _stext, _etext, _sinittext, _einittext; @@ -198,8 +197,10 @@ static void read_map(FILE *in) exit (1); } } - if (read_symbol(in, &table[table_cnt]) == 0) + if (read_symbol(in, &table[table_cnt]) == 0) { + table[table_cnt].start_pos = table_cnt; table_cnt++; + } } } @@ -502,6 +503,35 @@ static void optimize_token_table(void) optimize_result(); } +static int compare_symbols(const void *a, const void *b) +{ + const struct sym_entry *sa; + const struct sym_entry *sb; + int wa, wb; + + sa = a; + sb = b; + + /* sort by address first */ + if (sa->addr > sb->addr) + return 1; + if (sa->addr < sb->addr) + return -1; + + /* sort by "weakness" type */ + wa = (sa->sym[0] == 'w') || (sa->sym[0] == 'W'); + wb = (sb->sym[0] == 'w') || (sb->sym[0] == 'W'); + if (wa != wb) + return wa - wb; + + /* sort by initial order, so that other symbols are left undisturbed */ + return sa->start_pos - sb->start_pos; +} + +static void sort_symbols(void) +{ + qsort(table, table_cnt, sizeof(struct sym_entry), compare_symbols); +} int main(int argc, char **argv) { @@ -523,6 +553,7 @@ int main(int argc, char **argv) usage(); read_map(stdin); + sort_symbols(); optimize_token_table(); write_src(); -- cgit v1.2.3 From 2b54aaef7a3a77f208bc14f576010da4fb8dfe29 Mon Sep 17 00:00:00 2001 From: Joern Engel Date: Wed, 6 Feb 2008 01:38:02 -0800 Subject: Claim maintainership for block2mtd and update email addresses I have been prime author and maintainer of block2mtd from day one, but neither MAINTAINERS nor the module source makes this fact clear. And while I'm at it, update my email addresses tree-wide, as the old address currently bounces and change my name to "joern" as unicode will likely continue to cause trouble until the end of this century. Signed-off-by: Joern Engel Cc: David Woodhouse Cc: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- MAINTAINERS | 10 ++++++++-- drivers/mtd/devices/block2mtd.c | 4 ++-- drivers/mtd/devices/phram.c | 4 ++-- drivers/mtd/maps/mtx-1_flash.c | 2 +- scripts/checkstack.pl | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/MAINTAINERS b/MAINTAINERS index eacd304ce58b..c5325d2bb86d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -840,6 +840,12 @@ L: linux-kernel@vger.kernel.org T: git kernel.org:/pub/scm/linux/kernel/git/axboe/linux-2.6-block.git S: Maintained +BLOCK2MTD DRIVER +P: Joern Engel +M: joern@lazybastard.org +L: linux-mtd@lists.infradead.org +S: Maintained + BLUETOOTH SUBSYSTEM P: Marcel Holtmann M: marcel@holtmann.org @@ -3030,8 +3036,8 @@ L: linux-abi-devel@lists.sourceforge.net S: Maintained PHRAM MTD DRIVER -P: Jörn Engel -M: joern@wh.fh-wedel.de +P: Joern Engel +M: joern@lazybastard.org L: linux-mtd@lists.infradead.org S: Maintained diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index be4b9948c762..eeaaa9dce6ef 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -4,7 +4,7 @@ * block2mtd.c - create an mtd from a block device * * Copyright (C) 2001,2002 Simon Evans - * Copyright (C) 2004-2006 Jörn Engel + * Copyright (C) 2004-2006 Joern Engel * * Licence: GPL */ @@ -485,5 +485,5 @@ module_init(block2mtd_init); module_exit(block2mtd_exit); MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Simon Evans and others"); +MODULE_AUTHOR("Joern Engel "); MODULE_DESCRIPTION("Emulate an MTD using a block device"); diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index 56cc1ca7ffd5..180298b92a7a 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -2,7 +2,7 @@ * $Id: phram.c,v 1.16 2005/11/07 11:14:25 gleixner Exp $ * * Copyright (c) ???? Jochen Schäuble - * Copyright (c) 2003-2004 Jörn Engel + * Copyright (c) 2003-2004 Joern Engel * * Usage: * @@ -299,5 +299,5 @@ module_init(init_phram); module_exit(cleanup_phram); MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Jörn Engel "); +MODULE_AUTHOR("Joern Engel "); MODULE_DESCRIPTION("MTD driver for physical RAM"); diff --git a/drivers/mtd/maps/mtx-1_flash.c b/drivers/mtd/maps/mtx-1_flash.c index d884f2be28f6..2a8fde9b92f0 100644 --- a/drivers/mtd/maps/mtx-1_flash.c +++ b/drivers/mtd/maps/mtx-1_flash.c @@ -4,7 +4,7 @@ * $Id: mtx-1_flash.c,v 1.2 2005/11/07 11:14:27 gleixner Exp $ * * (C) 2005 Bruno Randolf - * (C) 2005 Jörn Engel + * (C) 2005 Joern Engel * */ diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl index d716b76098bb..340ad6920511 100755 --- a/scripts/checkstack.pl +++ b/scripts/checkstack.pl @@ -2,7 +2,7 @@ # Check the stack usage of functions # -# Copyright Joern Engel +# Copyright Joern Engel # Inspired by Linus Torvalds # Original idea maybe from Keith Owens # s390 port and big speedup by Arnd Bergmann -- cgit v1.2.3 From 94b3e03c875f25c19ede9600c66d74a30b81957d Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 7 Feb 2008 00:13:26 -0800 Subject: kernel-doc: fix for vunmap function prototype Fix kernel-doc function prototype parsing which was exposed by vunmap() by allowing more than one '*' before the function name. Error(linux-2.6.24-mm1//mm/vmalloc.c:438): cannot understand prototype: 'struct page **vunmap(const void *addr) ' Signed-off-by: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/kernel-doc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kernel-doc b/scripts/kernel-doc index ec54f12f57b0..1c1d350b4901 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -1654,7 +1654,7 @@ sub dump_function($$) { $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || - $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || -- cgit v1.2.3 From 792aa2f2cc4924024e28c9ddf1456434992f9c41 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 7 Feb 2008 00:13:41 -0800 Subject: kernel-doc: prevent duplicate description: output Prevent duplicate output of a Description: section when there is a "blank" ("*") line between the initial function name/description line and the "Description:" header. Test case: drivers/scsi/scsi_devinfo.c::scsi_init_devinfo(). Rob Landley hit this while he was producing SCSI kernel-doc. Signed-off-by: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/kernel-doc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 1c1d350b4901..7df099e6d1fd 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -1907,7 +1907,7 @@ sub process_file($) { $newsection = $1; $newcontents = $2; - if ($contents ne "") { + if (($contents ne "") && ($contents ne "\n")) { if (!$in_doc_sect && $verbose) { print STDERR "Warning(${file}:$.): contents before sections\n"; ++$warnings; -- cgit v1.2.3 From 77cc23b8c7f2f5ea0270bf4be31438aa38316e16 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Thu, 7 Feb 2008 00:13:42 -0800 Subject: kernel-doc: warn on badly formatted short description Make kernel-doc warn when a function/struct/union/typedef does not contain a properly formatted short description, such as: * scsi_devinfo: set up the dynamic device list or * scsi_devinfo - This warning is only generated when verbose (-v) mode is used. Also explain the -v command line option in the -h output. Signed-off-by: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/kernel-doc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts') diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 7df099e6d1fd..6c18a14386a4 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -218,6 +218,7 @@ sub usage { print " [ -function funcname [ -function funcname ...] ]\n"; print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; print " c source file(s) > outputfile\n"; + print " -v : verbose output, more warnings & other info listed\n"; exit 1; } @@ -1881,6 +1882,13 @@ sub process_file($) { } else { $declaration_purpose = ""; } + + if (($declaration_purpose eq "") && $verbose) { + print STDERR "Warning(${file}:$.): missing initial short description on line:\n"; + print STDERR $_; + ++$warnings; + } + if ($identifier =~ m/^struct/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union/) { -- cgit v1.2.3 From c2fdda0dfbe85ad5d68d4799ff7c5af89db8ac19 Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Fri, 8 Feb 2008 04:20:54 -0800 Subject: update checkpatch.pl to version 0.13 This version brings a large number of fixes which have built up over the Christmas period. Mostly these are fixes for false positives, both through improvments to unary checks and possible type detection. It also brings new checks for while location and CVS keywords. Of note: - a number of fixes to unary detection - detection of a number of new forms of types to improve type matching - better inline handling - recognision of '%' as an operator Andy Whitcroft (28): Version: 0.13 unary detection: maintain bracket state across lines move to pre-sanitising the entire file the text of a #error statement should be treated like it is in quotes line sanitisation needs to target double backslash correctly tighten comment guestimation for lines starting ' * ' debug: add a debug framework prevent unclosed single quotes from spreading add % as an operator the text of a #warning statement should be treated like it is in quotes possible matching applies in typedefs single statement block checks must not trigger when two or more statements possible types: local variables may also be const treat inline as a type attribute to even when out of place possible types: sparse annotations are valid indicators possible types: beef up the possible type testing check for hanging while statements on the wrong line utf8 checks need to occur against the raw lines function brace checks should use any whitespece matches comments should take up space in the line when sanitised remove debugging from if assignment checks possible types -- ensure we detect all pointer casts fix tests for function spacing in the presence of #define clean up the UTF-8 error message to be clearer test-lib: invert the status report, output success counts detect and report CVS keywords tests: break out tests Add $Id$ to the CVS keyword checks Benny Halevy (1): checkpatch.pl: recognize the #elif preprocessor directive Geert Uytterhoeven (1): print the filenames of patches where available Mauro Carvalho Chehab (1): Fix missing \n in checkpatch.pl Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 294 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 198 insertions(+), 96 deletions(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 579f50fa838c..545471a99eea 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -9,7 +9,7 @@ use strict; my $P = $0; $P =~ s@.*/@@g; -my $V = '0.12'; +my $V = '0.13'; use Getopt::Long qw(:config no_auto_abbrev); @@ -25,6 +25,7 @@ my $check = 0; my $summary = 1; my $mailback = 0; my $root; +my %debug; GetOptions( 'q|quiet+' => \$quiet, 'tree!' => \$tree, @@ -39,6 +40,7 @@ GetOptions( 'root=s' => \$root, 'summary!' => \$summary, 'mailback!' => \$mailback, + 'debug=s' => \%debug, ) or exit; my $exit = 0; @@ -56,6 +58,12 @@ if ($#ARGV < 0) { exit(1); } +my $dbg_values = 0; +my $dbg_possible = 0; +for my $key (keys %debug) { + eval "\${dbg_$key} = '$debug{$key}';" +} + if ($terse) { $emacs = 1; $quiet++; @@ -110,7 +118,7 @@ our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; our $Operators = qr{ <=|>=|==|!=| =>|->|<<|>>|<|>|!|~| - &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/ + &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% }x; our $NonptrType; @@ -152,7 +160,7 @@ sub build_types { $Type = qr{ \b$NonptrType\b (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? - (?:\s+$Sparse|\s+$Attribute)* + (?:\s+$Inline|\s+$Sparse|\s+$Attribute)* }x; $Declare = qr{(?:$Storage\s+)?$Type}; } @@ -181,6 +189,8 @@ if ($tree && -f "$root/$removal") { } my @rawlines = (); +my @lines = (); +my $vname; for my $filename (@ARGV) { if ($file) { open(FILE, "diff -u /dev/null $filename|") || @@ -189,12 +199,17 @@ for my $filename (@ARGV) { open(FILE, "<$filename") || die "$P: $filename: open failed - $!\n"; } + if ($filename eq '-') { + $vname = 'Your patch'; + } else { + $vname = $filename; + } while () { chomp; push(@rawlines, $_); } close(FILE); - if (!process($filename, @rawlines)) { + if (!process($filename)) { $exit = 1; } @rawlines = (); @@ -274,20 +289,30 @@ sub sanitise_line { my $l = ''; my $quote = ''; + my $qlen = 0; foreach my $c (split(//, $line)) { + # The second backslash of a pair is not a "quote". + if ($l eq "\\" && $c eq "\\") { + $c = 'X'; + } if ($l ne "\\" && ($c eq "'" || $c eq '"')) { if ($quote eq '') { $quote = $c; $res .= $c; $l = $c; + $qlen = 0; next; } elsif ($quote eq $c) { $quote = ''; } } + if ($quote eq "'" && $qlen > 1) { + $quote = ''; + } if ($quote && $c ne "\t") { $res .= "X"; + $qlen++; } else { $res .= $c; } @@ -295,6 +320,28 @@ sub sanitise_line { $l = $c; } + # Clear out the comments. + while ($res =~ m@(/\*.*?\*/)@) { + substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]); + } + if ($res =~ m@(/\*.*)@) { + substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]); + } + if ($res =~ m@^.(.*\*/)@) { + substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]); + } + + # The pathname on a #include may be surrounded by '<' and '>'. + if ($res =~ /^.#\s*include\s+\<(.*)\>/) { + my $clean = 'X' x length($1); + $res =~ s@\<.*\>@<$clean>@; + + # The whole of a #error is a string. + } elsif ($res =~ /^.#\s*(?:error|warning)\s+(.*)\b/) { + my $clean = 'X' x length($1); + $res =~ s@(#\s*(?:error|warning)\s+).*@$1$clean@; + } + return $res; } @@ -315,9 +362,9 @@ sub ctx_statement_block { # context. if ($off >= $len) { for (; $remain > 0; $line++) { - next if ($rawlines[$line] =~ /^-/); + next if ($lines[$line] =~ /^-/); $remain--; - $blk .= sanitise_line($rawlines[$line]) . "\n"; + $blk .= $lines[$line] . "\n"; $len = length($blk); $line++; last; @@ -500,103 +547,106 @@ sub cat_vet { return $res; } +my $av_preprocessor = 0; +my $av_paren = 0; +my @av_paren_type; + +sub annotate_reset { + $av_preprocessor = 0; + $av_paren = 0; + @av_paren_type = (); +} + sub annotate_values { my ($stream, $type) = @_; my $res; my $cur = $stream; - my $debug = 0; - - print "$stream\n" if ($debug); - - ##my $type = 'N'; - my $pos = 0; - my $preprocessor = 0; - my $paren = 0; - my @paren_type; + print "$stream\n" if ($dbg_values > 1); while (length($cur)) { - print " <$type> " if ($debug); + print " <$type> " if ($dbg_values > 1); if ($cur =~ /^(\s+)/o) { - print "WS($1)\n" if ($debug); - if ($1 =~ /\n/ && $preprocessor) { - $preprocessor = 0; + print "WS($1)\n" if ($dbg_values > 1); + if ($1 =~ /\n/ && $av_preprocessor) { + $av_preprocessor = 0; $type = 'N'; } } elsif ($cur =~ /^($Type)/) { - print "DECLARE($1)\n" if ($debug); + print "DECLARE($1)\n" if ($dbg_values > 1); $type = 'T'; } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) { - print "DEFINE($1)\n" if ($debug); - $preprocessor = 1; - $paren_type[$paren] = 'N'; + print "DEFINE($1)\n" if ($dbg_values > 1); + $av_preprocessor = 1; + $av_paren_type[$av_paren] = 'N'; - } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|endif))/o) { - print "PRE($1)\n" if ($debug); - $preprocessor = 1; + } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|elif|endif))/o) { + print "PRE($1)\n" if ($dbg_values > 1); + $av_preprocessor = 1; $type = 'N'; } elsif ($cur =~ /^(\\\n)/o) { - print "PRECONT($1)\n" if ($debug); + print "PRECONT($1)\n" if ($dbg_values > 1); } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { - print "SIZEOF($1)\n" if ($debug); + print "SIZEOF($1)\n" if ($dbg_values > 1); if (defined $2) { - $paren_type[$paren] = 'V'; + $av_paren_type[$av_paren] = 'V'; } $type = 'N'; } elsif ($cur =~ /^(if|while|typeof|for)\b/o) { - print "COND($1)\n" if ($debug); - $paren_type[$paren] = 'N'; + print "COND($1)\n" if ($dbg_values > 1); + $av_paren_type[$av_paren] = 'N'; $type = 'N'; } elsif ($cur =~/^(return|case|else)/o) { - print "KEYWORD($1)\n" if ($debug); + print "KEYWORD($1)\n" if ($dbg_values > 1); $type = 'N'; } elsif ($cur =~ /^(\()/o) { - print "PAREN('$1')\n" if ($debug); - $paren++; + print "PAREN('$1')\n" if ($dbg_values > 1); + $av_paren++; $type = 'N'; } elsif ($cur =~ /^(\))/o) { - $paren-- if ($paren > 0); - if (defined $paren_type[$paren]) { - $type = $paren_type[$paren]; - undef $paren_type[$paren]; - print "PAREN('$1') -> $type\n" if ($debug); + $av_paren-- if ($av_paren > 0); + if (defined $av_paren_type[$av_paren]) { + $type = $av_paren_type[$av_paren]; + undef $av_paren_type[$av_paren]; + print "PAREN('$1') -> $type\n" + if ($dbg_values > 1); } else { - print "PAREN('$1')\n" if ($debug); + print "PAREN('$1')\n" if ($dbg_values > 1); } } elsif ($cur =~ /^($Ident)\(/o) { - print "FUNC($1)\n" if ($debug); - $paren_type[$paren] = 'V'; + print "FUNC($1)\n" if ($dbg_values > 1); + $av_paren_type[$av_paren] = 'V'; } elsif ($cur =~ /^($Ident|$Constant)/o) { - print "IDENT($1)\n" if ($debug); + print "IDENT($1)\n" if ($dbg_values > 1); $type = 'V'; } elsif ($cur =~ /^($Assignment)/o) { - print "ASSIGN($1)\n" if ($debug); + print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N'; } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) { - print "END($1)\n" if ($debug); + print "END($1)\n" if ($dbg_values > 1); $type = 'N'; } elsif ($cur =~ /^($Operators)/o) { - print "OP($1)\n" if ($debug); + print "OP($1)\n" if ($dbg_values > 1); if ($1 ne '++' && $1 ne '--') { $type = 'N'; } } elsif ($cur =~ /(^.)/o) { - print "C($1)\n" if ($debug); + print "C($1)\n" if ($dbg_values > 1); } if (defined $1) { $cur = substr($cur, length($1)); @@ -616,7 +666,7 @@ sub possible { $possible ne 'struct' && $possible ne 'enum' && $possible ne 'case' && $possible ne 'else' && $possible ne 'typedef') { - #print "POSSIBLE<$possible>\n"; + warn "POSSIBLE: $possible\n" if ($dbg_possible); push(@typeList, $possible); build_types(); } @@ -655,11 +705,12 @@ sub CHK { sub process { my $filename = shift; - my @lines = @_; my $linenr=0; my $prevline=""; + my $prevrawline=""; my $stashline=""; + my $stashrawline=""; my $length; my $indent; @@ -681,14 +732,26 @@ sub process { my $realcnt = 0; my $here = ''; my $in_comment = 0; + my $comment_edge = 0; my $first_line = 0; my $prev_values = 'N'; + # Pre-scan the patch sanitizing the lines. # Pre-scan the patch looking for any __setup documentation. + # my @setup_docs = (); my $setup_docs = 0; - foreach my $line (@lines) { + my $line; + foreach my $rawline (@rawlines) { + # Standardise the strings and chars within the input to + # simplify matching. + $line = sanitise_line($rawline); + push(@lines, $line); + + ##print "==>$rawline\n"; + ##print "-->$line\n"; + if ($line=~/^\+\+\+\s+(\S+)/) { $setup_docs = 0; if ($1 =~ m@Documentation/kernel-parameters.txt$@) { @@ -707,8 +770,7 @@ sub process { foreach my $line (@lines) { $linenr++; - my $rawline = $line; - + my $rawline = $rawlines[$linenr - 1]; #extract the filename as it passes if ($line=~/^\+\+\+\s+(\S+)/) { @@ -728,6 +790,7 @@ sub process { } else { $realcnt=1+1; } + annotate_reset(); $prev_values = 'N'; next; } @@ -746,7 +809,7 @@ sub process { if ($linenr == $first_line) { my $edge; for (my $ln = $first_line; $ln < ($linenr + $realcnt); $ln++) { - ($edge) = ($lines[$ln - 1] =~ m@(/\*|\*/)@); + ($edge) = ($rawlines[$ln - 1] =~ m@(/\*|\*/)@); last if (defined $edge); } if (defined $edge && $edge eq '*/') { @@ -757,25 +820,30 @@ sub process { # Guestimate if this is a continuing comment. If this # is the start of a diff block and this line starts # ' *' then it is very likely a comment. - if ($linenr == $first_line and $line =~ m@^.\s*\*@) { + if ($linenr == $first_line and $rawline =~ m@^.\s* \*(?:\s|$)@) { $in_comment = 1; } # Find the last comment edge on _this_ line. - while (($line =~ m@(/\*|\*/)@g)) { + $comment_edge = 0; + while (($rawline =~ m@(/\*|\*/)@g)) { if ($1 eq '/*') { $in_comment = 1; } else { $in_comment = 0; } + $comment_edge = 1; } # Measure the line length and indent. - ($length, $indent) = line_stats($line); + ($length, $indent) = line_stats($rawline); # Track the previous line. ($prevline, $stashline) = ($stashline, $line); ($previndent, $stashindent) = ($stashindent, $indent); + ($prevrawline, $stashrawline) = ($stashrawline, $rawline); + + #warn "ic<$in_comment> ce<$comment_edge> line<$line>\n"; } elsif ($realcnt == 1) { $realcnt--; @@ -786,9 +854,9 @@ sub process { $here = "#$realline: " if ($file); $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); - my $hereline = "$here\n$line\n"; - my $herecurr = "$here\n$line\n"; - my $hereprev = "$here\n$prevline\n$line\n"; + my $hereline = "$here\n$rawline\n"; + my $herecurr = "$here\n$rawline\n"; + my $hereprev = "$here\n$prevrawline\n$rawline\n"; $prefix = "$filename:$realline: " if ($emacs && $file); $prefix = "$filename:$linenr: " if ($emacs && !$file); @@ -816,7 +884,7 @@ sub process { # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php if (($realfile =~ /^$/ || $line =~ /^\+/) && - !($line =~ m/^( + !($rawline =~ m/^( [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs @@ -826,7 +894,7 @@ sub process { | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$/x )) { - ERROR("Invalid UTF-8\n" . $herecurr); + ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $herecurr); } #ignore lines being removed @@ -837,15 +905,15 @@ sub process { #trailing whitespace if ($line =~ /^\+.*\015/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; ERROR("DOS line endings\n" . $herevet); - } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; + } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; ERROR("trailing whitespace\n" . $herevet); } #80 column limit - if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { + if ($line =~ /^\+/ && !($prevrawline=~/\/\*\*/) && $length > 80) { WARN("line over 80 characters\n" . $herecurr); } @@ -859,46 +927,48 @@ sub process { # at the beginning of a line any tabs must come first and anything # more than 8 must use tabs. - if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; + if ($rawline =~ /^\+\s* \t\s*\S/ || + $rawline =~ /^\+\s* \s*/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; ERROR("use tabs not spaces\n" . $herevet); } -# Remove comments from the line before processing. - my $comment_edge = ($line =~ s@/\*.*\*/@@g) + - ($line =~ s@/\*.*@@) + - ($line =~ s@^(.).*\*/@$1@); +# check for RCS/CVS revision markers + if ($rawline =~ /\$(Revision|Log|Id)(?:\$|)/) { + WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); + } # The rest of our checks refer specifically to C style # only apply those _outside_ comments. Only skip # lines in the middle of comments. next if (!$comment_edge && $in_comment); -# Standardise the strings and chars within the input to simplify matching. - $line = sanitise_line($line); - # Check for potential 'bare' types - if ($realcnt && - $line !~ /$Ident:\s*$/ && - ($line =~ /^.\s*$Ident\s*\(\*+\s*$Ident\)\s*\(/ || - $line !~ /^.\s*$Ident\s*\(/)) { + if ($realcnt) { + # Ignore goto labels. + if ($line =~ /$Ident:\*$/) { + + # Ignore functions being called + } elsif ($line =~ /^.\s*$Ident\s*\(/) { + # definitions in global scope can only start with types - if ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) { + } elsif ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) { possible($1); # declarations always start with types - } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/) { + } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=)/) { possible($1); + } # any (foo ... *) is a pointer cast, and foo is a type - } elsif ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/) { + while ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) { possible($1); } # Check for any sort of function declaration. # int foo(something bar, other baz); # void (*store_gdt)(x86_descr_ptr *); - if ($prev_values eq 'N' && $line =~ /^(.(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { + if ($prev_values eq 'N' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { my ($name_len) = length($1); my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, $name_len); my $ctx = join("\n", @ctx); @@ -974,8 +1044,11 @@ sub process { my $opline = $line; $opline =~ s/^./ /; my $curr_values = annotate_values($opline . "\n", $prev_values); $curr_values = $prev_values . $curr_values; - #warn "--> $opline\n"; - #warn "--> $curr_values ($prev_values)\n"; + if ($dbg_values) { + my $outline = $opline; $outline =~ s/\t/ /g; + warn "--> .$outline\n"; + warn "--> $curr_values\n"; + } $prev_values = substr($curr_values, -1); #ignore lines not being added @@ -1004,9 +1077,6 @@ sub process { ERROR("malformed #include filename\n" . $herecurr); } - # Sanitise this special form of string. - $path = 'X' x length($path); - $line =~ s{\<.*\>}{<$path>}; } # no C99 // comments @@ -1074,7 +1144,7 @@ sub process { # } if ($line =~ /\bLINUX_VERSION_CODE\b/) { - WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged" . $herecurr); + WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } # printk should use KERN_* levels. Note that follow on printk's on the @@ -1102,7 +1172,7 @@ sub process { # function brace can't be on same line, except for #defines of do while, # or if closed on same line - if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and + if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).*\s{/) and !($line=~/\#define.*do\s{/) and !($line=~/}/)) { ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); } @@ -1115,8 +1185,22 @@ sub process { # check for spaces between functions and their parentheses. while ($line =~ /($Ident)\s+\(/g) { - if ($1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/ && - $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) { + my $name = $1; + my $ctx = substr($line, 0, $-[1]); + + # Ignore those directives where spaces _are_ permitted. + if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/) { + + # cpp #define statements have non-optional spaces, ie + # if there is a space between the name and the open + # parenthesis it is simply not a parameter group. + } elsif ($ctx =~ /^.\#\s*define\s*$/) { + + # If this whole things ends with a type its most + # likely a typedef for a function. + } elsif ("$ctx$name" =~ /$Type$/) { + + } else { WARN("no space between function name and open parenthesis '('\n" . $herecurr); } } @@ -1126,7 +1210,7 @@ sub process { <<=|>>=|<=|>=|==|!=| \+=|-=|\*=|\/=|%=|\^=|\|=|&=| =>|->|<<|>>|<|>|=|!|~| - &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/ + &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% }x; my @elements = split(/($ops|;)/, $opline); my $off = 0; @@ -1239,7 +1323,8 @@ sub process { } elsif ($op eq '<<' or $op eq '>>' or $op eq '&' or $op eq '^' or $op eq '|' or $op eq '+' or $op eq '-' or - $op eq '*' or $op eq '/') + $op eq '*' or $op eq '/' or + $op eq '%') { if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) { ERROR("need consistent spacing around '$op' $at\n" . @@ -1324,7 +1409,7 @@ sub process { my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) { - ERROR("do not use assignment in if condition ($c)\n" . $herecurr); + ERROR("do not use assignment in if condition\n" . $herecurr); } # Find out what is on the end of the line after the @@ -1350,6 +1435,20 @@ sub process { ERROR("else should follow close brace '}'\n" . $hereprev); } + if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and + $previndent == $indent) { + my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); + + # Find out what is on the end of the line after the + # conditional. + substr($s, 0, length($c)) = ''; + $s =~ s/\n.*//g; + + if ($s =~ /^\s*;/) { + ERROR("while should follow close brace '}'\n" . $hereprev); + } + } + #studly caps, commented out until figure out how to distinguish between use of existing and adding new # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) { # print "No studly caps, use _\n"; @@ -1447,8 +1546,11 @@ sub process { # Count the newlines, if there is only one # then the block should not have {}'s. my @lines = ($stmt =~ /\n/g); + my @statements = ($stmt =~ /;/g); #print "lines<" . scalar(@lines) . ">\n"; + #print "statements<" . scalar(@statements) . ">\n"; if ($lvl == 0 && scalar(@lines) == 0 && + scalar(@statements) < 2 && $stmt !~ /{/ && $stmt !~ /\bif\b/ && $before !~ /}/ && $after !~ /{/) { my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n"; @@ -1587,10 +1689,10 @@ sub process { } if ($clean == 1 && $quiet == 0) { - print "Your patch has no obvious style problems and is ready for submission.\n" + print "$vname has no obvious style problems and is ready for submission.\n" } if ($clean == 0 && $quiet == 0) { - print "Your patch has style problems, please review. If any of these errors\n"; + print "$vname has style problems, please review. If any of these errors\n"; print "are false positives report them to the maintainer, see\n"; print "CHECKPATCH in MAINTAINERS.\n"; } -- cgit v1.2.3 From 13214adf738abc92b0a00c0763fd3be79eebaa7c Mon Sep 17 00:00:00 2001 From: Andy Whitcroft Date: Fri, 8 Feb 2008 04:22:03 -0800 Subject: update checkpatch.pl to version 0.14 This version brings the remainder of the queued fixes. A number of fixes for items missed reported by Andrew Morton and others. Also a handful of new checks and fixes for false positives. Of note: - new warning associated with --file to try and avoid cleanup only patches, - corrected handling of completly empty files, - corrected report handling with multiple files, - handling of possible types in the face of multiple declarations, - detection of unnessary braces on complex if statements (where present), and - all new comment spacing handling. Andi Kleen (1): Introduce a warning when --file mode is used Andy Whitcroft (14): Version: 0.14 clean up some space violations in checkpatch.pl a completly empty file should not provoke a whinge reset report lines buffers between files unary ++/-- may abutt close braces __typeof__ is also unary comments: revamp comment handling add --summary-file option adding filename to summary line trailing backslashes are not trailing statements handle operators passed as parameters such as to ASSERTCMP possible types -- enhance debugging check for boolean operations with constants possible types: handle multiple declarations detect and report if statements where all branches are single statements Arjan van de Ven (1): quiet option should not print the summary on no errors Bartlomiej Zolnierkiewicz (1): warn about using __FUNCTION__ Timur Tabi (1): loosen spacing checks for __asm__ Signed-off-by: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 226 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 184 insertions(+), 42 deletions(-) (limited to 'scripts') diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 545471a99eea..2086a856400a 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -9,7 +9,7 @@ use strict; my $P = $0; $P =~ s@.*/@@g; -my $V = '0.13'; +my $V = '0.14'; use Getopt::Long qw(:config no_auto_abbrev); @@ -24,6 +24,7 @@ my $file = 0; my $check = 0; my $summary = 1; my $mailback = 0; +my $summary_file = 0; my $root; my %debug; GetOptions( @@ -31,7 +32,6 @@ GetOptions( 'tree!' => \$tree, 'signoff!' => \$chk_signoff, 'patch!' => \$chk_patch, - 'test-type!' => \$tst_type, 'emacs!' => \$emacs, 'terse!' => \$terse, 'file!' => \$file, @@ -40,7 +40,10 @@ GetOptions( 'root=s' => \$root, 'summary!' => \$summary, 'mailback!' => \$mailback, + 'summary-file!' => \$summary_file, + 'debug=s' => \%debug, + 'test-type!' => \$tst_type, ) or exit; my $exit = 0; @@ -48,13 +51,15 @@ my $exit = 0; if ($#ARGV < 0) { print "usage: $P [options] patchfile\n"; print "version: $V\n"; - print "options: -q => quiet\n"; - print " --no-tree => run without a kernel tree\n"; - print " --terse => one line per report\n"; - print " --emacs => emacs compile window format\n"; - print " --file => check a source file\n"; - print " --strict => enable more subjective tests\n"; - print " --root => path to the kernel tree root\n"; + print "options: -q => quiet\n"; + print " --no-tree => run without a kernel tree\n"; + print " --terse => one line per report\n"; + print " --emacs => emacs compile window format\n"; + print " --file => check a source file\n"; + print " --strict => enable more subjective tests\n"; + print " --root => path to the kernel tree root\n"; + print " --no-summary => suppress the per-file summary\n"; + print " --summary-file => include the filename in summary\n"; exit(1); } @@ -213,6 +218,7 @@ for my $filename (@ARGV) { $exit = 1; } @rawlines = (); + @lines = (); } exit($exit); @@ -321,14 +327,14 @@ sub sanitise_line { } # Clear out the comments. - while ($res =~ m@(/\*.*?\*/)@) { - substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]); + while ($res =~ m@(/\*.*?\*/)@g) { + substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]); } if ($res =~ m@(/\*.*)@) { - substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]); + substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]); } if ($res =~ m@^.(.*\*/)@) { - substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]); + substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]); } # The pathname on a #include may be surrounded by '<' and '>'. @@ -352,10 +358,14 @@ sub ctx_statement_block { my $soff = $off; my $coff = $off - 1; + my $loff = 0; + my $type = ''; my $level = 0; my $c; my $len = 0; + + my $remainder; while (1) { #warn "CSB: blk<$blk>\n"; # If we are about to drop off the end, pull in more @@ -364,6 +374,7 @@ sub ctx_statement_block { for (; $remain > 0; $line++) { next if ($lines[$line] =~ /^-/); $remain--; + $loff = $len; $blk .= $lines[$line] . "\n"; $len = length($blk); $line++; @@ -371,11 +382,12 @@ sub ctx_statement_block { } # Bail if there is no further context. #warn "CSB: blk<$blk> off<$off> len<$len>\n"; - if ($off == $len) { + if ($off >= $len) { last; } } $c = substr($blk, $off, 1); + $remainder = substr($blk, $off); #warn "CSB: c<$c> type<$type> level<$level>\n"; # Statement ends at the ';' or a close '}' at the @@ -384,6 +396,12 @@ sub ctx_statement_block { last; } + # An else is really a conditional as long as its not else if + if ($level == 0 && $remainder =~ /(\s+else)(?:\s|{)/ && + $remainder !~ /\s+else\s+if\b/) { + $coff = $off + length($1); + } + if (($type eq '' || $type eq '(') && $c eq '(') { $level++; $type = '('; @@ -410,6 +428,10 @@ sub ctx_statement_block { } $off++; } + if ($off == $len) { + $line++; + $remain--; + } my $statement = substr($blk, $soff, $off - $soff + 1); my $condition = substr($blk, $soff, $coff - $soff + 1); @@ -417,7 +439,30 @@ sub ctx_statement_block { #warn "STATEMENT<$statement>\n"; #warn "CONDITION<$condition>\n"; - return ($statement, $condition); + #print "off<$off> loff<$loff>\n"; + + return ($statement, $condition, + $line, $remain + 1, $off - $loff + 1, $level); +} + +sub ctx_statement_full { + my ($linenr, $remain, $off) = @_; + my ($statement, $condition, $level); + + my (@chunks); + + ($statement, $condition, $linenr, $remain, $off, $level) = + ctx_statement_block($linenr, $remain, $off); + #print "F: c<$condition> s<$statement>\n"; + for (;;) { + push(@chunks, [ $condition, $statement ]); + last if (!($remain > 0 && $condition =~ /^.\s*(?:if|else|do)/)); + ($statement, $condition, $linenr, $remain, $off, $level) = + ctx_statement_block($linenr, $remain, $off); + #print "C: c<$condition> s<$statement>\n"; + } + + return ($level, $linenr, @chunks); } sub ctx_block_get { @@ -598,7 +643,7 @@ sub annotate_values { } $type = 'N'; - } elsif ($cur =~ /^(if|while|typeof|for)\b/o) { + } elsif ($cur =~ /^(if|while|typeof|__typeof__|for)\b/o) { print "COND($1)\n" if ($dbg_values > 1); $av_paren_type[$av_paren] = 'N'; $type = 'N'; @@ -635,8 +680,12 @@ sub annotate_values { print "ASSIGN($1)\n" if ($dbg_values > 1); $type = 'N'; - } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) { + } elsif ($cur =~/^(;)/) { print "END($1)\n" if ($dbg_values > 1); + $type = 'E'; + + } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) { + print "CLOSE($1)\n" if ($dbg_values > 1); $type = 'N'; } elsif ($cur =~ /^($Operators)/o) { @@ -658,7 +707,7 @@ sub annotate_values { } sub possible { - my ($possible) = @_; + my ($possible, $line) = @_; #print "CHECK<$possible>\n"; if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ && @@ -666,7 +715,7 @@ sub possible { $possible ne 'struct' && $possible ne 'enum' && $possible ne 'case' && $possible ne 'else' && $possible ne 'typedef') { - warn "POSSIBLE: $possible\n" if ($dbg_possible); + warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); push(@typeList, $possible); build_types(); } @@ -674,16 +723,15 @@ sub possible { my $prefix = ''; -my @report = (); sub report { my $line = $prefix . $_[0]; $line = (split('\n', $line))[0] . "\n" if ($terse); - push(@report, $line); + push(our @report, $line); } sub report_dump { - @report; + our @report; } sub ERROR { report("ERROR: $_[0]\n"); @@ -721,6 +769,7 @@ sub process { my $signoff = 0; my $is_patch = 0; + our @report = (); our $cnt_lines = 0; our $cnt_error = 0; our $cnt_warn = 0; @@ -735,7 +784,10 @@ sub process { my $comment_edge = 0; my $first_line = 0; - my $prev_values = 'N'; + my $prev_values = 'E'; + + # suppression flags + my $suppress_ifbraces = 0; # Pre-scan the patch sanitizing the lines. # Pre-scan the patch looking for any __setup documentation. @@ -791,7 +843,9 @@ sub process { $realcnt=1+1; } annotate_reset(); - $prev_values = 'N'; + $prev_values = 'E'; + + $suppress_ifbraces = $linenr - 1; next; } @@ -953,22 +1007,22 @@ sub process { # definitions in global scope can only start with types } elsif ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) { - possible($1); + possible($1, $line); # declarations always start with types - } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=)/) { + } elsif ($prev_values eq 'E' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) { possible($1); } # any (foo ... *) is a pointer cast, and foo is a type while ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) { - possible($1); + possible($1, $line); } # Check for any sort of function declaration. # int foo(something bar, other baz); # void (*store_gdt)(x86_descr_ptr *); - if ($prev_values eq 'N' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { + if ($prev_values eq 'E' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { my ($name_len) = length($1); my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, $name_len); my $ctx = join("\n", @ctx); @@ -979,7 +1033,7 @@ sub process { for my $arg (split(/\s*,\s*/, $ctx)) { if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) { - possible($1); + possible($1, $line); } } } @@ -1189,7 +1243,7 @@ sub process { my $ctx = substr($line, 0, $-[1]); # Ignore those directives where spaces _are_ permitted. - if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/) { + if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case|__asm__)$/) { # cpp #define statements have non-optional spaces, ie # if there is a space between the name and the open @@ -1212,7 +1266,7 @@ sub process { =>|->|<<|>>|<|>|=|!|~| &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% }x; - my @elements = split(/($ops|;)/, $opline); + my @elements = split(/($;+|$ops|;)/, $opline); my $off = 0; my $blank = copy_spacing($opline); @@ -1272,8 +1326,15 @@ sub process { # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; #} + # Ignore operators passed as parameters. + if ($op_type ne 'V' && + $ca =~ /\s$/ && $cc =~ /^\s*,/) { + + # Ignore comments + } elsif ($op =~ /^$;+$/) { + # ; should have either the end of line or a space or \ after it - if ($op eq ';') { + } elsif ($op eq ';') { if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ && $cc !~ /^;/) { ERROR("need space after that '$op' $at\n" . $hereptr); @@ -1315,7 +1376,7 @@ sub process { if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { ERROR("need space one side of that '$op' $at\n" . $hereptr); } - if ($ctx =~ /Wx./ && $cc =~ /^;/) { + if ($ctx =~ /WxB/ || ($ctx =~ /Wx./ && $cc =~ /^;/)) { ERROR("no space before that '$op' $at\n" . $hereptr); } @@ -1388,7 +1449,7 @@ sub process { $line !~ /for\s*\(\s+;/) { ERROR("no space after that open parenthesis '('\n" . $herecurr); } - if ($line =~ /\s\)/ && $line !~ /^.\s*\)/ && + if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && $line !~ /for\s*\(.*;\s+\)/) { ERROR("no space before that close parenthesis ')'\n" . $herecurr); } @@ -1416,16 +1477,34 @@ sub process { # conditional. substr($s, 0, length($c)) = ''; $s =~ s/\n.*//g; - - if (length($c) && $s !~ /^\s*({|;|\/\*.*\*\/)?\s*\\*\s*$/) { + $s =~ s/$;//g; # Remove any comments + if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/) { ERROR("trailing statements should be on next line\n" . $herecurr); } } +# Check for bitwise tests written as boolean + if ($line =~ / + (?: + (?:\[|\(|\&\&|\|\|) + \s*0[xX][0-9]+\s* + (?:\&\&|\|\|) + | + (?:\&\&|\|\|) + \s*0[xX][0-9]+\s* + (?:\&\&|\|\||\)|\]) + )/x) + { + WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); + } + # if and else should not have general statements after it - if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ && - $1 !~ /^\s*(?:\sif|{|\\|$)/) { - ERROR("trailing statements should be on next line\n" . $herecurr); + if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { + my $s = $1; + $s =~ s/$;//g; # Remove any comments + if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { + ERROR("trailing statements should be on next line\n" . $herecurr); + } } # Check for }else {, these must be at the same @@ -1518,7 +1597,48 @@ sub process { } # check for redundant bracing round if etc - if ($line =~ /\b(if|while|for|else)\b/) { + if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { + my ($level, $endln, @chunks) = + ctx_statement_full($linenr, $realcnt, 0); + #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n"; + if ($#chunks > 1 && $level == 0) { + my $allowed = 0; + my $seen = 0; + for my $chunk (@chunks) { + my ($cond, $block) = @{$chunk}; + + substr($block, 0, length($cond)) = ''; + + $seen++ if ($block =~ /^\s*{/); + + $block =~ s/(^|\n)./$1/g; + $block =~ s/^\s*{//; + $block =~ s/}\s*$//; + $block =~ s/^\s*//; + $block =~ s/\s*$//; + + my @lines = ($block =~ /\n/g); + my @statements = ($block =~ /;/g); + + #print "cond<$cond> block<$block> lines<" . scalar(@lines) . "> statements<" . scalar(@statements) . "> seen<$seen> allowed<$allowed>\n"; + if (scalar(@lines) != 0) { + $allowed = 1; + } + if ($block =~/\b(?:if|for|while)\b/) { + $allowed = 1; + } + if (scalar(@statements) > 1) { + $allowed = 1; + } + } + if ($seen && !$allowed) { + WARN("braces {} are not necessary for any arm of this statement\n" . $herecurr); + $suppress_ifbraces = $endln; + } + } + } + if ($linenr > $suppress_ifbraces && + $line =~ /\b(if|while|for|else)\b/) { # Locate the end of the opening statement. my @control = ctx_statement($linenr, $realcnt, 0); my $nr = $linenr + (scalar(@control) - 1); @@ -1541,7 +1661,7 @@ sub process { my $after = $1; #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n"; - #print "stmt<$stmt>\n\n"; + #print "before<$before> stmt<$stmt> after<$after>\n\n"; # Count the newlines, if there is only one # then the block should not have {}'s. @@ -1659,6 +1779,17 @@ sub process { if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); } + +# check for gcc specific __FUNCTION__ + if ($line =~ /__FUNCTION__/) { + WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); + } + } + + # If we have no input at all, then there is nothing to report on + # so just keep quiet. + if ($#rawlines == -1) { + exit(0); } # In mailback mode only produce a report in the negative, for @@ -1681,7 +1812,8 @@ sub process { } print report_dump(); - if ($summary) { + if ($summary && !($clean == 1 && $quiet == 1)) { + print "$filename " if ($summary_file); print "total: $cnt_error errors, $cnt_warn warnings, " . (($check)? "$cnt_chk checks, " : "") . "$cnt_lines lines checked\n"; @@ -1696,5 +1828,15 @@ sub process { print "are false positives report them to the maintainer, see\n"; print "CHECKPATCH in MAINTAINERS.\n"; } + print < Date: Wed, 6 Feb 2008 21:51:18 +0100 Subject: kbuild/modpost: improve warnings if symbol is unknown If we cannot determine the symbol then print (unknown) to hint the reader that we failed to find the symbol. This happens with REL relocation records in arm object files. Signed-off-by: Sam Ravnborg --- scripts/mod/modpost.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 5d546466e6b1..32e9d8ffceef 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -613,7 +613,7 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) if (sym) return elf->strtab + sym->st_name; else - return ""; + return "(unknown)"; } static const char *sec_name(struct elf_info *elf, int shndx) @@ -1102,7 +1102,7 @@ static int is_function(Elf_Sym *sym) if (sym) return ELF_ST_TYPE(sym->st_info) == STT_FUNC; else - return 0; + return -1; } /* @@ -1120,10 +1120,17 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, { const char *from, *from_p; const char *to, *to_p; - from = from_is_func ? "function" : "variable"; - from_p = from_is_func ? "()" : ""; - to = to_is_func ? "function" : "variable"; - to_p = to_is_func ? "()" : ""; + + switch (from_is_func) { + case 0: from = "variable"; from_p = ""; break; + case 1: from = "function"; from_p = "()"; break; + default: from = "(unknown reference)"; from_p = ""; break; + } + switch (to_is_func) { + case 0: to = "variable"; to_p = ""; break; + case 1: to = "function"; to_p = "()"; break; + default: to = "(unknown reference)"; to_p = ""; break; + } sec_mismatch_count++; if (!sec_mismatch_verbose) @@ -1137,7 +1144,7 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, switch (mismatch) { case TEXT_TO_INIT: fprintf(stderr, - "The function %s %s() references\n" + "The function %s%s() references\n" "the %s %s%s%s.\n" "This is often because %s lacks a %s\n" "annotation or the annotation of %s is wrong.\n", -- cgit v1.2.3 From ff739b611f41a93338855c064959404f3b7c9bab Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Tue, 5 Feb 2008 11:44:52 +0100 Subject: Add binoffset to gitignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Uwe Kleine-König Signed-off-by: Sam Ravnborg --- scripts/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/.gitignore b/scripts/.gitignore index a1f52cb47200..b939fbd01195 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -6,3 +6,4 @@ kallsyms pnmtologo bin2c unifdef +binoffset -- cgit v1.2.3 From 7c0ac495e30b2b9becb79be2ff87642ed8ad8f0c Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 5 Feb 2008 11:38:49 +0100 Subject: kbuild/modpost: Use warn() for announcing section mismatches modpost: Use warn() for announcing section mismatches, for easy grepping for warnings in build logs. Also change an existing call from fprintf() to warn() while we're at it. Signed-off-by: Geert Uytterhoeven Signed-off-by: Sam Ravnborg --- scripts/mod/modpost.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 32e9d8ffceef..dbe1fb5e8cc0 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1136,10 +1136,10 @@ static void report_sec_mismatch(const char *modname, enum mismatch mismatch, if (!sec_mismatch_verbose) return; - fprintf(stderr, "WARNING: %s(%s+0x%llx): Section mismatch in" - " reference from the %s %s%s to the %s %s:%s%s\n", - modname, fromsec, fromaddr, from, fromsym, from_p, - to, tosec, tosym, to_p); + warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s " + "to the %s %s:%s%s\n", + modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec, + tosym, to_p); switch (mismatch) { case TEXT_TO_INIT: @@ -1945,10 +1945,10 @@ int main(int argc, char **argv) if (dump_write) write_dump(dump_write); if (sec_mismatch_count && !sec_mismatch_verbose) - fprintf(stderr, "modpost: Found %d section mismatch(es).\n" - "To see full details build your kernel with:\n" - "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", - sec_mismatch_count); + warn("modpost: Found %d section mismatch(es).\n" + "To see full details build your kernel with:\n" + "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", + sec_mismatch_count); return err; } -- cgit v1.2.3 From d75f4c683f817ef61c9ae634886e7ebc3133c002 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 8 Feb 2008 00:05:52 -0500 Subject: kbuild: silence CHK/UPD messages according to $(quiet) Signed-off-by: Mike Frysinger Signed-off-by: Sam Ravnborg --- init/Makefile | 4 +++- scripts/Kbuild.include | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/init/Makefile b/init/Makefile index 633392f5cdee..c5f157ce293e 100644 --- a/init/Makefile +++ b/init/Makefile @@ -27,7 +27,9 @@ $(obj)/version.o: include/linux/compile.h # mkcompile_h will make sure to only update the # actual file if its content has changed. + quiet_chk_compile.h = echo ' CHK $@' +silent_chk_compile.h = : include/linux/compile.h: FORCE - @echo ' CHK $@' + @$($(quiet)chk_compile.h) $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \ "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)" diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index b96ea8d6a5ed..da3559ea92e0 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -39,15 +39,19 @@ escsq = $(subst $(squote),'\$(squote)',$1) # - If they are equal no change, and no timestamp update # - stdin is piped in from the first prerequisite ($<) so one has # to specify a valid file as first prerequisite (often the kbuild file) + quiet_chk_filechk = echo ' CHK $@' +silent_chk_filechk = : + quiet_upd_filechk = echo ' UPD $@' +silent_upd_filechk = : define filechk $(Q)set -e; \ - echo ' CHK $@'; \ + $($(quiet)chk_filechk); \ mkdir -p $(dir $@); \ $(filechk_$(1)) < $< > $@.tmp; \ if [ -r $@ ] && cmp -s $@ $@.tmp; then \ rm -f $@.tmp; \ else \ - echo ' UPD $@'; \ + $($(quiet)upd_filechk); \ mv -f $@.tmp $@; \ fi endef -- cgit v1.2.3 From ed2c9fa53b7a3e240a64e6e97494d72d0f80eed0 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 7 Feb 2008 17:18:51 +0100 Subject: Kbuild: Fix deb-pkg target to work with kernel versions ending with - If CONIFIG_LOCALVERSION is set for example to -loop, the following error message was generated. dpkg-deb - error: Debian revision (`loop') doesn't contain any digits dpkg-deb: 1 errors in control file The patch solves this by adding a numeric revision to package version. Signed-off-by: Michal Sojka Signed-off-by: Sam Ravnborg --- scripts/package/builddeb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/package/builddeb b/scripts/package/builddeb index 0f657b5f3bc8..ba6bf5d5abf9 100644 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -13,6 +13,7 @@ set -e # Some variables and settings used throughout the script version=$KERNELRELEASE +revision=`cat .version` tmpdir="$objtree/debian/tmp" packagename=linux-$version @@ -65,7 +66,7 @@ done name="Kernel Compiler <$(id -nu)@$(hostname -f)>" # Generate a simple changelog template cat < debian/changelog -linux ($version) unstable; urgency=low +linux ($version-$revision) unstable; urgency=low * A standard release -- cgit v1.2.3 From fab1e310d3f97bb9403ac68e181fd3e654a755c7 Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Mon, 11 Feb 2008 14:26:26 +0100 Subject: kbuild: fix make V=1 When make -s support were added to filechk to combination created with make V=1 were not covered. Fix it by explicitly cover this case too. Signed-off-by: Sam Ravnborg Cc: Mike Frysinger --- init/Makefile | 1 + scripts/Kbuild.include | 3 +++ 2 files changed, 4 insertions(+) (limited to 'scripts') diff --git a/init/Makefile b/init/Makefile index c5f157ce293e..4a243df426f7 100644 --- a/init/Makefile +++ b/init/Makefile @@ -27,6 +27,7 @@ $(obj)/version.o: include/linux/compile.h # mkcompile_h will make sure to only update the # actual file if its content has changed. + chk_compile.h = : quiet_chk_compile.h = echo ' CHK $@' silent_chk_compile.h = : include/linux/compile.h: FORCE diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index da3559ea92e0..d64e6badc942 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -39,10 +39,13 @@ escsq = $(subst $(squote),'\$(squote)',$1) # - If they are equal no change, and no timestamp update # - stdin is piped in from the first prerequisite ($<) so one has # to specify a valid file as first prerequisite (often the kbuild file) + chk_filechk = : quiet_chk_filechk = echo ' CHK $@' silent_chk_filechk = : + upd_filechk = : quiet_upd_filechk = echo ' UPD $@' silent_upd_filechk = : + define filechk $(Q)set -e; \ $($(quiet)chk_filechk); \ -- cgit v1.2.3 From b2e3e658b344c6bcfb8fb694100ab2f2b5b2edb0 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 13 Feb 2008 15:03:39 -0800 Subject: Linux Kernel Markers: create modpost file This adds some new magic in the MODPOST phase for CONFIG_MARKERS. Analogous to the Module.symvers file, the build will now write a Module.markers file when CONFIG_MARKERS=y is set. This file lists the name, defining module, and format string of each marker, separated by \t characters. This simple text file can be used by offline build procedures for instrumentation code, analogous to how System.map and Module.symvers can be useful to have for kernels other than the one you are running right now. The strings are made easy to extract by having the __trace_mark macro define the name and format together in a single array called __mstrtab_* in the __markers_strings section. This is straightforward and reliable as long as the marker structs are always defined by this macro. It is an unreasonable amount of hairy work to extract the string pointers from the __markers section structs, which entails handling a relocation type for every machine under the sun. Mathieu : - Ran through checkpatch.pl Signed-off-by: Roland McGrath Signed-off-by: Mathieu Desnoyers Cc: David Smith Cc: Sam Ravnborg Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/marker.h | 9 +-- scripts/Makefile.modpost | 11 ++++ scripts/mod/modpost.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++- scripts/mod/modpost.h | 3 + 4 files changed, 180 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/include/linux/marker.h b/include/linux/marker.h index b5f95637f289..5df879dc3776 100644 --- a/include/linux/marker.h +++ b/include/linux/marker.h @@ -61,15 +61,12 @@ struct marker { */ #define __trace_mark(name, call_private, format, args...) \ do { \ - static const char __mstrtab_name_##name[] \ + static const char __mstrtab_##name[] \ __attribute__((section("__markers_strings"))) \ - = #name; \ - static const char __mstrtab_format_##name[] \ - __attribute__((section("__markers_strings"))) \ - = format; \ + = #name "\0" format; \ static struct marker __mark_##name \ __attribute__((section("__markers"), aligned(8))) = \ - { __mstrtab_name_##name, __mstrtab_format_##name, \ + { __mstrtab_##name, &__mstrtab_##name[sizeof(#name)], \ 0, 0, marker_probe_cb, \ { __mark_empty_function, NULL}, NULL }; \ __mark_check_format(format, ## args); \ diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 65e707e1ffc3..cfc004e04417 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -13,6 +13,7 @@ # 2) modpost is then used to # 3) create one .mod.c file pr. module # 4) create one Module.symvers file with CRC for all exported symbols +# 4a) [CONFIG_MARKERS] create one Module.markers file listing defined markers # 5) compile all .mod.c files # 6) final link of the module to a file @@ -45,6 +46,10 @@ include scripts/Makefile.lib kernelsymfile := $(objtree)/Module.symvers modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers +kernelmarkersfile := $(objtree)/Module.markers +modulemarkersfile := $(firstword $(KBUILD_EXTMOD))/Module.markers + +markersfile = $(if $(KBUILD_EXTMOD),$(modulemarkersfile),$(kernelmarkersfile)) # Step 1), find all modules listed in $(MODVERDIR)/ __modules := $(sort $(shell grep -h '\.ko' /dev/null $(wildcard $(MODVERDIR)/*.mod))) @@ -63,6 +68,8 @@ modpost = scripts/mod/modpost \ $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ + $(if $(CONFIG_MARKERS),-K $(kernelmarkersfile)) \ + $(if $(CONFIG_MARKERS),-M $(markersfile)) \ $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules @@ -82,6 +89,10 @@ vmlinux.o: FORCE $(symverfile): __modpost ; $(modules:.ko=.mod.c): __modpost ; +ifdef CONFIG_MARKERS +$(markersfile): __modpost ; +endif + # Step 5), compile all *.mod.c files diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index dbe1fb5e8cc0..61742771c65d 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -11,6 +11,8 @@ * Usage: modpost vmlinux module1.o module2.o ... */ +#define _GNU_SOURCE +#include #include #include "modpost.h" #include "../../include/linux/license.h" @@ -435,6 +437,8 @@ static int parse_elf(struct elf_info *info, const char *filename) info->export_unused_gpl_sec = i; else if (strcmp(secname, "__ksymtab_gpl_future") == 0) info->export_gpl_future_sec = i; + else if (strcmp(secname, "__markers_strings") == 0) + info->markers_strings_sec = i; if (sechdrs[i].sh_type != SHT_SYMTAB) continue; @@ -1470,6 +1474,62 @@ static void check_sec_ref(struct module *mod, const char *modname, } } +static void get_markers(struct elf_info *info, struct module *mod) +{ + const Elf_Shdr *sh = &info->sechdrs[info->markers_strings_sec]; + const char *strings = (const char *) info->hdr + sh->sh_offset; + const Elf_Sym *sym, *first_sym, *last_sym; + size_t n; + + if (!info->markers_strings_sec) + return; + + /* + * First count the strings. We look for all the symbols defined + * in the __markers_strings section named __mstrtab_*. For + * these local names, the compiler puts a random .NNN suffix on, + * so the names don't correspond exactly. + */ + first_sym = last_sym = NULL; + n = 0; + for (sym = info->symtab_start; sym < info->symtab_stop; sym++) + if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && + sym->st_shndx == info->markers_strings_sec && + !strncmp(info->strtab + sym->st_name, + "__mstrtab_", sizeof "__mstrtab_" - 1)) { + if (first_sym == NULL) + first_sym = sym; + last_sym = sym; + ++n; + } + + if (n == 0) + return; + + /* + * Now collect each name and format into a line for the output. + * Lines look like: + * marker_name vmlinux marker %s format %d + * The format string after the second \t can use whitespace. + */ + mod->markers = NOFAIL(malloc(sizeof mod->markers[0] * n)); + mod->nmarkers = n; + + n = 0; + for (sym = first_sym; sym <= last_sym; sym++) + if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && + sym->st_shndx == info->markers_strings_sec && + !strncmp(info->strtab + sym->st_name, + "__mstrtab_", sizeof "__mstrtab_" - 1)) { + const char *name = strings + sym->st_value; + const char *fmt = strchr(name, '\0') + 1; + char *line = NULL; + asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); + NOFAIL(line); + mod->markers[n++] = line; + } +} + static void read_symbols(char *modname) { const char *symname; @@ -1521,6 +1581,8 @@ static void read_symbols(char *modname) get_src_version(modname, mod->srcversion, sizeof(mod->srcversion)-1); + get_markers(&info, mod); + parse_elf_finish(&info); /* Our trick to get versioning for struct_module - it's @@ -1867,16 +1929,104 @@ static void write_dump(const char *fname) write_if_changed(&buf, fname); } +static void add_marker(struct module *mod, const char *name, const char *fmt) +{ + char *line = NULL; + asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); + NOFAIL(line); + + mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) * + sizeof mod->markers[0]))); + mod->markers[mod->nmarkers++] = line; +} + +static void read_markers(const char *fname) +{ + unsigned long size, pos = 0; + void *file = grab_file(fname, &size); + char *line; + + if (!file) /* No old markers, silently ignore */ + return; + + while ((line = get_next_line(&pos, file, size))) { + char *marker, *modname, *fmt; + struct module *mod; + + marker = line; + modname = strchr(marker, '\t'); + if (!modname) + goto fail; + *modname++ = '\0'; + fmt = strchr(modname, '\t'); + if (!fmt) + goto fail; + *fmt++ = '\0'; + if (*marker == '\0' || *modname == '\0') + goto fail; + + mod = find_module(modname); + if (!mod) { + if (is_vmlinux(modname)) + have_vmlinux = 1; + mod = new_module(NOFAIL(strdup(modname))); + mod->skip = 1; + } + + add_marker(mod, marker, fmt); + } + return; +fail: + fatal("parse error in markers list file\n"); +} + +static int compare_strings(const void *a, const void *b) +{ + return strcmp(*(const char **) a, *(const char **) b); +} + +static void write_markers(const char *fname) +{ + struct buffer buf = { }; + struct module *mod; + size_t i; + + for (mod = modules; mod; mod = mod->next) + if ((!external_module || !mod->skip) && mod->markers != NULL) { + /* + * Sort the strings so we can skip duplicates when + * we write them out. + */ + qsort(mod->markers, mod->nmarkers, + sizeof mod->markers[0], &compare_strings); + for (i = 0; i < mod->nmarkers; ++i) { + char *line = mod->markers[i]; + buf_write(&buf, line, strlen(line)); + while (i + 1 < mod->nmarkers && + !strcmp(mod->markers[i], + mod->markers[i + 1])) + free(mod->markers[i++]); + free(mod->markers[i]); + } + free(mod->markers); + mod->markers = NULL; + } + + write_if_changed(&buf, fname); +} + int main(int argc, char **argv) { struct module *mod; struct buffer buf = { }; char *kernel_read = NULL, *module_read = NULL; char *dump_write = NULL; + char *markers_read = NULL; + char *markers_write = NULL; int opt; int err; - while ((opt = getopt(argc, argv, "i:I:msSo:aw")) != -1) { + while ((opt = getopt(argc, argv, "i:I:msSo:awM:K:")) != -1) { switch (opt) { case 'i': kernel_read = optarg; @@ -1903,6 +2053,12 @@ int main(int argc, char **argv) case 'w': warn_unresolved = 1; break; + case 'M': + markers_write = optarg; + break; + case 'K': + markers_read = optarg; + break; default: exit(1); } @@ -1950,5 +2106,11 @@ int main(int argc, char **argv) "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", sec_mismatch_count); + if (markers_read) + read_markers(markers_read); + + if (markers_write) + write_markers(markers_write); + return err; } diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 999f15e0e008..565c5872407e 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -112,6 +112,8 @@ struct module { int has_init; int has_cleanup; struct buffer dev_table_buf; + char **markers; + size_t nmarkers; char srcversion[25]; }; @@ -126,6 +128,7 @@ struct elf_info { Elf_Section export_gpl_sec; Elf_Section export_unused_gpl_sec; Elf_Section export_gpl_future_sec; + Elf_Section markers_strings_sec; const char *strtab; char *modinfo; unsigned int modinfo_len; -- cgit v1.2.3 From 34ff8a52fa7ebb7be036534295f7b252d39e3439 Mon Sep 17 00:00:00 2001 From: Harvey Harrison Date: Thu, 14 Feb 2008 19:31:23 -0800 Subject: kernel-doc: remove fastcall fastcall is gone from the tree, no need to adjust the function prototypes anymore for this. Signed-off-by: Harvey Harrison Acked-by: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/kernel-doc | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 6c18a14386a4..26146cbaa504 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -1624,7 +1624,6 @@ sub dump_function($$) { $prototype =~ s/^static +//; $prototype =~ s/^extern +//; - $prototype =~ s/^fastcall +//; $prototype =~ s/^asmlinkage +//; $prototype =~ s/^inline +//; $prototype =~ s/^__inline__ +//; -- cgit v1.2.3