aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile1
-rw-r--r--scripts/Makefile.build13
-rw-r--r--scripts/Makefile.headersinst3
-rw-r--r--scripts/Makefile.help3
-rw-r--r--scripts/Makefile.lib11
-rw-r--r--scripts/basic/Makefile2
-rw-r--r--scripts/basic/docproc.c129
-rw-r--r--scripts/basic/hash.c64
-rwxr-xr-xscripts/checkkconfigsymbols.sh2
-rwxr-xr-xscripts/checkpatch.pl186
-rwxr-xr-xscripts/checksyscalls.sh1
-rwxr-xr-xscripts/coccicheck80
-rw-r--r--scripts/coccinelle/alloc/drop_kmalloc_cast.cocci67
-rw-r--r--scripts/coccinelle/alloc/kzalloc-simple.cocci82
-rw-r--r--scripts/coccinelle/deref_null.cocci293
-rw-r--r--scripts/coccinelle/err_cast.cocci56
-rw-r--r--scripts/coccinelle/resource_size.cocci93
-rwxr-xr-xscripts/decodecode10
-rw-r--r--scripts/dtc/fstree.c1
-rw-r--r--scripts/gcc-goto.sh5
-rwxr-xr-xscripts/get_maintainer.pl1162
-rw-r--r--scripts/kconfig/.gitignore1
-rw-r--r--scripts/kconfig/Makefile77
-rw-r--r--scripts/kconfig/conf.c196
-rw-r--r--scripts/kconfig/confdata.c324
-rw-r--r--scripts/kconfig/expr.c4
-rw-r--r--scripts/kconfig/expr.h2
-rw-r--r--scripts/kconfig/gconf.c7
-rw-r--r--scripts/kconfig/lkc.h12
-rw-r--r--scripts/kconfig/lkc_proto.h1
-rw-r--r--scripts/kconfig/lxdialog/checklist.c10
-rw-r--r--scripts/kconfig/mconf.c2
-rw-r--r--scripts/kconfig/menu.c24
-rw-r--r--scripts/kconfig/nconf.c2
-rw-r--r--scripts/kconfig/qconf.cc106
-rw-r--r--scripts/kconfig/qconf.h17
-rw-r--r--scripts/kconfig/symbol.c296
-rwxr-xr-xscripts/kernel-doc56
-rw-r--r--scripts/mkmakefile4
-rw-r--r--scripts/mod/modpost.c73
-rw-r--r--scripts/package/Makefile37
-rw-r--r--scripts/package/builddeb5
-rw-r--r--scripts/recordmcount.c363
-rw-r--r--scripts/recordmcount.h366
-rwxr-xr-xscripts/recordmcount.pl11
-rwxr-xr-xscripts/setlocalversion4
46 files changed, 3586 insertions, 678 deletions
diff --git a/scripts/Makefile b/scripts/Makefile
index 842dbc2d5aed..2e088109fbd5 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -11,6 +11,7 @@ hostprogs-$(CONFIG_KALLSYMS) += kallsyms
11hostprogs-$(CONFIG_LOGO) += pnmtologo 11hostprogs-$(CONFIG_LOGO) += pnmtologo
12hostprogs-$(CONFIG_VT) += conmakehash 12hostprogs-$(CONFIG_VT) += conmakehash
13hostprogs-$(CONFIG_IKCONFIG) += bin2c 13hostprogs-$(CONFIG_IKCONFIG) += bin2c
14hostprogs-$(BUILD_C_RECORDMCOUNT) += recordmcount
14 15
15always := $(hostprogs-y) $(hostprogs-m) 16always := $(hostprogs-y) $(hostprogs-m)
16 17
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a1a5cf95a68d..5ad25e17b6cb 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -209,12 +209,23 @@ cmd_modversions = \
209endif 209endif
210 210
211ifdef CONFIG_FTRACE_MCOUNT_RECORD 211ifdef CONFIG_FTRACE_MCOUNT_RECORD
212ifdef BUILD_C_RECORDMCOUNT
213# Due to recursion, we must skip empty.o.
214# The empty.o file is created in the make process in order to determine
215# the target endianness and word size. It is made before all other C
216# files, including recordmcount.
217cmd_record_mcount = if [ $(@) != "scripts/mod/empty.o" ]; then \
218 $(objtree)/scripts/recordmcount "$(@)"; \
219 fi;
220else
212cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ 221cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
213 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ 222 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
214 "$(if $(CONFIG_64BIT),64,32)" \ 223 "$(if $(CONFIG_64BIT),64,32)" \
215 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC)" "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ 224 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \
225 "$(LD)" "$(NM)" "$(RM)" "$(MV)" \
216 "$(if $(part-of-module),1,0)" "$(@)"; 226 "$(if $(part-of-module),1,0)" "$(@)";
217endif 227endif
228endif
218 229
219define rule_cc_o_c 230define rule_cc_o_c
220 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 231 $(call echo-cmd,checksrc) $(cmd_checksrc) \
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
index 0fcd83838771..f89cb87f5c01 100644
--- a/scripts/Makefile.headersinst
+++ b/scripts/Makefile.headersinst
@@ -3,7 +3,6 @@
3# 3#
4# header-y - list files to be installed. They are preprocessed 4# header-y - list files to be installed. They are preprocessed
5# to remove __KERNEL__ section of the file 5# to remove __KERNEL__ section of the file
6# unifdef-y - Same as header-y. Obsolete
7# objhdr-y - Same as header-y but for generated files 6# objhdr-y - Same as header-y but for generated files
8# 7#
9# ========================================================================== 8# ==========================================================================
@@ -20,7 +19,7 @@ include scripts/Kbuild.include
20 19
21install := $(INSTALL_HDR_PATH)/$(_dst) 20install := $(INSTALL_HDR_PATH)/$(_dst)
22 21
23header-y := $(sort $(header-y) $(unifdef-y)) 22header-y := $(sort $(header-y))
24subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) 23subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
25header-y := $(filter-out %/, $(header-y)) 24header-y := $(filter-out %/, $(header-y))
26 25
diff --git a/scripts/Makefile.help b/scripts/Makefile.help
new file mode 100644
index 000000000000..d03608f5db04
--- /dev/null
+++ b/scripts/Makefile.help
@@ -0,0 +1,3 @@
1
2checker-help:
3 @echo ' coccicheck - Check with Coccinelle.'
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e93525c5e915..4c72c1189479 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -101,14 +101,6 @@ basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
101modname_flags = $(if $(filter 1,$(words $(modname))),\ 101modname_flags = $(if $(filter 1,$(words $(modname))),\
102 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") 102 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
103 103
104#hash values
105ifdef CONFIG_DYNAMIC_DEBUG
106debug_flags = -D"DEBUG_HASH=$(shell ./scripts/basic/hash djb2 $(@D)$(modname))"\
107 -D"DEBUG_HASH2=$(shell ./scripts/basic/hash r5 $(@D)$(modname))"
108else
109debug_flags =
110endif
111
112orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ 104orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
113 $(ccflags-y) $(CFLAGS_$(basetarget).o) 105 $(ccflags-y) $(CFLAGS_$(basetarget).o)
114_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) 106_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
@@ -154,8 +146,7 @@ endif
154 146
155c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 147c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
156 $(__c_flags) $(modkern_cflags) \ 148 $(__c_flags) $(modkern_cflags) \
157 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) \ 149 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
158 $(debug_flags)
159 150
160a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 151a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
161 $(__a_flags) $(modkern_aflags) 152 $(__a_flags) $(modkern_aflags)
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile
index 09559951df12..4c324a1f1e0e 100644
--- a/scripts/basic/Makefile
+++ b/scripts/basic/Makefile
@@ -9,7 +9,7 @@
9# fixdep: Used to generate dependency information during build process 9# fixdep: Used to generate dependency information during build process
10# docproc: Used in Documentation/DocBook 10# docproc: Used in Documentation/DocBook
11 11
12hostprogs-y := fixdep docproc hash 12hostprogs-y := fixdep docproc
13always := $(hostprogs-y) 13always := $(hostprogs-y)
14 14
15# fixdep is needed to compile other host programs 15# fixdep is needed to compile other host programs
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c
index 79ab973fb43a..fc3b18d844af 100644
--- a/scripts/basic/docproc.c
+++ b/scripts/basic/docproc.c
@@ -34,12 +34,14 @@
34 * 34 *
35 */ 35 */
36 36
37#define _GNU_SOURCE
37#include <stdio.h> 38#include <stdio.h>
38#include <stdlib.h> 39#include <stdlib.h>
39#include <string.h> 40#include <string.h>
40#include <ctype.h> 41#include <ctype.h>
41#include <unistd.h> 42#include <unistd.h>
42#include <limits.h> 43#include <limits.h>
44#include <errno.h>
43#include <sys/types.h> 45#include <sys/types.h>
44#include <sys/wait.h> 46#include <sys/wait.h>
45 47
@@ -54,6 +56,7 @@ typedef void FILEONLY(char * file);
54FILEONLY *internalfunctions; 56FILEONLY *internalfunctions;
55FILEONLY *externalfunctions; 57FILEONLY *externalfunctions;
56FILEONLY *symbolsonly; 58FILEONLY *symbolsonly;
59FILEONLY *findall;
57 60
58typedef void FILELINE(char * file, char * line); 61typedef void FILELINE(char * file, char * line);
59FILELINE * singlefunctions; 62FILELINE * singlefunctions;
@@ -65,12 +68,30 @@ FILELINE * docsection;
65#define KERNELDOCPATH "scripts/" 68#define KERNELDOCPATH "scripts/"
66#define KERNELDOC "kernel-doc" 69#define KERNELDOC "kernel-doc"
67#define DOCBOOK "-docbook" 70#define DOCBOOK "-docbook"
71#define LIST "-list"
68#define FUNCTION "-function" 72#define FUNCTION "-function"
69#define NOFUNCTION "-nofunction" 73#define NOFUNCTION "-nofunction"
70#define NODOCSECTIONS "-no-doc-sections" 74#define NODOCSECTIONS "-no-doc-sections"
71 75
72static char *srctree, *kernsrctree; 76static char *srctree, *kernsrctree;
73 77
78static char **all_list = NULL;
79static int all_list_len = 0;
80
81static void consume_symbol(const char *sym)
82{
83 int i;
84
85 for (i = 0; i < all_list_len; i++) {
86 if (!all_list[i])
87 continue;
88 if (strcmp(sym, all_list[i]))
89 continue;
90 all_list[i] = NULL;
91 break;
92 }
93}
94
74static void usage (void) 95static void usage (void)
75{ 96{
76 fprintf(stderr, "Usage: docproc {doc|depend} file\n"); 97 fprintf(stderr, "Usage: docproc {doc|depend} file\n");
@@ -248,6 +269,7 @@ static void docfunctions(char * filename, char * type)
248 struct symfile * sym = &symfilelist[i]; 269 struct symfile * sym = &symfilelist[i];
249 for (j=0; j < sym->symbolcnt; j++) { 270 for (j=0; j < sym->symbolcnt; j++) {
250 vec[idx++] = type; 271 vec[idx++] = type;
272 consume_symbol(sym->symbollist[j].name);
251 vec[idx++] = sym->symbollist[j].name; 273 vec[idx++] = sym->symbollist[j].name;
252 } 274 }
253 } 275 }
@@ -287,6 +309,11 @@ static void singfunc(char * filename, char * line)
287 vec[idx++] = &line[i]; 309 vec[idx++] = &line[i];
288 } 310 }
289 } 311 }
312 for (i = 0; i < idx; i++) {
313 if (strcmp(vec[i], FUNCTION))
314 continue;
315 consume_symbol(vec[i + 1]);
316 }
290 vec[idx++] = filename; 317 vec[idx++] = filename;
291 vec[idx] = NULL; 318 vec[idx] = NULL;
292 exec_kernel_doc(vec); 319 exec_kernel_doc(vec);
@@ -306,6 +333,10 @@ static void docsect(char *filename, char *line)
306 if (*s == '\n') 333 if (*s == '\n')
307 *s = '\0'; 334 *s = '\0';
308 335
336 asprintf(&s, "DOC: %s", line);
337 consume_symbol(s);
338 free(s);
339
309 vec[0] = KERNELDOC; 340 vec[0] = KERNELDOC;
310 vec[1] = DOCBOOK; 341 vec[1] = DOCBOOK;
311 vec[2] = FUNCTION; 342 vec[2] = FUNCTION;
@@ -315,6 +346,84 @@ static void docsect(char *filename, char *line)
315 exec_kernel_doc(vec); 346 exec_kernel_doc(vec);
316} 347}
317 348
349static void find_all_symbols(char *filename)
350{
351 char *vec[4]; /* kerneldoc -list file NULL */
352 pid_t pid;
353 int ret, i, count, start;
354 char real_filename[PATH_MAX + 1];
355 int pipefd[2];
356 char *data, *str;
357 size_t data_len = 0;
358
359 vec[0] = KERNELDOC;
360 vec[1] = LIST;
361 vec[2] = filename;
362 vec[3] = NULL;
363
364 if (pipe(pipefd)) {
365 perror("pipe");
366 exit(1);
367 }
368
369 switch (pid=fork()) {
370 case -1:
371 perror("fork");
372 exit(1);
373 case 0:
374 close(pipefd[0]);
375 dup2(pipefd[1], 1);
376 memset(real_filename, 0, sizeof(real_filename));
377 strncat(real_filename, kernsrctree, PATH_MAX);
378 strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
379 PATH_MAX - strlen(real_filename));
380 execvp(real_filename, vec);
381 fprintf(stderr, "exec ");
382 perror(real_filename);
383 exit(1);
384 default:
385 close(pipefd[1]);
386 data = malloc(4096);
387 do {
388 while ((ret = read(pipefd[0],
389 data + data_len,
390 4096)) > 0) {
391 data_len += ret;
392 data = realloc(data, data_len + 4096);
393 }
394 } while (ret == -EAGAIN);
395 if (ret != 0) {
396 perror("read");
397 exit(1);
398 }
399 waitpid(pid, &ret ,0);
400 }
401 if (WIFEXITED(ret))
402 exitstatus |= WEXITSTATUS(ret);
403 else
404 exitstatus = 0xff;
405
406 count = 0;
407 /* poor man's strtok, but with counting */
408 for (i = 0; i < data_len; i++) {
409 if (data[i] == '\n') {
410 count++;
411 data[i] = '\0';
412 }
413 }
414 start = all_list_len;
415 all_list_len += count;
416 all_list = realloc(all_list, sizeof(char *) * all_list_len);
417 str = data;
418 for (i = 0; i < data_len && start != all_list_len; i++) {
419 if (data[i] == '\0') {
420 all_list[start] = str;
421 str = data + i + 1;
422 start++;
423 }
424 }
425}
426
318/* 427/*
319 * Parse file, calling action specific functions for: 428 * Parse file, calling action specific functions for:
320 * 1) Lines containing !E 429 * 1) Lines containing !E
@@ -322,7 +431,8 @@ static void docsect(char *filename, char *line)
322 * 3) Lines containing !D 431 * 3) Lines containing !D
323 * 4) Lines containing !F 432 * 4) Lines containing !F
324 * 5) Lines containing !P 433 * 5) Lines containing !P
325 * 6) Default lines - lines not matching the above 434 * 6) Lines containing !C
435 * 7) Default lines - lines not matching the above
326 */ 436 */
327static void parse_file(FILE *infile) 437static void parse_file(FILE *infile)
328{ 438{
@@ -365,6 +475,12 @@ static void parse_file(FILE *infile)
365 s++; 475 s++;
366 docsection(line + 2, s); 476 docsection(line + 2, s);
367 break; 477 break;
478 case 'C':
479 while (*s && !isspace(*s)) s++;
480 *s = '\0';
481 if (findall)
482 findall(line+2);
483 break;
368 default: 484 default:
369 defaultline(line); 485 defaultline(line);
370 } 486 }
@@ -380,6 +496,7 @@ static void parse_file(FILE *infile)
380int main(int argc, char *argv[]) 496int main(int argc, char *argv[])
381{ 497{
382 FILE * infile; 498 FILE * infile;
499 int i;
383 500
384 srctree = getenv("SRCTREE"); 501 srctree = getenv("SRCTREE");
385 if (!srctree) 502 if (!srctree)
@@ -415,6 +532,7 @@ int main(int argc, char *argv[])
415 symbolsonly = find_export_symbols; 532 symbolsonly = find_export_symbols;
416 singlefunctions = noaction2; 533 singlefunctions = noaction2;
417 docsection = noaction2; 534 docsection = noaction2;
535 findall = find_all_symbols;
418 parse_file(infile); 536 parse_file(infile);
419 537
420 /* Rewind to start from beginning of file again */ 538 /* Rewind to start from beginning of file again */
@@ -425,8 +543,16 @@ int main(int argc, char *argv[])
425 symbolsonly = printline; 543 symbolsonly = printline;
426 singlefunctions = singfunc; 544 singlefunctions = singfunc;
427 docsection = docsect; 545 docsection = docsect;
546 findall = NULL;
428 547
429 parse_file(infile); 548 parse_file(infile);
549
550 for (i = 0; i < all_list_len; i++) {
551 if (!all_list[i])
552 continue;
553 fprintf(stderr, "Warning: didn't use docs for %s\n",
554 all_list[i]);
555 }
430 } 556 }
431 else if (strcmp("depend", argv[1]) == 0) 557 else if (strcmp("depend", argv[1]) == 0)
432 { 558 {
@@ -439,6 +565,7 @@ int main(int argc, char *argv[])
439 symbolsonly = adddep; 565 symbolsonly = adddep;
440 singlefunctions = adddep2; 566 singlefunctions = adddep2;
441 docsection = adddep2; 567 docsection = adddep2;
568 findall = adddep;
442 parse_file(infile); 569 parse_file(infile);
443 printf("\n"); 570 printf("\n");
444 } 571 }
diff --git a/scripts/basic/hash.c b/scripts/basic/hash.c
deleted file mode 100644
index 2ef5d3f666b8..000000000000
--- a/scripts/basic/hash.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
3 *
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#define DYNAMIC_DEBUG_HASH_BITS 6
11
12static const char *program;
13
14static void usage(void)
15{
16 printf("Usage: %s <djb2|r5> <modname>\n", program);
17 exit(1);
18}
19
20/* djb2 hashing algorithm by Dan Bernstein. From:
21 * http://www.cse.yorku.ca/~oz/hash.html
22 */
23
24static unsigned int djb2_hash(char *str)
25{
26 unsigned long hash = 5381;
27 int c;
28
29 c = *str;
30 while (c) {
31 hash = ((hash << 5) + hash) + c;
32 c = *++str;
33 }
34 return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
35}
36
37static unsigned int r5_hash(char *str)
38{
39 unsigned long hash = 0;
40 int c;
41
42 c = *str;
43 while (c) {
44 hash = (hash + (c << 4) + (c >> 4)) * 11;
45 c = *++str;
46 }
47 return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
48}
49
50int main(int argc, char *argv[])
51{
52 program = argv[0];
53
54 if (argc != 3)
55 usage();
56 if (!strcmp(argv[1], "djb2"))
57 printf("%d\n", djb2_hash(argv[2]));
58 else if (!strcmp(argv[1], "r5"))
59 printf("%d\n", r5_hash(argv[2]));
60 else
61 usage();
62 exit(0);
63}
64
diff --git a/scripts/checkkconfigsymbols.sh b/scripts/checkkconfigsymbols.sh
index 46be3c5a62b7..2ca49bb31efc 100755
--- a/scripts/checkkconfigsymbols.sh
+++ b/scripts/checkkconfigsymbols.sh
@@ -14,7 +14,7 @@ find $paths -name '*.[chS]' -o -name 'Makefile' -o -name 'Makefile*[^~]'| while
14do 14do
15 # Output the bare Kconfig variable and the filename; the _MODULE part at 15 # Output the bare Kconfig variable and the filename; the _MODULE part at
16 # the end is not removed here (would need perl an not-hungry regexp for that). 16 # the end is not removed here (would need perl an not-hungry regexp for that).
17 sed -ne 's!^.*\<\(UML_\)\?CONFIG_\([0-9A-Z_]\+\).*!\2 '$i'!p' < $i 17 sed -ne 's!^.*\<\(UML_\)\?CONFIG_\([0-9A-Za-z_]\+\).*!\2 '$i'!p' < $i
18done | \ 18done | \
19# Smart "sort|uniq" implemented in awk and tuned to collect the names of all 19# Smart "sort|uniq" implemented in awk and tuned to collect the names of all
20# files which use a given symbol 20# files which use a given symbol
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index bd88f11b0953..90b54d4697fd 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2,7 +2,7 @@
2# (c) 2001, Dave Jones. (the file handling bit) 2# (c) 2001, Dave Jones. (the file handling bit)
3# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) 3# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
4# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) 4# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
5# (c) 2008,2009, Andy Whitcroft <apw@canonical.com> 5# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
6# Licensed under the terms of the GNU GPL License version 2 6# Licensed under the terms of the GNU GPL License version 2
7 7
8use strict; 8use strict;
@@ -10,7 +10,7 @@ use strict;
10my $P = $0; 10my $P = $0;
11$P =~ s@.*/@@g; 11$P =~ s@.*/@@g;
12 12
13my $V = '0.30'; 13my $V = '0.31';
14 14
15use Getopt::Long qw(:config no_auto_abbrev); 15use Getopt::Long qw(:config no_auto_abbrev);
16 16
@@ -103,6 +103,8 @@ for my $key (keys %debug) {
103 die "$@" if ($@); 103 die "$@" if ($@);
104} 104}
105 105
106my $rpt_cleaners = 0;
107
106if ($terse) { 108if ($terse) {
107 $emacs = 1; 109 $emacs = 1;
108 $quiet++; 110 $quiet++;
@@ -150,6 +152,20 @@ our $Sparse = qr{
150# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check 152# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
151our $Attribute = qr{ 153our $Attribute = qr{
152 const| 154 const|
155 __percpu|
156 __nocast|
157 __safe|
158 __bitwise__|
159 __packed__|
160 __packed2__|
161 __naked|
162 __maybe_unused|
163 __always_unused|
164 __noreturn|
165 __used|
166 __cold|
167 __noclone|
168 __deprecated|
153 __read_mostly| 169 __read_mostly|
154 __kprobes| 170 __kprobes|
155 __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)| 171 __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
@@ -195,7 +211,7 @@ our $typeTypedefs = qr{(?x:
195our $logFunctions = qr{(?x: 211our $logFunctions = qr{(?x:
196 printk| 212 printk|
197 pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| 213 pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)|
198 dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| 214 (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
199 WARN| 215 WARN|
200 panic 216 panic
201)}; 217)};
@@ -224,6 +240,12 @@ our @modifierList = (
224 qr{fastcall}, 240 qr{fastcall},
225); 241);
226 242
243our $allowed_asm_includes = qr{(?x:
244 irq|
245 memory
246)};
247# memory.h: ARM has a custom one
248
227sub build_types { 249sub build_types {
228 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; 250 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
229 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; 251 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
@@ -552,6 +574,9 @@ sub ctx_statement_block {
552 $type = ($level != 0)? '{' : ''; 574 $type = ($level != 0)? '{' : '';
553 575
554 if ($level == 0) { 576 if ($level == 0) {
577 if (substr($blk, $off + 1, 1) eq ';') {
578 $off++;
579 }
555 last; 580 last;
556 } 581 }
557 } 582 }
@@ -666,15 +691,15 @@ sub ctx_block_get {
666 $blk .= $rawlines[$line]; 691 $blk .= $rawlines[$line];
667 692
668 # Handle nested #if/#else. 693 # Handle nested #if/#else.
669 if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) { 694 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
670 push(@stack, $level); 695 push(@stack, $level);
671 } elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) { 696 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
672 $level = $stack[$#stack - 1]; 697 $level = $stack[$#stack - 1];
673 } elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) { 698 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
674 $level = pop(@stack); 699 $level = pop(@stack);
675 } 700 }
676 701
677 foreach my $c (split(//, $rawlines[$line])) { 702 foreach my $c (split(//, $lines[$line])) {
678 ##print "C<$c>L<$level><$open$close>O<$off>\n"; 703 ##print "C<$c>L<$level><$open$close>O<$off>\n";
679 if ($off > 0) { 704 if ($off > 0) {
680 $off--; 705 $off--;
@@ -834,7 +859,12 @@ sub annotate_values {
834 $av_preprocessor = 0; 859 $av_preprocessor = 0;
835 } 860 }
836 861
837 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\()/) { 862 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/) {
863 print "CAST($1)\n" if ($dbg_values > 1);
864 push(@av_paren_type, $type);
865 $type = 'C';
866
867 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
838 print "DECLARE($1)\n" if ($dbg_values > 1); 868 print "DECLARE($1)\n" if ($dbg_values > 1);
839 $type = 'T'; 869 $type = 'T';
840 870
@@ -1299,7 +1329,11 @@ sub process {
1299 $here = "#$realline: " if ($file); 1329 $here = "#$realline: " if ($file);
1300 1330
1301 # extract the filename as it passes 1331 # extract the filename as it passes
1302 if ($line=~/^\+\+\+\s+(\S+)/) { 1332 if ($line =~ /^diff --git.*?(\S+)$/) {
1333 $realfile = $1;
1334 $realfile =~ s@^([^/]*)/@@;
1335
1336 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1303 $realfile = $1; 1337 $realfile = $1;
1304 $realfile =~ s@^([^/]*)/@@; 1338 $realfile =~ s@^([^/]*)/@@;
1305 1339
@@ -1323,6 +1357,14 @@ sub process {
1323 1357
1324 $cnt_lines++ if ($realcnt != 0); 1358 $cnt_lines++ if ($realcnt != 0);
1325 1359
1360# Check for incorrect file permissions
1361 if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
1362 my $permhere = $here . "FILE: $realfile\n";
1363 if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
1364 ERROR("do not set execute permissions for source files\n" . $permhere);
1365 }
1366 }
1367
1326#check the patch for a signoff: 1368#check the patch for a signoff:
1327 if ($line =~ /^\s*signed-off-by:/i) { 1369 if ($line =~ /^\s*signed-off-by:/i) {
1328 # This is a signoff, if ugly, so do not double report. 1370 # This is a signoff, if ugly, so do not double report.
@@ -1380,21 +1422,38 @@ sub process {
1380 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { 1422 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1381 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1423 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1382 ERROR("trailing whitespace\n" . $herevet); 1424 ERROR("trailing whitespace\n" . $herevet);
1425 $rpt_cleaners = 1;
1383 } 1426 }
1384 1427
1385# check for Kconfig help text having a real description 1428# check for Kconfig help text having a real description
1429# Only applies when adding the entry originally, after that we do not have
1430# sufficient context to determine whether it is indeed long enough.
1386 if ($realfile =~ /Kconfig/ && 1431 if ($realfile =~ /Kconfig/ &&
1387 $line =~ /\+?\s*(---)?help(---)?$/) { 1432 $line =~ /\+\s*(?:---)?help(?:---)?$/) {
1388 my $length = 0; 1433 my $length = 0;
1389 for (my $l = $linenr; defined($lines[$l]); $l++) { 1434 my $cnt = $realcnt;
1390 my $f = $lines[$l]; 1435 my $ln = $linenr + 1;
1436 my $f;
1437 my $is_end = 0;
1438 while ($cnt > 0 && defined $lines[$ln - 1]) {
1439 $f = $lines[$ln - 1];
1440 $cnt-- if ($lines[$ln - 1] !~ /^-/);
1441 $is_end = $lines[$ln - 1] =~ /^\+/;
1442 $ln++;
1443
1444 next if ($f =~ /^-/);
1445 $f =~ s/^.//;
1391 $f =~ s/#.*//; 1446 $f =~ s/#.*//;
1392 $f =~ s/^\s+//; 1447 $f =~ s/^\s+//;
1393 next if ($f =~ /^$/); 1448 next if ($f =~ /^$/);
1394 last if ($f =~ /^\s*config\s/); 1449 if ($f =~ /^\s*config\s/) {
1450 $is_end = 1;
1451 last;
1452 }
1395 $length++; 1453 $length++;
1396 } 1454 }
1397 WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($length < 4); 1455 WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4);
1456 #print "is_end<$is_end> length<$length>\n";
1398 } 1457 }
1399 1458
1400# check we are in a valid source file if not then ignore this hunk 1459# check we are in a valid source file if not then ignore this hunk
@@ -1403,7 +1462,8 @@ sub process {
1403#80 column limit 1462#80 column limit
1404 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 1463 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
1405 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 1464 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
1406 $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && 1465 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ ||
1466 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
1407 $length > 80) 1467 $length > 80)
1408 { 1468 {
1409 WARN("line over 80 characters\n" . $herecurr); 1469 WARN("line over 80 characters\n" . $herecurr);
@@ -1440,6 +1500,7 @@ sub process {
1440 $rawline =~ /^\+\s* \s*/) { 1500 $rawline =~ /^\+\s* \s*/) {
1441 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1501 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1442 ERROR("code indent should use tabs where possible\n" . $herevet); 1502 ERROR("code indent should use tabs where possible\n" . $herevet);
1503 $rpt_cleaners = 1;
1443 } 1504 }
1444 1505
1445# check for space before tabs. 1506# check for space before tabs.
@@ -1448,6 +1509,16 @@ sub process {
1448 WARN("please, no space before tabs\n" . $herevet); 1509 WARN("please, no space before tabs\n" . $herevet);
1449 } 1510 }
1450 1511
1512# check for spaces at the beginning of a line.
1513# Exceptions:
1514# 1) within comments
1515# 2) indented preprocessor commands
1516# 3) hanging labels
1517 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
1518 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1519 WARN("please, no spaces at the start of a line\n" . $herevet);
1520 }
1521
1451# check we are in a valid C source file if not then ignore this hunk 1522# check we are in a valid C source file if not then ignore this hunk
1452 next if ($realfile !~ /\.(h|c)$/); 1523 next if ($realfile !~ /\.(h|c)$/);
1453 1524
@@ -1581,7 +1652,7 @@ sub process {
1581 1652
1582 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { 1653 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1583 ERROR("that open brace { should be on the previous line\n" . 1654 ERROR("that open brace { should be on the previous line\n" .
1584 "$here\n$ctx\n$lines[$ctx_ln - 1]\n"); 1655 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1585 } 1656 }
1586 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && 1657 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
1587 $ctx =~ /\)\s*\;\s*$/ && 1658 $ctx =~ /\)\s*\;\s*$/ &&
@@ -1590,7 +1661,7 @@ sub process {
1590 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); 1661 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
1591 if ($nindent > $indent) { 1662 if ($nindent > $indent) {
1592 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . 1663 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" .
1593 "$here\n$ctx\n$lines[$ctx_ln - 1]\n"); 1664 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1594 } 1665 }
1595 } 1666 }
1596 } 1667 }
@@ -1751,8 +1822,17 @@ sub process {
1751 !defined $suppress_export{$realline_next} && 1822 !defined $suppress_export{$realline_next} &&
1752 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || 1823 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
1753 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { 1824 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
1825 # Handle definitions which produce identifiers with
1826 # a prefix:
1827 # XXX(foo);
1828 # EXPORT_SYMBOL(something_foo);
1754 my $name = $1; 1829 my $name = $1;
1755 if ($stat !~ /(?: 1830 if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ &&
1831 $name =~ /^${Ident}_$2/) {
1832#print "FOO C name<$name>\n";
1833 $suppress_export{$realline_next} = 1;
1834
1835 } elsif ($stat !~ /(?:
1756 \n.}\s*$| 1836 \n.}\s*$|
1757 ^.DEFINE_$Ident\(\Q$name\E\)| 1837 ^.DEFINE_$Ident\(\Q$name\E\)|
1758 ^.DECLARE_$Ident\(\Q$name\E\)| 1838 ^.DECLARE_$Ident\(\Q$name\E\)|
@@ -1778,9 +1858,9 @@ sub process {
1778 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); 1858 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1779 } 1859 }
1780 1860
1781# check for external initialisers. 1861# check for global initialisers.
1782 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { 1862 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
1783 ERROR("do not initialise externals to 0 or NULL\n" . 1863 ERROR("do not initialise globals to 0 or NULL\n" .
1784 $herecurr); 1864 $herecurr);
1785 } 1865 }
1786# check for static initialisers. 1866# check for static initialisers.
@@ -1789,6 +1869,23 @@ sub process {
1789 $herecurr); 1869 $herecurr);
1790 } 1870 }
1791 1871
1872# check for static const char * arrays.
1873 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
1874 WARN("static const char * array should probably be static const char * const\n" .
1875 $herecurr);
1876 }
1877
1878# check for static char foo[] = "bar" declarations.
1879 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
1880 WARN("static char array declaration should probably be static const char\n" .
1881 $herecurr);
1882 }
1883
1884# check for declarations of struct pci_device_id
1885 if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) {
1886 WARN("Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr);
1887 }
1888
1792# check for new typedefs, only function parameters and sparse annotations 1889# check for new typedefs, only function parameters and sparse annotations
1793# make sense. 1890# make sense.
1794 if ($line =~ /\btypedef\s/ && 1891 if ($line =~ /\btypedef\s/ &&
@@ -1882,6 +1979,11 @@ sub process {
1882 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); 1979 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
1883 } 1980 }
1884 1981
1982# missing space after union, struct or enum definition
1983 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
1984 WARN("missing space after $1 definition\n" . $herecurr);
1985 }
1986
1885# check for spacing round square brackets; allowed: 1987# check for spacing round square brackets; allowed:
1886# 1. with a type on the left -- int [] a; 1988# 1. with a type on the left -- int [] a;
1887# 2. at the beginning of a line for slice initialisers -- [0...10] = 5, 1989# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
@@ -2159,21 +2261,29 @@ sub process {
2159 my $value = $2; 2261 my $value = $2;
2160 2262
2161 # Flatten any parentheses 2263 # Flatten any parentheses
2162 $value =~ s/\)\(/\) \(/g; 2264 $value =~ s/\(/ \(/g;
2265 $value =~ s/\)/\) /g;
2163 while ($value =~ s/\[[^\{\}]*\]/1/ || 2266 while ($value =~ s/\[[^\{\}]*\]/1/ ||
2164 $value !~ /(?:$Ident|-?$Constant)\s* 2267 $value !~ /(?:$Ident|-?$Constant)\s*
2165 $Compare\s* 2268 $Compare\s*
2166 (?:$Ident|-?$Constant)/x && 2269 (?:$Ident|-?$Constant)/x &&
2167 $value =~ s/\([^\(\)]*\)/1/) { 2270 $value =~ s/\([^\(\)]*\)/1/) {
2168 } 2271 }
2169 2272#print "value<$value>\n";
2170 if ($value =~ /^(?:$Ident|-?$Constant)$/) { 2273 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
2171 ERROR("return is not a function, parentheses are not required\n" . $herecurr); 2274 ERROR("return is not a function, parentheses are not required\n" . $herecurr);
2172 2275
2173 } elsif ($spacing !~ /\s+/) { 2276 } elsif ($spacing !~ /\s+/) {
2174 ERROR("space required before the open parenthesis '('\n" . $herecurr); 2277 ERROR("space required before the open parenthesis '('\n" . $herecurr);
2175 } 2278 }
2176 } 2279 }
2280# Return of what appears to be an errno should normally be -'ve
2281 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
2282 my $name = $1;
2283 if ($name ne 'EOF' && $name ne 'ERROR') {
2284 WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
2285 }
2286 }
2177 2287
2178# Need a space before open parenthesis after if, while etc 2288# Need a space before open parenthesis after if, while etc
2179 if ($line=~/\b(if|while|for|switch)\(/) { 2289 if ($line=~/\b(if|while|for|switch)\(/) {
@@ -2308,7 +2418,7 @@ sub process {
2308 my $checkfile = "include/linux/$file"; 2418 my $checkfile = "include/linux/$file";
2309 if (-f "$root/$checkfile" && 2419 if (-f "$root/$checkfile" &&
2310 $realfile ne $checkfile && 2420 $realfile ne $checkfile &&
2311 $1 ne 'irq') 2421 $1 !~ /$allowed_asm_includes/)
2312 { 2422 {
2313 if ($realfile =~ m{^arch/}) { 2423 if ($realfile =~ m{^arch/}) {
2314 CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 2424 CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
@@ -2392,8 +2502,8 @@ sub process {
2392 \.$Ident\s*=\s*| 2502 \.$Ident\s*=\s*|
2393 ^\"|\"$ 2503 ^\"|\"$
2394 }x; 2504 }x;
2395 #print "REST<$rest> dstat<$dstat>\n"; 2505 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
2396 if ($rest ne '') { 2506 if ($rest ne '' && $rest ne ',') {
2397 if ($rest !~ /while\s*\(/ && 2507 if ($rest !~ /while\s*\(/ &&
2398 $dstat !~ /$exceptions/) 2508 $dstat !~ /$exceptions/)
2399 { 2509 {
@@ -2570,6 +2680,21 @@ sub process {
2570 } 2680 }
2571 } 2681 }
2572 2682
2683# prefer usleep_range over udelay
2684 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
2685 # ignore udelay's < 10, however
2686 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
2687 CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
2688 }
2689 }
2690
2691# warn about unexpectedly long msleep's
2692 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
2693 if ($1 < 20) {
2694 WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
2695 }
2696 }
2697
2573# warn about #ifdefs in C files 2698# warn about #ifdefs in C files
2574# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { 2699# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
2575# print "#ifdef in C files should be avoided\n"; 2700# print "#ifdef in C files should be avoided\n";
@@ -2807,6 +2932,15 @@ sub process {
2807 print "\n" if ($quiet == 0); 2932 print "\n" if ($quiet == 0);
2808 } 2933 }
2809 2934
2935 if ($quiet == 0) {
2936 # If there were whitespace errors which cleanpatch can fix
2937 # then suggest that.
2938 if ($rpt_cleaners) {
2939 print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
2940 print " scripts/cleanfile\n\n";
2941 }
2942 }
2943
2810 if ($clean == 1 && $quiet == 0) { 2944 if ($clean == 1 && $quiet == 0) {
2811 print "$vname has no obvious style problems and is ready for submission.\n" 2945 print "$vname has no obvious style problems and is ready for submission.\n"
2812 } 2946 }
diff --git a/scripts/checksyscalls.sh b/scripts/checksyscalls.sh
index 66ad375612f2..6bb42e72e0e5 100755
--- a/scripts/checksyscalls.sh
+++ b/scripts/checksyscalls.sh
@@ -183,7 +183,6 @@ cat << EOF
183#define __IGNORE_ustat /* statfs */ 183#define __IGNORE_ustat /* statfs */
184#define __IGNORE_utime /* utimes */ 184#define __IGNORE_utime /* utimes */
185#define __IGNORE_vfork /* clone */ 185#define __IGNORE_vfork /* clone */
186#define __IGNORE_wait4 /* waitid */
187 186
188/* sync_file_range had a stupid ABI. Allow sync_file_range2 instead */ 187/* sync_file_range had a stupid ABI. Allow sync_file_range2 instead */
189#ifdef __NR_sync_file_range2 188#ifdef __NR_sync_file_range2
diff --git a/scripts/coccicheck b/scripts/coccicheck
new file mode 100755
index 000000000000..b8bcf1f7bed7
--- /dev/null
+++ b/scripts/coccicheck
@@ -0,0 +1,80 @@
1#!/bin/sh
2
3SPATCH="`which ${SPATCH:=spatch}`"
4
5if [ "$C" = "1" -o "$C" = "2" ]; then
6 ONLINE=1
7
8# This requires Coccinelle >= 0.2.3
9# FLAGS="-ignore_unknown_options -very_quiet"
10# OPTIONS=$*
11
12# Workaround for Coccinelle < 0.2.3
13 FLAGS="-I $srctree/include -very_quiet"
14 shift $(( $# - 1 ))
15 OPTIONS=$1
16else
17 ONLINE=0
18 FLAGS="-very_quiet"
19fi
20
21if [ ! -x "$SPATCH" ]; then
22 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
23 exit 1
24fi
25
26if [ "$MODE" = "" ] ; then
27 if [ "$ONLINE" = "0" ] ; then
28 echo 'You have not explicitly specify the mode to use. Fallback to "report".'
29 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
30 echo 'Available modes are: report, patch, context, org'
31 fi
32 MODE="report"
33fi
34
35if [ "$ONLINE" = "0" ] ; then
36 echo ''
37 echo 'Please check for false positives in the output before submitting a patch.'
38 echo 'When using "patch" mode, carefully review the patch before submitting it.'
39 echo ''
40fi
41
42coccinelle () {
43 COCCI="$1"
44
45 OPT=`grep "Option" $COCCI | cut -d':' -f2`
46
47# The option '-parse_cocci' can be used to syntaxically check the SmPL files.
48#
49# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
50
51 if [ "$ONLINE" = "0" ] ; then
52
53 FILE=`echo $COCCI | sed "s|$srctree/||"`
54
55 echo "Processing `basename $COCCI` with option(s) \"$OPT\""
56 echo 'Message example to submit a patch:'
57
58 sed -e '/\/\/\//!d' -e 's|^///||' $COCCI
59
60 echo ' The semantic patch that makes this change is available'
61 echo " in $FILE."
62 echo ''
63 echo ' More information about semantic patching is available at'
64 echo ' http://coccinelle.lip6.fr/'
65 echo ''
66
67 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT -dir $srctree || exit 1
68 else
69 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
70 fi
71
72}
73
74if [ "$COCCI" = "" ] ; then
75 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
76 coccinelle $f
77 done
78else
79 coccinelle $COCCI
80fi
diff --git a/scripts/coccinelle/alloc/drop_kmalloc_cast.cocci b/scripts/coccinelle/alloc/drop_kmalloc_cast.cocci
new file mode 100644
index 000000000000..7d4771d449c3
--- /dev/null
+++ b/scripts/coccinelle/alloc/drop_kmalloc_cast.cocci
@@ -0,0 +1,67 @@
1///
2/// Casting (void *) value returned by kmalloc is useless
3/// as mentioned in Documentation/CodingStyle, Chap 14.
4///
5// Confidence: High
6// Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2.
7// URL: http://coccinelle.lip6.fr/
8// Options: -no_includes -include_headers
9//
10// Keywords: kmalloc, kzalloc, kcalloc
11// Version min: < 2.6.12 kmalloc
12// Version min: < 2.6.12 kcalloc
13// Version min: 2.6.14 kzalloc
14//
15
16virtual context
17virtual patch
18virtual org
19virtual report
20
21//----------------------------------------------------------
22// For context mode
23//----------------------------------------------------------
24
25@depends on context@
26type T;
27@@
28
29* (T *)
30 \(kmalloc\|kzalloc\|kcalloc\)(...)
31
32//----------------------------------------------------------
33// For patch mode
34//----------------------------------------------------------
35
36@depends on patch@
37type T;
38@@
39
40- (T *)
41 \(kmalloc\|kzalloc\|kcalloc\)(...)
42
43//----------------------------------------------------------
44// For org and report mode
45//----------------------------------------------------------
46
47@r depends on org || report@
48type T;
49position p;
50@@
51
52 (T@p *)\(kmalloc\|kzalloc\|kcalloc\)(...)
53
54@script:python depends on org@
55p << r.p;
56t << r.T;
57@@
58
59coccilib.org.print_safe_todo(p[0], t)
60
61@script:python depends on report@
62p << r.p;
63t << r.T;
64@@
65
66msg="WARNING: casting value returned by k[cmz]alloc to (%s *) is useless." % (t)
67coccilib.report.print_report(p[0], msg)
diff --git a/scripts/coccinelle/alloc/kzalloc-simple.cocci b/scripts/coccinelle/alloc/kzalloc-simple.cocci
new file mode 100644
index 000000000000..2eae828fc657
--- /dev/null
+++ b/scripts/coccinelle/alloc/kzalloc-simple.cocci
@@ -0,0 +1,82 @@
1///
2/// kzalloc should be used rather than kmalloc followed by memset 0
3///
4// Confidence: High
5// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2.
6// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
8// Options: -no_includes -include_headers
9//
10// Keywords: kmalloc, kzalloc
11// Version min: < 2.6.12 kmalloc
12// Version min: 2.6.14 kzalloc
13//
14
15virtual context
16virtual patch
17virtual org
18virtual report
19
20//----------------------------------------------------------
21// For context mode
22//----------------------------------------------------------
23
24@depends on context@
25type T, T2;
26expression x;
27expression E1,E2;
28statement S;
29@@
30
31* x = (T)kmalloc(E1,E2);
32 if ((x==NULL) || ...) S
33* memset((T2)x,0,E1);
34
35//----------------------------------------------------------
36// For patch mode
37//----------------------------------------------------------
38
39@depends on patch@
40type T, T2;
41expression x;
42expression E1,E2;
43statement S;
44@@
45
46- x = (T)kmalloc(E1,E2);
47+ x = kzalloc(E1,E2);
48 if ((x==NULL) || ...) S
49- memset((T2)x,0,E1);
50
51//----------------------------------------------------------
52// For org mode
53//----------------------------------------------------------
54
55@r depends on org || report@
56type T, T2;
57expression x;
58expression E1,E2;
59statement S;
60position p;
61@@
62
63 x = (T)kmalloc@p(E1,E2);
64 if ((x==NULL) || ...) S
65 memset((T2)x,0,E1);
66
67@script:python depends on org@
68p << r.p;
69x << r.x;
70@@
71
72msg="%s" % (x)
73msg_safe=msg.replace("[","@(").replace("]",")")
74coccilib.org.print_todo(p[0], msg_safe)
75
76@script:python depends on report@
77p << r.p;
78x << r.x;
79@@
80
81msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x)
82coccilib.report.print_report(p[0], msg)
diff --git a/scripts/coccinelle/deref_null.cocci b/scripts/coccinelle/deref_null.cocci
new file mode 100644
index 000000000000..9969d76d0f4b
--- /dev/null
+++ b/scripts/coccinelle/deref_null.cocci
@@ -0,0 +1,293 @@
1///
2/// A variable is dereference under a NULL test.
3/// Even though it is know to be NULL.
4///
5// Confidence: Moderate
6// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
7// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/
10// Comments: -I ... -all_includes can give more complete results
11// Options:
12
13virtual context
14virtual patch
15virtual org
16virtual report
17
18@initialize:python depends on !context && patch && !org && !report@
19
20import sys
21print >> sys.stderr, "This semantic patch does not support the 'patch' mode."
22
23@depends on patch@
24@@
25
26this_rule_should_never_matches();
27
28@ifm depends on !patch@
29expression *E;
30statement S1,S2;
31position p1;
32@@
33
34if@p1 ((E == NULL && ...) || ...) S1 else S2
35
36// The following two rules are separate, because both can match a single
37// expression in different ways
38@pr1 depends on !patch expression@
39expression *ifm.E;
40identifier f;
41position p1;
42@@
43
44 (E != NULL && ...) ? <+...E->f@p1...+> : ...
45
46@pr2 depends on !patch expression@
47expression *ifm.E;
48identifier f;
49position p2;
50@@
51
52(
53 (E != NULL) && ... && <+...E->f@p2...+>
54|
55 (E == NULL) || ... || <+...E->f@p2...+>
56|
57 sizeof(<+...E->f@p2...+>)
58)
59
60// For org and report modes
61
62@r depends on !context && !patch && (org || report) exists@
63expression subE <= ifm.E;
64expression *ifm.E;
65expression E1,E2;
66identifier f;
67statement S1,S2,S3,S4;
68iterator iter;
69position p!={pr1.p1,pr2.p2};
70position ifm.p1;
71@@
72
73if@p1 ((E == NULL && ...) || ...)
74{
75 ... when != if (...) S1 else S2
76(
77 iter(subE,...) S4 // no use
78|
79 list_remove_head(E2,subE,...)
80|
81 subE = E1
82|
83 for(subE = E1;...;...) S4
84|
85 subE++
86|
87 ++subE
88|
89 --subE
90|
91 subE--
92|
93 &subE
94|
95 E->f@p // bad use
96)
97 ... when any
98 return ...;
99}
100else S3
101
102@script:python depends on !context && !patch && !org && report@
103p << r.p;
104p1 << ifm.p1;
105x << ifm.E;
106@@
107
108msg="ERROR: %s is NULL but dereferenced." % (x)
109coccilib.report.print_report(p[0], msg)
110cocci.include_match(False)
111
112@script:python depends on !context && !patch && org && !report@
113p << r.p;
114p1 << ifm.p1;
115x << ifm.E;
116@@
117
118msg="ERROR: %s is NULL but dereferenced." % (x)
119msg_safe=msg.replace("[","@(").replace("]",")")
120cocci.print_main(msg_safe,p)
121cocci.include_match(False)
122
123@s depends on !context && !patch && (org || report) exists@
124expression subE <= ifm.E;
125expression *ifm.E;
126expression E1,E2;
127identifier f;
128statement S1,S2,S3,S4;
129iterator iter;
130position p!={pr1.p1,pr2.p2};
131position ifm.p1;
132@@
133
134if@p1 ((E == NULL && ...) || ...)
135{
136 ... when != if (...) S1 else S2
137(
138 iter(subE,...) S4 // no use
139|
140 list_remove_head(E2,subE,...)
141|
142 subE = E1
143|
144 for(subE = E1;...;...) S4
145|
146 subE++
147|
148 ++subE
149|
150 --subE
151|
152 subE--
153|
154 &subE
155|
156 E->f@p // bad use
157)
158 ... when any
159}
160else S3
161
162@script:python depends on !context && !patch && !org && report@
163p << s.p;
164p1 << ifm.p1;
165x << ifm.E;
166@@
167
168msg="ERROR: %s is NULL but dereferenced." % (x)
169coccilib.report.print_report(p[0], msg)
170
171@script:python depends on !context && !patch && org && !report@
172p << s.p;
173p1 << ifm.p1;
174x << ifm.E;
175@@
176
177msg="ERROR: %s is NULL but dereferenced." % (x)
178msg_safe=msg.replace("[","@(").replace("]",")")
179cocci.print_main(msg_safe,p)
180
181// For context mode
182
183@depends on context && !patch && !org && !report exists@
184expression subE <= ifm.E;
185expression *ifm.E;
186expression E1,E2;
187identifier f;
188statement S1,S2,S3,S4;
189iterator iter;
190position p!={pr1.p1,pr2.p2};
191position ifm.p1;
192@@
193
194if@p1 ((E == NULL && ...) || ...)
195{
196 ... when != if (...) S1 else S2
197(
198 iter(subE,...) S4 // no use
199|
200 list_remove_head(E2,subE,...)
201|
202 subE = E1
203|
204 for(subE = E1;...;...) S4
205|
206 subE++
207|
208 ++subE
209|
210 --subE
211|
212 subE--
213|
214 &subE
215|
216* E->f@p // bad use
217)
218 ... when any
219 return ...;
220}
221else S3
222
223// The following three rules are duplicates of ifm, pr1 and pr2 respectively.
224// It is need because the previous rule as already made a "change".
225
226@ifm1 depends on !patch@
227expression *E;
228statement S1,S2;
229position p1;
230@@
231
232if@p1 ((E == NULL && ...) || ...) S1 else S2
233
234@pr11 depends on !patch expression@
235expression *ifm1.E;
236identifier f;
237position p1;
238@@
239
240 (E != NULL && ...) ? <+...E->f@p1...+> : ...
241
242@pr12 depends on !patch expression@
243expression *ifm1.E;
244identifier f;
245position p2;
246@@
247
248(
249 (E != NULL) && ... && <+...E->f@p2...+>
250|
251 (E == NULL) || ... || <+...E->f@p2...+>
252|
253 sizeof(<+...E->f@p2...+>)
254)
255
256@depends on context && !patch && !org && !report exists@
257expression subE <= ifm1.E;
258expression *ifm1.E;
259expression E1,E2;
260identifier f;
261statement S1,S2,S3,S4;
262iterator iter;
263position p!={pr11.p1,pr12.p2};
264position ifm1.p1;
265@@
266
267if@p1 ((E == NULL && ...) || ...)
268{
269 ... when != if (...) S1 else S2
270(
271 iter(subE,...) S4 // no use
272|
273 list_remove_head(E2,subE,...)
274|
275 subE = E1
276|
277 for(subE = E1;...;...) S4
278|
279 subE++
280|
281 ++subE
282|
283 --subE
284|
285 subE--
286|
287 &subE
288|
289* E->f@p // bad use
290)
291 ... when any
292}
293else S3
diff --git a/scripts/coccinelle/err_cast.cocci b/scripts/coccinelle/err_cast.cocci
new file mode 100644
index 000000000000..2ce115000af6
--- /dev/null
+++ b/scripts/coccinelle/err_cast.cocci
@@ -0,0 +1,56 @@
1///
2/// Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...))
3///
4// Confidence: High
5// Copyright: (C) 2009, 2010 Nicolas Palix, DIKU. GPLv2.
6// Copyright: (C) 2009, 2010 Julia Lawall, DIKU. GPLv2.
7// Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/
9// Options:
10//
11// Keywords: ERR_PTR, PTR_ERR, ERR_CAST
12// Version min: 2.6.25
13//
14
15virtual context
16virtual patch
17virtual org
18virtual report
19
20
21@ depends on context && !patch && !org && !report@
22expression x;
23@@
24
25* ERR_PTR(PTR_ERR(x))
26
27@ depends on !context && patch && !org && !report @
28expression x;
29@@
30
31- ERR_PTR(PTR_ERR(x))
32+ ERR_CAST(x)
33
34@r depends on !context && !patch && (org || report)@
35expression x;
36position p;
37@@
38
39 ERR_PTR@p(PTR_ERR(x))
40
41@script:python depends on org@
42p << r.p;
43x << r.x;
44@@
45
46msg="WARNING ERR_CAST can be used with %s" % (x)
47msg_safe=msg.replace("[","@(").replace("]",")")
48coccilib.org.print_todo(p[0], msg_safe)
49
50@script:python depends on report@
51p << r.p;
52x << r.x;
53@@
54
55msg="WARNING: ERR_CAST can be used with %s" % (x)
56coccilib.report.print_report(p[0], msg)
diff --git a/scripts/coccinelle/resource_size.cocci b/scripts/coccinelle/resource_size.cocci
new file mode 100644
index 000000000000..1935a58b39d9
--- /dev/null
+++ b/scripts/coccinelle/resource_size.cocci
@@ -0,0 +1,93 @@
1///
2/// Use resource_size function on resource object
3/// instead of explicit computation.
4///
5// Confidence: High
6// Copyright: (C) 2009, 2010 Nicolas Palix, DIKU. GPLv2.
7// Copyright: (C) 2009, 2010 Julia Lawall, DIKU. GPLv2.
8// Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/
10// Options:
11//
12// Keywords: resource_size
13// Version min: 2.6.27 resource_size
14//
15
16virtual context
17virtual patch
18virtual org
19virtual report
20
21//----------------------------------------------------------
22// For context mode
23//----------------------------------------------------------
24
25@r_context depends on context && !patch && !org@
26struct resource *res;
27@@
28
29* (res->end - res->start) + 1
30
31//----------------------------------------------------------
32// For patch mode
33//----------------------------------------------------------
34
35@r_patch depends on !context && patch && !org@
36struct resource *res;
37@@
38
39- (res->end - res->start) + 1
40+ resource_size(res)
41
42//----------------------------------------------------------
43// For org mode
44//----------------------------------------------------------
45
46
47@r_org depends on !context && !patch && (org || report)@
48struct resource *res;
49position p;
50@@
51
52 (res->end@p - res->start) + 1
53
54@rbad_org depends on !context && !patch && (org || report)@
55struct resource *res;
56position p != r_org.p;
57@@
58
59 res->end@p - res->start
60
61@script:python depends on org@
62p << r_org.p;
63x << r_org.res;
64@@
65
66msg="ERROR with %s" % (x)
67msg_safe=msg.replace("[","@(").replace("]",")")
68coccilib.org.print_todo(p[0], msg_safe)
69
70@script:python depends on report@
71p << r_org.p;
72x << r_org.res;
73@@
74
75msg="ERROR: Missing resource_size with %s" % (x)
76coccilib.report.print_report(p[0], msg)
77
78@script:python depends on org@
79p << rbad_org.p;
80x << rbad_org.res;
81@@
82
83msg="WARNING with %s" % (x)
84msg_safe=msg.replace("[","@(").replace("]",")")
85coccilib.org.print_todo(p[0], msg_safe)
86
87@script:python depends on report@
88p << rbad_org.p;
89x << rbad_org.res;
90@@
91
92msg="WARNING: Suspicious code. resource_size is maybe missing with %s" % (x)
93coccilib.report.print_report(p[0], msg)
diff --git a/scripts/decodecode b/scripts/decodecode
index 8b30cc36744f..18ba881c3415 100755
--- a/scripts/decodecode
+++ b/scripts/decodecode
@@ -40,7 +40,7 @@ echo $code
40code=`echo $code | sed -e 's/.*Code: //'` 40code=`echo $code | sed -e 's/.*Code: //'`
41 41
42width=`expr index "$code" ' '` 42width=`expr index "$code" ' '`
43width=$[($width-1)/2] 43width=$((($width-1)/2))
44case $width in 44case $width in
451) type=byte ;; 451) type=byte ;;
462) type=2byte ;; 462) type=2byte ;;
@@ -48,10 +48,10 @@ case $width in
48esac 48esac
49 49
50disas() { 50disas() {
51 ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s &> /dev/null 51 ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1
52 52
53 if [ "$ARCH" == "arm" ]; then 53 if [ "$ARCH" = "arm" ]; then
54 if [ $width == 2 ]; then 54 if [ $width -eq 2 ]; then
55 OBJDUMPFLAGS="-M force-thumb" 55 OBJDUMPFLAGS="-M force-thumb"
56 fi 56 fi
57 57
@@ -59,7 +59,7 @@ disas() {
59 fi 59 fi
60 60
61 ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \ 61 ${CROSS_COMPILE}objdump $OBJDUMPFLAGS -S $1.o | \
62 grep -v "/tmp\|Disassembly\|\.text\|^$" &> $1.dis 62 grep -v "/tmp\|Disassembly\|\.text\|^$" > $1.dis 2>&1
63} 63}
64 64
65marker=`expr index "$code" "\<"` 65marker=`expr index "$code" "\<"`
diff --git a/scripts/dtc/fstree.c b/scripts/dtc/fstree.c
index 766b2694d935..8fe1bdf239f0 100644
--- a/scripts/dtc/fstree.c
+++ b/scripts/dtc/fstree.c
@@ -77,6 +77,7 @@ static struct node *read_fstree(const char *dirname)
77 free(tmpnam); 77 free(tmpnam);
78 } 78 }
79 79
80 closedir(d);
80 return tree; 81 return tree;
81} 82}
82 83
diff --git a/scripts/gcc-goto.sh b/scripts/gcc-goto.sh
new file mode 100644
index 000000000000..520d16b1ffaf
--- /dev/null
+++ b/scripts/gcc-goto.sh
@@ -0,0 +1,5 @@
1#!/bin/sh
2# Test for gcc 'asm goto' suport
3# Copyright (C) 2010, Jason Baron <jbaron@redhat.com>
4
5echo "int main(void) { entry: asm goto (\"\"::::entry); return 0; }" | $@ -x c - -c -o /dev/null >/dev/null 2>&1 && echo "y"
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index b2281982f52f..d21ec3a89603 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -13,7 +13,7 @@
13use strict; 13use strict;
14 14
15my $P = $0; 15my $P = $0;
16my $V = '0.24'; 16my $V = '0.26-beta6';
17 17
18use Getopt::Long qw(:config no_auto_abbrev); 18use Getopt::Long qw(:config no_auto_abbrev);
19 19
@@ -24,15 +24,19 @@ my $email_maintainer = 1;
24my $email_list = 1; 24my $email_list = 1;
25my $email_subscriber_list = 0; 25my $email_subscriber_list = 0;
26my $email_git_penguin_chiefs = 0; 26my $email_git_penguin_chiefs = 0;
27my $email_git = 1; 27my $email_git = 0;
28my $email_git_all_signature_types = 0; 28my $email_git_all_signature_types = 0;
29my $email_git_blame = 0; 29my $email_git_blame = 0;
30my $email_git_blame_signatures = 1;
31my $email_git_fallback = 1;
30my $email_git_min_signatures = 1; 32my $email_git_min_signatures = 1;
31my $email_git_max_maintainers = 5; 33my $email_git_max_maintainers = 5;
32my $email_git_min_percent = 5; 34my $email_git_min_percent = 5;
33my $email_git_since = "1-year-ago"; 35my $email_git_since = "1-year-ago";
34my $email_hg_since = "-365"; 36my $email_hg_since = "-365";
37my $interactive = 0;
35my $email_remove_duplicates = 1; 38my $email_remove_duplicates = 1;
39my $email_use_mailmap = 1;
36my $output_multiline = 1; 40my $output_multiline = 1;
37my $output_separator = ", "; 41my $output_separator = ", ";
38my $output_roles = 0; 42my $output_roles = 0;
@@ -49,8 +53,13 @@ my $pattern_depth = 0;
49my $version = 0; 53my $version = 0;
50my $help = 0; 54my $help = 0;
51 55
56my $vcs_used = 0;
57
52my $exit = 0; 58my $exit = 0;
53 59
60my %commit_author_hash;
61my %commit_signer_hash;
62
54my @penguin_chief = (); 63my @penguin_chief = ();
55push(@penguin_chief, "Linus Torvalds:torvalds\@linux-foundation.org"); 64push(@penguin_chief, "Linus Torvalds:torvalds\@linux-foundation.org");
56#Andrew wants in on most everything - 2009/01/14 65#Andrew wants in on most everything - 2009/01/14
@@ -73,7 +82,6 @@ my @signature_tags = ();
73push(@signature_tags, "Signed-off-by:"); 82push(@signature_tags, "Signed-off-by:");
74push(@signature_tags, "Reviewed-by:"); 83push(@signature_tags, "Reviewed-by:");
75push(@signature_tags, "Acked-by:"); 84push(@signature_tags, "Acked-by:");
76my $signaturePattern = "\(" . join("|", @signature_tags) . "\)";
77 85
78# rfc822 email address - preloaded methods go here. 86# rfc822 email address - preloaded methods go here.
79my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; 87my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
@@ -86,31 +94,70 @@ my %VCS_cmds;
86my %VCS_cmds_git = ( 94my %VCS_cmds_git = (
87 "execute_cmd" => \&git_execute_cmd, 95 "execute_cmd" => \&git_execute_cmd,
88 "available" => '(which("git") ne "") && (-d ".git")', 96 "available" => '(which("git") ne "") && (-d ".git")',
89 "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file", 97 "find_signers_cmd" =>
90 "find_commit_signers_cmd" => "git log --no-color -1 \$commit", 98 "git log --no-color --since=\$email_git_since " .
99 '--format="GitCommit: %H%n' .
100 'GitAuthor: %an <%ae>%n' .
101 'GitDate: %aD%n' .
102 'GitSubject: %s%n' .
103 '%b%n"' .
104 " -- \$file",
105 "find_commit_signers_cmd" =>
106 "git log --no-color " .
107 '--format="GitCommit: %H%n' .
108 'GitAuthor: %an <%ae>%n' .
109 'GitDate: %aD%n' .
110 'GitSubject: %s%n' .
111 '%b%n"' .
112 " -1 \$commit",
113 "find_commit_author_cmd" =>
114 "git log --no-color " .
115 '--format="GitCommit: %H%n' .
116 'GitAuthor: %an <%ae>%n' .
117 'GitDate: %aD%n' .
118 'GitSubject: %s%n"' .
119 " -1 \$commit",
91 "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file", 120 "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
92 "blame_file_cmd" => "git blame -l \$file", 121 "blame_file_cmd" => "git blame -l \$file",
93 "commit_pattern" => "^commit [0-9a-f]{40,40}", 122 "commit_pattern" => "^GitCommit: ([0-9a-f]{40,40})",
94 "blame_commit_pattern" => "^([0-9a-f]+) " 123 "blame_commit_pattern" => "^([0-9a-f]+) ",
124 "author_pattern" => "^GitAuthor: (.*)",
125 "subject_pattern" => "^GitSubject: (.*)",
95); 126);
96 127
97my %VCS_cmds_hg = ( 128my %VCS_cmds_hg = (
98 "execute_cmd" => \&hg_execute_cmd, 129 "execute_cmd" => \&hg_execute_cmd,
99 "available" => '(which("hg") ne "") && (-d ".hg")', 130 "available" => '(which("hg") ne "") && (-d ".hg")',
100 "find_signers_cmd" => 131 "find_signers_cmd" =>
101 "hg log --date=\$email_hg_since" . 132 "hg log --date=\$email_hg_since " .
102 " --template='commit {node}\\n{desc}\\n' -- \$file", 133 "--template='HgCommit: {node}\\n" .
103 "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit", 134 "HgAuthor: {author}\\n" .
135 "HgSubject: {desc}\\n'" .
136 " -- \$file",
137 "find_commit_signers_cmd" =>
138 "hg log " .
139 "--template='HgSubject: {desc}\\n'" .
140 " -r \$commit",
141 "find_commit_author_cmd" =>
142 "hg log " .
143 "--template='HgCommit: {node}\\n" .
144 "HgAuthor: {author}\\n" .
145 "HgSubject: {desc|firstline}\\n'" .
146 " -r \$commit",
104 "blame_range_cmd" => "", # not supported 147 "blame_range_cmd" => "", # not supported
105 "blame_file_cmd" => "hg blame -c \$file", 148 "blame_file_cmd" => "hg blame -n \$file",
106 "commit_pattern" => "^commit [0-9a-f]{40,40}", 149 "commit_pattern" => "^HgCommit: ([0-9a-f]{40,40})",
107 "blame_commit_pattern" => "^([0-9a-f]+):" 150 "blame_commit_pattern" => "^([ 0-9a-f]+):",
151 "author_pattern" => "^HgAuthor: (.*)",
152 "subject_pattern" => "^HgSubject: (.*)",
108); 153);
109 154
110if (-f "${lk_path}.get_maintainer.conf") { 155my $conf = which_conf(".get_maintainer.conf");
156if (-f $conf) {
111 my @conf_args; 157 my @conf_args;
112 open(my $conffile, '<', "${lk_path}.get_maintainer.conf") 158 open(my $conffile, '<', "$conf")
113 or warn "$P: Can't open .get_maintainer.conf: $!\n"; 159 or warn "$P: Can't find a readable .get_maintainer.conf file $!\n";
160
114 while (<$conffile>) { 161 while (<$conffile>) {
115 my $line = $_; 162 my $line = $_;
116 163
@@ -136,13 +183,17 @@ if (!GetOptions(
136 'git!' => \$email_git, 183 'git!' => \$email_git,
137 'git-all-signature-types!' => \$email_git_all_signature_types, 184 'git-all-signature-types!' => \$email_git_all_signature_types,
138 'git-blame!' => \$email_git_blame, 185 'git-blame!' => \$email_git_blame,
186 'git-blame-signatures!' => \$email_git_blame_signatures,
187 'git-fallback!' => \$email_git_fallback,
139 'git-chief-penguins!' => \$email_git_penguin_chiefs, 188 'git-chief-penguins!' => \$email_git_penguin_chiefs,
140 'git-min-signatures=i' => \$email_git_min_signatures, 189 'git-min-signatures=i' => \$email_git_min_signatures,
141 'git-max-maintainers=i' => \$email_git_max_maintainers, 190 'git-max-maintainers=i' => \$email_git_max_maintainers,
142 'git-min-percent=i' => \$email_git_min_percent, 191 'git-min-percent=i' => \$email_git_min_percent,
143 'git-since=s' => \$email_git_since, 192 'git-since=s' => \$email_git_since,
144 'hg-since=s' => \$email_hg_since, 193 'hg-since=s' => \$email_hg_since,
194 'i|interactive!' => \$interactive,
145 'remove-duplicates!' => \$email_remove_duplicates, 195 'remove-duplicates!' => \$email_remove_duplicates,
196 'mailmap!' => \$email_use_mailmap,
146 'm!' => \$email_maintainer, 197 'm!' => \$email_maintainer,
147 'n!' => \$email_usename, 198 'n!' => \$email_usename,
148 'l!' => \$email_list, 199 'l!' => \$email_list,
@@ -181,13 +232,9 @@ if (-t STDIN && !@ARGV) {
181 die "$P: missing patchfile or -f file - use --help if necessary\n"; 232 die "$P: missing patchfile or -f file - use --help if necessary\n";
182} 233}
183 234
184if ($output_separator ne ", ") { 235$output_multiline = 0 if ($output_separator ne ", ");
185 $output_multiline = 0; 236$output_rolestats = 1 if ($interactive);
186} 237$output_roles = 1 if ($output_rolestats);
187
188if ($output_rolestats) {
189 $output_roles = 1;
190}
191 238
192if ($sections) { 239if ($sections) {
193 $email = 0; 240 $email = 0;
@@ -197,6 +244,7 @@ if ($sections) {
197 $subsystem = 0; 244 $subsystem = 0;
198 $web = 0; 245 $web = 0;
199 $keywords = 0; 246 $keywords = 0;
247 $interactive = 0;
200} else { 248} else {
201 my $selections = $email + $scm + $status + $subsystem + $web; 249 my $selections = $email + $scm + $status + $subsystem + $web;
202 if ($selections == 0) { 250 if ($selections == 0) {
@@ -215,10 +263,6 @@ if (!top_of_kernel_tree($lk_path)) {
215 . "a linux kernel source tree.\n"; 263 . "a linux kernel source tree.\n";
216} 264}
217 265
218if ($email_git_all_signature_types) {
219 $signaturePattern = "(.+?)[Bb][Yy]:";
220}
221
222## Read MAINTAINERS for type/value pairs 266## Read MAINTAINERS for type/value pairs
223 267
224my @typevalue = (); 268my @typevalue = ();
@@ -253,31 +297,82 @@ while (<$maint>) {
253} 297}
254close($maint); 298close($maint);
255 299
256my %mailmap;
257 300
258if ($email_remove_duplicates) { 301#
259 open(my $mailmap, '<', "${lk_path}.mailmap") 302# Read mail address map
260 or warn "$P: Can't open .mailmap: $!\n"; 303#
261 while (<$mailmap>) {
262 my $line = $_;
263 304
264 next if ($line =~ m/^\s*#/); 305my $mailmap;
265 next if ($line =~ m/^\s*$/);
266 306
267 my ($name, $address) = parse_email($line); 307read_mailmap();
268 $line = format_email($name, $address, $email_usename);
269 308
270 next if ($line =~ m/^\s*$/); 309sub read_mailmap {
310 $mailmap = {
311 names => {},
312 addresses => {}
313 };
271 314
272 if (exists($mailmap{$name})) { 315 return if (!$email_use_mailmap || !(-f "${lk_path}.mailmap"));
273 my $obj = $mailmap{$name}; 316
274 push(@$obj, $address); 317 open(my $mailmap_file, '<', "${lk_path}.mailmap")
275 } else { 318 or warn "$P: Can't open .mailmap: $!\n";
276 my @arr = ($address); 319
277 $mailmap{$name} = \@arr; 320 while (<$mailmap_file>) {
321 s/#.*$//; #strip comments
322 s/^\s+|\s+$//g; #trim
323
324 next if (/^\s*$/); #skip empty lines
325 #entries have one of the following formats:
326 # name1 <mail1>
327 # <mail1> <mail2>
328 # name1 <mail1> <mail2>
329 # name1 <mail1> name2 <mail2>
330 # (see man git-shortlog)
331 if (/^(.+)<(.+)>$/) {
332 my $real_name = $1;
333 my $address = $2;
334
335 $real_name =~ s/\s+$//;
336 ($real_name, $address) = parse_email("$real_name <$address>");
337 $mailmap->{names}->{$address} = $real_name;
338
339 } elsif (/^<([^\s]+)>\s*<([^\s]+)>$/) {
340 my $real_address = $1;
341 my $wrong_address = $2;
342
343 $mailmap->{addresses}->{$wrong_address} = $real_address;
344
345 } elsif (/^(.+)<([^\s]+)>\s*<([^\s]+)>$/) {
346 my $real_name = $1;
347 my $real_address = $2;
348 my $wrong_address = $3;
349
350 $real_name =~ s/\s+$//;
351 ($real_name, $real_address) =
352 parse_email("$real_name <$real_address>");
353 $mailmap->{names}->{$wrong_address} = $real_name;
354 $mailmap->{addresses}->{$wrong_address} = $real_address;
355
356 } elsif (/^(.+)<([^\s]+)>\s*([^\s].*)<([^\s]+)>$/) {
357 my $real_name = $1;
358 my $real_address = $2;
359 my $wrong_name = $3;
360 my $wrong_address = $4;
361
362 $real_name =~ s/\s+$//;
363 ($real_name, $real_address) =
364 parse_email("$real_name <$real_address>");
365
366 $wrong_name =~ s/\s+$//;
367 ($wrong_name, $wrong_address) =
368 parse_email("$wrong_name <$wrong_address>");
369
370 my $wrong_email = format_email($wrong_name, $wrong_address, 1);
371 $mailmap->{names}->{$wrong_email} = $real_name;
372 $mailmap->{addresses}->{$wrong_email} = $real_address;
278 } 373 }
279 } 374 }
280 close($mailmap); 375 close($mailmap_file);
281} 376}
282 377
283## use the filenames on the command line or find the filenames in the patchfiles 378## use the filenames on the command line or find the filenames in the patchfiles
@@ -302,7 +397,7 @@ foreach my $file (@ARGV) {
302 } 397 }
303 if ($from_filename) { 398 if ($from_filename) {
304 push(@files, $file); 399 push(@files, $file);
305 if (-f $file && ($keywords || $file_emails)) { 400 if ($file ne "MAINTAINERS" && -f $file && ($keywords || $file_emails)) {
306 open(my $f, '<', $file) 401 open(my $f, '<', $file)
307 or die "$P: Can't open $file: $!\n"; 402 or die "$P: Can't open $file: $!\n";
308 my $text = do { local($/) ; <$f> }; 403 my $text = do { local($/) ; <$f> };
@@ -357,67 +452,127 @@ foreach my $file (@ARGV) {
357 452
358@file_emails = uniq(@file_emails); 453@file_emails = uniq(@file_emails);
359 454
455my %email_hash_name;
456my %email_hash_address;
360my @email_to = (); 457my @email_to = ();
458my %hash_list_to;
361my @list_to = (); 459my @list_to = ();
362my @scm = (); 460my @scm = ();
363my @web = (); 461my @web = ();
364my @subsystem = (); 462my @subsystem = ();
365my @status = (); 463my @status = ();
464my %deduplicate_name_hash = ();
465my %deduplicate_address_hash = ();
466my $signature_pattern;
366 467
367# Find responsible parties 468my @maintainers = get_maintainers();
368 469
369foreach my $file (@files) { 470if (@maintainers) {
471 @maintainers = merge_email(@maintainers);
472 output(@maintainers);
473}
370 474
371 my %hash; 475if ($scm) {
372 my $tvi = find_first_section(); 476 @scm = uniq(@scm);
373 while ($tvi < @typevalue) { 477 output(@scm);
374 my $start = find_starting_index($tvi); 478}
375 my $end = find_ending_index($tvi); 479
376 my $exclude = 0; 480if ($status) {
377 my $i; 481 @status = uniq(@status);
378 482 output(@status);
379 #Do not match excluded file patterns 483}
380 484
381 for ($i = $start; $i < $end; $i++) { 485if ($subsystem) {
382 my $line = $typevalue[$i]; 486 @subsystem = uniq(@subsystem);
383 if ($line =~ m/^(\C):\s*(.*)/) { 487 output(@subsystem);
384 my $type = $1; 488}
385 my $value = $2; 489
386 if ($type eq 'X') { 490if ($web) {
387 if (file_match_pattern($file, $value)) { 491 @web = uniq(@web);
388 $exclude = 1; 492 output(@web);
389 last; 493}
390 } 494
391 } 495exit($exit);
392 } 496
393 } 497sub get_maintainers {
498 %email_hash_name = ();
499 %email_hash_address = ();
500 %commit_author_hash = ();
501 %commit_signer_hash = ();
502 @email_to = ();
503 %hash_list_to = ();
504 @list_to = ();
505 @scm = ();
506 @web = ();
507 @subsystem = ();
508 @status = ();
509 %deduplicate_name_hash = ();
510 %deduplicate_address_hash = ();
511 if ($email_git_all_signature_types) {
512 $signature_pattern = "(.+?)[Bb][Yy]:";
513 } else {
514 $signature_pattern = "\(" . join("|", @signature_tags) . "\)";
515 }
516
517 # Find responsible parties
518
519 my %exact_pattern_match_hash = ();
520
521 foreach my $file (@files) {
522
523 my %hash;
524 my $tvi = find_first_section();
525 while ($tvi < @typevalue) {
526 my $start = find_starting_index($tvi);
527 my $end = find_ending_index($tvi);
528 my $exclude = 0;
529 my $i;
530
531 #Do not match excluded file patterns
394 532
395 if (!$exclude) {
396 for ($i = $start; $i < $end; $i++) { 533 for ($i = $start; $i < $end; $i++) {
397 my $line = $typevalue[$i]; 534 my $line = $typevalue[$i];
398 if ($line =~ m/^(\C):\s*(.*)/) { 535 if ($line =~ m/^(\C):\s*(.*)/) {
399 my $type = $1; 536 my $type = $1;
400 my $value = $2; 537 my $value = $2;
401 if ($type eq 'F') { 538 if ($type eq 'X') {
402 if (file_match_pattern($file, $value)) { 539 if (file_match_pattern($file, $value)) {
403 my $value_pd = ($value =~ tr@/@@); 540 $exclude = 1;
404 my $file_pd = ($file =~ tr@/@@); 541 last;
405 $value_pd++ if (substr($value,-1,1) ne "/"); 542 }
406 if ($pattern_depth == 0 || 543 }
407 (($file_pd - $value_pd) < $pattern_depth)) { 544 }
408 $hash{$tvi} = $value_pd; 545 }
546
547 if (!$exclude) {
548 for ($i = $start; $i < $end; $i++) {
549 my $line = $typevalue[$i];
550 if ($line =~ m/^(\C):\s*(.*)/) {
551 my $type = $1;
552 my $value = $2;
553 if ($type eq 'F') {
554 if (file_match_pattern($file, $value)) {
555 my $value_pd = ($value =~ tr@/@@);
556 my $file_pd = ($file =~ tr@/@@);
557 $value_pd++ if (substr($value,-1,1) ne "/");
558 $value_pd = -1 if ($value =~ /^\.\*/);
559 if ($value_pd >= $file_pd) {
560 $exact_pattern_match_hash{$file} = 1;
561 }
562 if ($pattern_depth == 0 ||
563 (($file_pd - $value_pd) < $pattern_depth)) {
564 $hash{$tvi} = $value_pd;
565 }
409 } 566 }
410 } 567 }
411 } 568 }
412 } 569 }
413 } 570 }
571 $tvi = $end + 1;
414 } 572 }
415 573
416 $tvi = $end + 1; 574 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
417 } 575 add_categories($line);
418
419 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
420 add_categories($line);
421 if ($sections) { 576 if ($sections) {
422 my $i; 577 my $i;
423 my $start = find_starting_index($line); 578 my $start = find_starting_index($line);
@@ -435,80 +590,71 @@ foreach my $file (@files) {
435 } 590 }
436 print("\n"); 591 print("\n");
437 } 592 }
593 }
438 } 594 }
439 595
440 if ($email && $email_git) { 596 if ($keywords) {
441 vcs_file_signoffs($file); 597 @keyword_tvi = sort_and_uniq(@keyword_tvi);
598 foreach my $line (@keyword_tvi) {
599 add_categories($line);
600 }
442 } 601 }
443 602
444 if ($email && $email_git_blame) { 603 foreach my $email (@email_to, @list_to) {
445 vcs_file_blame($file); 604 $email->[0] = deduplicate_email($email->[0]);
446 } 605 }
447}
448 606
449if ($keywords) { 607 foreach my $file (@files) {
450 @keyword_tvi = sort_and_uniq(@keyword_tvi); 608 if ($email &&
451 foreach my $line (@keyword_tvi) { 609 ($email_git || ($email_git_fallback &&
452 add_categories($line); 610 !$exact_pattern_match_hash{$file}))) {
611 vcs_file_signoffs($file);
612 }
613 if ($email && $email_git_blame) {
614 vcs_file_blame($file);
615 }
453 } 616 }
454}
455 617
456if ($email) { 618 if ($email) {
457 foreach my $chief (@penguin_chief) { 619 foreach my $chief (@penguin_chief) {
458 if ($chief =~ m/^(.*):(.*)/) { 620 if ($chief =~ m/^(.*):(.*)/) {
459 my $email_address; 621 my $email_address;
460 622
461 $email_address = format_email($1, $2, $email_usename); 623 $email_address = format_email($1, $2, $email_usename);
462 if ($email_git_penguin_chiefs) { 624 if ($email_git_penguin_chiefs) {
463 push(@email_to, [$email_address, 'chief penguin']); 625 push(@email_to, [$email_address, 'chief penguin']);
464 } else { 626 } else {
465 @email_to = grep($_->[0] !~ /${email_address}/, @email_to); 627 @email_to = grep($_->[0] !~ /${email_address}/, @email_to);
628 }
466 } 629 }
467 } 630 }
468 }
469 631
470 foreach my $email (@file_emails) { 632 foreach my $email (@file_emails) {
471 my ($name, $address) = parse_email($email); 633 my ($name, $address) = parse_email($email);
472 634
473 my $tmp_email = format_email($name, $address, $email_usename); 635 my $tmp_email = format_email($name, $address, $email_usename);
474 push_email_address($tmp_email, ''); 636 push_email_address($tmp_email, '');
475 add_role($tmp_email, 'in file'); 637 add_role($tmp_email, 'in file');
638 }
476 } 639 }
477}
478 640
479if ($email || $email_list) {
480 my @to = (); 641 my @to = ();
481 if ($email) { 642 if ($email || $email_list) {
482 @to = (@to, @email_to); 643 if ($email) {
483 } 644 @to = (@to, @email_to);
484 if ($email_list) { 645 }
485 @to = (@to, @list_to); 646 if ($email_list) {
647 @to = (@to, @list_to);
648 }
486 } 649 }
487 output(merge_email(@to));
488}
489
490if ($scm) {
491 @scm = uniq(@scm);
492 output(@scm);
493}
494
495if ($status) {
496 @status = uniq(@status);
497 output(@status);
498}
499 650
500if ($subsystem) { 651 if ($interactive) {
501 @subsystem = uniq(@subsystem); 652 @to = interactive_get_maintainers(\@to);
502 output(@subsystem); 653 }
503}
504 654
505if ($web) { 655 return @to;
506 @web = uniq(@web);
507 output(@web);
508} 656}
509 657
510exit($exit);
511
512sub file_match_pattern { 658sub file_match_pattern {
513 my ($file, $pattern) = @_; 659 my ($file, $pattern) = @_;
514 if (substr($pattern, -1) eq "/") { 660 if (substr($pattern, -1) eq "/") {
@@ -537,7 +683,8 @@ MAINTAINER field selection options:
537 --email => print email address(es) if any 683 --email => print email address(es) if any
538 --git => include recent git \*-by: signers 684 --git => include recent git \*-by: signers
539 --git-all-signature-types => include signers regardless of signature type 685 --git-all-signature-types => include signers regardless of signature type
540 or use only ${signaturePattern} signers (default: $email_git_all_signature_types) 686 or use only ${signature_pattern} signers (default: $email_git_all_signature_types)
687 --git-fallback => use git when no exact MAINTAINERS pattern (default: $email_git_fallback)
541 --git-chief-penguins => include ${penguin_chiefs} 688 --git-chief-penguins => include ${penguin_chiefs}
542 --git-min-signatures => number of signatures required (default: $email_git_min_signatures) 689 --git-min-signatures => number of signatures required (default: $email_git_min_signatures)
543 --git-max-maintainers => maximum maintainers to add (default: $email_git_max_maintainers) 690 --git-max-maintainers => maximum maintainers to add (default: $email_git_max_maintainers)
@@ -545,6 +692,7 @@ MAINTAINER field selection options:
545 --git-blame => use git blame to find modified commits for patch or file 692 --git-blame => use git blame to find modified commits for patch or file
546 --git-since => git history to use (default: $email_git_since) 693 --git-since => git history to use (default: $email_git_since)
547 --hg-since => hg history to use (default: $email_hg_since) 694 --hg-since => hg history to use (default: $email_hg_since)
695 --interactive => display a menu (mostly useful if used with the --git option)
548 --m => include maintainer(s) if any 696 --m => include maintainer(s) if any
549 --n => include name 'Full Name <addr\@domain.tld>' 697 --n => include name 'Full Name <addr\@domain.tld>'
550 --l => include list(s) if any 698 --l => include list(s) if any
@@ -565,8 +713,9 @@ Output type options:
565 713
566Other options: 714Other options:
567 --pattern-depth => Number of pattern directory traversals (default: 0 (all)) 715 --pattern-depth => Number of pattern directory traversals (default: 0 (all))
568 --keywords => scan patch for keywords (default: 1 (on)) 716 --keywords => scan patch for keywords (default: $keywords)
569 --sections => print the entire subsystem sections with pattern matches 717 --sections => print all of the subsystem sections with pattern matches
718 --mailmap => use .mailmap file (default: $email_use_mailmap)
570 --version => show version 719 --version => show version
571 --help => show this help information 720 --help => show this help information
572 721
@@ -606,30 +755,30 @@ EOT
606} 755}
607 756
608sub top_of_kernel_tree { 757sub top_of_kernel_tree {
609 my ($lk_path) = @_; 758 my ($lk_path) = @_;
610 759
611 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") { 760 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
612 $lk_path .= "/"; 761 $lk_path .= "/";
613 } 762 }
614 if ( (-f "${lk_path}COPYING") 763 if ( (-f "${lk_path}COPYING")
615 && (-f "${lk_path}CREDITS") 764 && (-f "${lk_path}CREDITS")
616 && (-f "${lk_path}Kbuild") 765 && (-f "${lk_path}Kbuild")
617 && (-f "${lk_path}MAINTAINERS") 766 && (-f "${lk_path}MAINTAINERS")
618 && (-f "${lk_path}Makefile") 767 && (-f "${lk_path}Makefile")
619 && (-f "${lk_path}README") 768 && (-f "${lk_path}README")
620 && (-d "${lk_path}Documentation") 769 && (-d "${lk_path}Documentation")
621 && (-d "${lk_path}arch") 770 && (-d "${lk_path}arch")
622 && (-d "${lk_path}include") 771 && (-d "${lk_path}include")
623 && (-d "${lk_path}drivers") 772 && (-d "${lk_path}drivers")
624 && (-d "${lk_path}fs") 773 && (-d "${lk_path}fs")
625 && (-d "${lk_path}init") 774 && (-d "${lk_path}init")
626 && (-d "${lk_path}ipc") 775 && (-d "${lk_path}ipc")
627 && (-d "${lk_path}kernel") 776 && (-d "${lk_path}kernel")
628 && (-d "${lk_path}lib") 777 && (-d "${lk_path}lib")
629 && (-d "${lk_path}scripts")) { 778 && (-d "${lk_path}scripts")) {
630 return 1; 779 return 1;
631 } 780 }
632 return 0; 781 return 0;
633} 782}
634 783
635sub parse_email { 784sub parse_email {
@@ -821,11 +970,19 @@ sub add_categories {
821 } 970 }
822 if ($list_additional =~ m/subscribers-only/) { 971 if ($list_additional =~ m/subscribers-only/) {
823 if ($email_subscriber_list) { 972 if ($email_subscriber_list) {
824 push(@list_to, [$list_address, "subscriber list${list_role}"]); 973 if (!$hash_list_to{lc($list_address)}) {
974 $hash_list_to{lc($list_address)} = 1;
975 push(@list_to, [$list_address,
976 "subscriber list${list_role}"]);
977 }
825 } 978 }
826 } else { 979 } else {
827 if ($email_list) { 980 if ($email_list) {
828 push(@list_to, [$list_address, "open list${list_role}"]); 981 if (!$hash_list_to{lc($list_address)}) {
982 $hash_list_to{lc($list_address)} = 1;
983 push(@list_to, [$list_address,
984 "open list${list_role}"]);
985 }
829 } 986 }
830 } 987 }
831 } elsif ($ptype eq "M") { 988 } elsif ($ptype eq "M") {
@@ -856,15 +1013,12 @@ sub add_categories {
856 } 1013 }
857} 1014}
858 1015
859my %email_hash_name;
860my %email_hash_address;
861
862sub email_inuse { 1016sub email_inuse {
863 my ($name, $address) = @_; 1017 my ($name, $address) = @_;
864 1018
865 return 1 if (($name eq "") && ($address eq "")); 1019 return 1 if (($name eq "") && ($address eq ""));
866 return 1 if (($name ne "") && exists($email_hash_name{$name})); 1020 return 1 if (($name ne "") && exists($email_hash_name{lc($name)}));
867 return 1 if (($address ne "") && exists($email_hash_address{$address})); 1021 return 1 if (($address ne "") && exists($email_hash_address{lc($address)}));
868 1022
869 return 0; 1023 return 0;
870} 1024}
@@ -882,8 +1036,8 @@ sub push_email_address {
882 push(@email_to, [format_email($name, $address, $email_usename), $role]); 1036 push(@email_to, [format_email($name, $address, $email_usename), $role]);
883 } elsif (!email_inuse($name, $address)) { 1037 } elsif (!email_inuse($name, $address)) {
884 push(@email_to, [format_email($name, $address, $email_usename), $role]); 1038 push(@email_to, [format_email($name, $address, $email_usename), $role]);
885 $email_hash_name{$name}++; 1039 $email_hash_name{lc($name)}++ if ($name ne "");
886 $email_hash_address{$address}++; 1040 $email_hash_address{lc($address)}++;
887 } 1041 }
888 1042
889 return 1; 1043 return 1;
@@ -952,30 +1106,69 @@ sub which {
952 return ""; 1106 return "";
953} 1107}
954 1108
955sub mailmap { 1109sub which_conf {
956 my (@lines) = @_; 1110 my ($conf) = @_;
957 my %hash;
958 1111
959 foreach my $line (@lines) { 1112 foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
960 my ($name, $address) = parse_email($line); 1113 if (-e "$path/$conf") {
961 if (!exists($hash{$name})) { 1114 return "$path/$conf";
962 $hash{$name} = $address;
963 } elsif ($address ne $hash{$name}) {
964 $address = $hash{$name};
965 $line = format_email($name, $address, $email_usename);
966 } 1115 }
967 if (exists($mailmap{$name})) { 1116 }
968 my $obj = $mailmap{$name}; 1117
969 foreach my $map_address (@$obj) { 1118 return "";
970 if (($map_address eq $address) && 1119}
971 ($map_address ne $hash{$name})) { 1120
972 $line = format_email($name, $hash{$name}, $email_usename); 1121sub mailmap_email {
973 } 1122 my ($line) = @_;
974 } 1123
1124 my ($name, $address) = parse_email($line);
1125 my $email = format_email($name, $address, 1);
1126 my $real_name = $name;
1127 my $real_address = $address;
1128
1129 if (exists $mailmap->{names}->{$email} ||
1130 exists $mailmap->{addresses}->{$email}) {
1131 if (exists $mailmap->{names}->{$email}) {
1132 $real_name = $mailmap->{names}->{$email};
1133 }
1134 if (exists $mailmap->{addresses}->{$email}) {
1135 $real_address = $mailmap->{addresses}->{$email};
1136 }
1137 } else {
1138 if (exists $mailmap->{names}->{$address}) {
1139 $real_name = $mailmap->{names}->{$address};
1140 }
1141 if (exists $mailmap->{addresses}->{$address}) {
1142 $real_address = $mailmap->{addresses}->{$address};
975 } 1143 }
976 } 1144 }
1145 return format_email($real_name, $real_address, 1);
1146}
977 1147
978 return @lines; 1148sub mailmap {
1149 my (@addresses) = @_;
1150
1151 my @mapped_emails = ();
1152 foreach my $line (@addresses) {
1153 push(@mapped_emails, mailmap_email($line));
1154 }
1155 merge_by_realname(@mapped_emails) if ($email_use_mailmap);
1156 return @mapped_emails;
1157}
1158
1159sub merge_by_realname {
1160 my %address_map;
1161 my (@emails) = @_;
1162
1163 foreach my $email (@emails) {
1164 my ($name, $address) = parse_email($email);
1165 if (exists $address_map{$name}) {
1166 $address = $address_map{$name};
1167 $email = format_email($name, $address, 1);
1168 } else {
1169 $address_map{$name} = $address;
1170 }
1171 }
979} 1172}
980 1173
981sub git_execute_cmd { 1174sub git_execute_cmd {
@@ -999,10 +1192,30 @@ sub hg_execute_cmd {
999 return @lines; 1192 return @lines;
1000} 1193}
1001 1194
1195sub extract_formatted_signatures {
1196 my (@signature_lines) = @_;
1197
1198 my @type = @signature_lines;
1199
1200 s/\s*(.*):.*/$1/ for (@type);
1201
1202 # cut -f2- -d":"
1203 s/\s*.*:\s*(.+)\s*/$1/ for (@signature_lines);
1204
1205## Reformat email addresses (with names) to avoid badly written signatures
1206
1207 foreach my $signer (@signature_lines) {
1208 $signer = deduplicate_email($signer);
1209 }
1210
1211 return (\@type, \@signature_lines);
1212}
1213
1002sub vcs_find_signers { 1214sub vcs_find_signers {
1003 my ($cmd) = @_; 1215 my ($cmd) = @_;
1004 my @lines = ();
1005 my $commits; 1216 my $commits;
1217 my @lines = ();
1218 my @signatures = ();
1006 1219
1007 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); 1220 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
1008 1221
@@ -1010,21 +1223,48 @@ sub vcs_find_signers {
1010 1223
1011 $commits = grep(/$pattern/, @lines); # of commits 1224 $commits = grep(/$pattern/, @lines); # of commits
1012 1225
1013 @lines = grep(/^[ \t]*${signaturePattern}.*\@.*$/, @lines); 1226 @signatures = grep(/^[ \t]*${signature_pattern}.*\@.*$/, @lines);
1227
1228 return (0, @signatures) if !@signatures;
1229
1230 save_commits_by_author(@lines) if ($interactive);
1231 save_commits_by_signer(@lines) if ($interactive);
1232
1233 if (!$email_git_penguin_chiefs) {
1234 @signatures = grep(!/${penguin_chiefs}/i, @signatures);
1235 }
1236
1237 my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
1238
1239 return ($commits, @$signers_ref);
1240}
1241
1242sub vcs_find_author {
1243 my ($cmd) = @_;
1244 my @lines = ();
1245
1246 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
1247
1014 if (!$email_git_penguin_chiefs) { 1248 if (!$email_git_penguin_chiefs) {
1015 @lines = grep(!/${penguin_chiefs}/i, @lines); 1249 @lines = grep(!/${penguin_chiefs}/i, @lines);
1016 } 1250 }
1017 # cut -f2- -d":"
1018 s/.*:\s*(.+)\s*/$1/ for (@lines);
1019 1251
1020## Reformat email addresses (with names) to avoid badly written signatures 1252 return @lines if !@lines;
1021 1253
1254 my @authors = ();
1022 foreach my $line (@lines) { 1255 foreach my $line (@lines) {
1023 my ($name, $address) = parse_email($line); 1256 if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
1024 $line = format_email($name, $address, 1); 1257 my $author = $1;
1258 my ($name, $address) = parse_email($author);
1259 $author = format_email($name, $address, 1);
1260 push(@authors, $author);
1261 }
1025 } 1262 }
1026 1263
1027 return ($commits, @lines); 1264 save_commits_by_author(@lines) if ($interactive);
1265 save_commits_by_signer(@lines) if ($interactive);
1266
1267 return @authors;
1028} 1268}
1029 1269
1030sub vcs_save_commits { 1270sub vcs_save_commits {
@@ -1084,6 +1324,10 @@ sub vcs_blame {
1084 @commits = vcs_save_commits($cmd); 1324 @commits = vcs_save_commits($cmd);
1085 } 1325 }
1086 1326
1327 foreach my $commit (@commits) {
1328 $commit =~ s/^\^//g;
1329 }
1330
1087 return @commits; 1331 return @commits;
1088} 1332}
1089 1333
@@ -1092,7 +1336,7 @@ sub vcs_exists {
1092 %VCS_cmds = %VCS_cmds_git; 1336 %VCS_cmds = %VCS_cmds_git;
1093 return 1 if eval $VCS_cmds{"available"}; 1337 return 1 if eval $VCS_cmds{"available"};
1094 %VCS_cmds = %VCS_cmds_hg; 1338 %VCS_cmds = %VCS_cmds_hg;
1095 return 1 if eval $VCS_cmds{"available"}; 1339 return 2 if eval $VCS_cmds{"available"};
1096 %VCS_cmds = (); 1340 %VCS_cmds = ();
1097 if (!$printed_novcs) { 1341 if (!$printed_novcs) {
1098 warn("$P: No supported VCS found. Add --nogit to options?\n"); 1342 warn("$P: No supported VCS found. Add --nogit to options?\n");
@@ -1104,6 +1348,405 @@ sub vcs_exists {
1104 return 0; 1348 return 0;
1105} 1349}
1106 1350
1351sub vcs_is_git {
1352 vcs_exists();
1353 return $vcs_used == 1;
1354}
1355
1356sub vcs_is_hg {
1357 return $vcs_used == 2;
1358}
1359
1360sub interactive_get_maintainers {
1361 my ($list_ref) = @_;
1362 my @list = @$list_ref;
1363
1364 vcs_exists();
1365
1366 my %selected;
1367 my %authored;
1368 my %signed;
1369 my $count = 0;
1370 my $maintained = 0;
1371 foreach my $entry (@list) {
1372 $maintained = 1 if ($entry->[1] =~ /^(maintainer|supporter)/i);
1373 $selected{$count} = 1;
1374 $authored{$count} = 0;
1375 $signed{$count} = 0;
1376 $count++;
1377 }
1378
1379 #menu loop
1380 my $done = 0;
1381 my $print_options = 0;
1382 my $redraw = 1;
1383 while (!$done) {
1384 $count = 0;
1385 if ($redraw) {
1386 printf STDERR "\n%1s %2s %-65s",
1387 "*", "#", "email/list and role:stats";
1388 if ($email_git ||
1389 ($email_git_fallback && !$maintained) ||
1390 $email_git_blame) {
1391 print STDERR "auth sign";
1392 }
1393 print STDERR "\n";
1394 foreach my $entry (@list) {
1395 my $email = $entry->[0];
1396 my $role = $entry->[1];
1397 my $sel = "";
1398 $sel = "*" if ($selected{$count});
1399 my $commit_author = $commit_author_hash{$email};
1400 my $commit_signer = $commit_signer_hash{$email};
1401 my $authored = 0;
1402 my $signed = 0;
1403 $authored++ for (@{$commit_author});
1404 $signed++ for (@{$commit_signer});
1405 printf STDERR "%1s %2d %-65s", $sel, $count + 1, $email;
1406 printf STDERR "%4d %4d", $authored, $signed
1407 if ($authored > 0 || $signed > 0);
1408 printf STDERR "\n %s\n", $role;
1409 if ($authored{$count}) {
1410 my $commit_author = $commit_author_hash{$email};
1411 foreach my $ref (@{$commit_author}) {
1412 print STDERR " Author: @{$ref}[1]\n";
1413 }
1414 }
1415 if ($signed{$count}) {
1416 my $commit_signer = $commit_signer_hash{$email};
1417 foreach my $ref (@{$commit_signer}) {
1418 print STDERR " @{$ref}[2]: @{$ref}[1]\n";
1419 }
1420 }
1421
1422 $count++;
1423 }
1424 }
1425 my $date_ref = \$email_git_since;
1426 $date_ref = \$email_hg_since if (vcs_is_hg());
1427 if ($print_options) {
1428 $print_options = 0;
1429 if (vcs_exists()) {
1430 print STDERR <<EOT
1431
1432Version Control options:
1433g use git history [$email_git]
1434gf use git-fallback [$email_git_fallback]
1435b use git blame [$email_git_blame]
1436bs use blame signatures [$email_git_blame_signatures]
1437c# minimum commits [$email_git_min_signatures]
1438%# min percent [$email_git_min_percent]
1439d# history to use [$$date_ref]
1440x# max maintainers [$email_git_max_maintainers]
1441t all signature types [$email_git_all_signature_types]
1442m use .mailmap [$email_use_mailmap]
1443EOT
1444 }
1445 print STDERR <<EOT
1446
1447Additional options:
14480 toggle all
1449tm toggle maintainers
1450tg toggle git entries
1451tl toggle open list entries
1452ts toggle subscriber list entries
1453f emails in file [$file_emails]
1454k keywords in file [$keywords]
1455r remove duplicates [$email_remove_duplicates]
1456p# pattern match depth [$pattern_depth]
1457EOT
1458 }
1459 print STDERR
1460"\n#(toggle), A#(author), S#(signed) *(all), ^(none), O(options), Y(approve): ";
1461
1462 my $input = <STDIN>;
1463 chomp($input);
1464
1465 $redraw = 1;
1466 my $rerun = 0;
1467 my @wish = split(/[, ]+/, $input);
1468 foreach my $nr (@wish) {
1469 $nr = lc($nr);
1470 my $sel = substr($nr, 0, 1);
1471 my $str = substr($nr, 1);
1472 my $val = 0;
1473 $val = $1 if $str =~ /^(\d+)$/;
1474
1475 if ($sel eq "y") {
1476 $interactive = 0;
1477 $done = 1;
1478 $output_rolestats = 0;
1479 $output_roles = 0;
1480 last;
1481 } elsif ($nr =~ /^\d+$/ && $nr > 0 && $nr <= $count) {
1482 $selected{$nr - 1} = !$selected{$nr - 1};
1483 } elsif ($sel eq "*" || $sel eq '^') {
1484 my $toggle = 0;
1485 $toggle = 1 if ($sel eq '*');
1486 for (my $i = 0; $i < $count; $i++) {
1487 $selected{$i} = $toggle;
1488 }
1489 } elsif ($sel eq "0") {
1490 for (my $i = 0; $i < $count; $i++) {
1491 $selected{$i} = !$selected{$i};
1492 }
1493 } elsif ($sel eq "t") {
1494 if (lc($str) eq "m") {
1495 for (my $i = 0; $i < $count; $i++) {
1496 $selected{$i} = !$selected{$i}
1497 if ($list[$i]->[1] =~ /^(maintainer|supporter)/i);
1498 }
1499 } elsif (lc($str) eq "g") {
1500 for (my $i = 0; $i < $count; $i++) {
1501 $selected{$i} = !$selected{$i}
1502 if ($list[$i]->[1] =~ /^(author|commit|signer)/i);
1503 }
1504 } elsif (lc($str) eq "l") {
1505 for (my $i = 0; $i < $count; $i++) {
1506 $selected{$i} = !$selected{$i}
1507 if ($list[$i]->[1] =~ /^(open list)/i);
1508 }
1509 } elsif (lc($str) eq "s") {
1510 for (my $i = 0; $i < $count; $i++) {
1511 $selected{$i} = !$selected{$i}
1512 if ($list[$i]->[1] =~ /^(subscriber list)/i);
1513 }
1514 }
1515 } elsif ($sel eq "a") {
1516 if ($val > 0 && $val <= $count) {
1517 $authored{$val - 1} = !$authored{$val - 1};
1518 } elsif ($str eq '*' || $str eq '^') {
1519 my $toggle = 0;
1520 $toggle = 1 if ($str eq '*');
1521 for (my $i = 0; $i < $count; $i++) {
1522 $authored{$i} = $toggle;
1523 }
1524 }
1525 } elsif ($sel eq "s") {
1526 if ($val > 0 && $val <= $count) {
1527 $signed{$val - 1} = !$signed{$val - 1};
1528 } elsif ($str eq '*' || $str eq '^') {
1529 my $toggle = 0;
1530 $toggle = 1 if ($str eq '*');
1531 for (my $i = 0; $i < $count; $i++) {
1532 $signed{$i} = $toggle;
1533 }
1534 }
1535 } elsif ($sel eq "o") {
1536 $print_options = 1;
1537 $redraw = 1;
1538 } elsif ($sel eq "g") {
1539 if ($str eq "f") {
1540 bool_invert(\$email_git_fallback);
1541 } else {
1542 bool_invert(\$email_git);
1543 }
1544 $rerun = 1;
1545 } elsif ($sel eq "b") {
1546 if ($str eq "s") {
1547 bool_invert(\$email_git_blame_signatures);
1548 } else {
1549 bool_invert(\$email_git_blame);
1550 }
1551 $rerun = 1;
1552 } elsif ($sel eq "c") {
1553 if ($val > 0) {
1554 $email_git_min_signatures = $val;
1555 $rerun = 1;
1556 }
1557 } elsif ($sel eq "x") {
1558 if ($val > 0) {
1559 $email_git_max_maintainers = $val;
1560 $rerun = 1;
1561 }
1562 } elsif ($sel eq "%") {
1563 if ($str ne "" && $val >= 0) {
1564 $email_git_min_percent = $val;
1565 $rerun = 1;
1566 }
1567 } elsif ($sel eq "d") {
1568 if (vcs_is_git()) {
1569 $email_git_since = $str;
1570 } elsif (vcs_is_hg()) {
1571 $email_hg_since = $str;
1572 }
1573 $rerun = 1;
1574 } elsif ($sel eq "t") {
1575 bool_invert(\$email_git_all_signature_types);
1576 $rerun = 1;
1577 } elsif ($sel eq "f") {
1578 bool_invert(\$file_emails);
1579 $rerun = 1;
1580 } elsif ($sel eq "r") {
1581 bool_invert(\$email_remove_duplicates);
1582 $rerun = 1;
1583 } elsif ($sel eq "m") {
1584 bool_invert(\$email_use_mailmap);
1585 read_mailmap();
1586 $rerun = 1;
1587 } elsif ($sel eq "k") {
1588 bool_invert(\$keywords);
1589 $rerun = 1;
1590 } elsif ($sel eq "p") {
1591 if ($str ne "" && $val >= 0) {
1592 $pattern_depth = $val;
1593 $rerun = 1;
1594 }
1595 } elsif ($sel eq "h" || $sel eq "?") {
1596 print STDERR <<EOT
1597
1598Interactive mode allows you to select the various maintainers, submitters,
1599commit signers and mailing lists that could be CC'd on a patch.
1600
1601Any *'d entry is selected.
1602
1603If you have git or hg installed, you can choose to summarize the commit
1604history of files in the patch. Also, each line of the current file can
1605be matched to its commit author and that commits signers with blame.
1606
1607Various knobs exist to control the length of time for active commit
1608tracking, the maximum number of commit authors and signers to add,
1609and such.
1610
1611Enter selections at the prompt until you are satisfied that the selected
1612maintainers are appropriate. You may enter multiple selections separated
1613by either commas or spaces.
1614
1615EOT
1616 } else {
1617 print STDERR "invalid option: '$nr'\n";
1618 $redraw = 0;
1619 }
1620 }
1621 if ($rerun) {
1622 print STDERR "git-blame can be very slow, please have patience..."
1623 if ($email_git_blame);
1624 goto &get_maintainers;
1625 }
1626 }
1627
1628 #drop not selected entries
1629 $count = 0;
1630 my @new_emailto = ();
1631 foreach my $entry (@list) {
1632 if ($selected{$count}) {
1633 push(@new_emailto, $list[$count]);
1634 }
1635 $count++;
1636 }
1637 return @new_emailto;
1638}
1639
1640sub bool_invert {
1641 my ($bool_ref) = @_;
1642
1643 if ($$bool_ref) {
1644 $$bool_ref = 0;
1645 } else {
1646 $$bool_ref = 1;
1647 }
1648}
1649
1650sub deduplicate_email {
1651 my ($email) = @_;
1652
1653 my $matched = 0;
1654 my ($name, $address) = parse_email($email);
1655 $email = format_email($name, $address, 1);
1656 $email = mailmap_email($email);
1657
1658 return $email if (!$email_remove_duplicates);
1659
1660 ($name, $address) = parse_email($email);
1661
1662 if ($name ne "" && $deduplicate_name_hash{lc($name)}) {
1663 $name = $deduplicate_name_hash{lc($name)}->[0];
1664 $address = $deduplicate_name_hash{lc($name)}->[1];
1665 $matched = 1;
1666 } elsif ($deduplicate_address_hash{lc($address)}) {
1667 $name = $deduplicate_address_hash{lc($address)}->[0];
1668 $address = $deduplicate_address_hash{lc($address)}->[1];
1669 $matched = 1;
1670 }
1671 if (!$matched) {
1672 $deduplicate_name_hash{lc($name)} = [ $name, $address ];
1673 $deduplicate_address_hash{lc($address)} = [ $name, $address ];
1674 }
1675 $email = format_email($name, $address, 1);
1676 $email = mailmap_email($email);
1677 return $email;
1678}
1679
1680sub save_commits_by_author {
1681 my (@lines) = @_;
1682
1683 my @authors = ();
1684 my @commits = ();
1685 my @subjects = ();
1686
1687 foreach my $line (@lines) {
1688 if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
1689 my $author = $1;
1690 $author = deduplicate_email($author);
1691 push(@authors, $author);
1692 }
1693 push(@commits, $1) if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
1694 push(@subjects, $1) if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
1695 }
1696
1697 for (my $i = 0; $i < @authors; $i++) {
1698 my $exists = 0;
1699 foreach my $ref(@{$commit_author_hash{$authors[$i]}}) {
1700 if (@{$ref}[0] eq $commits[$i] &&
1701 @{$ref}[1] eq $subjects[$i]) {
1702 $exists = 1;
1703 last;
1704 }
1705 }
1706 if (!$exists) {
1707 push(@{$commit_author_hash{$authors[$i]}},
1708 [ ($commits[$i], $subjects[$i]) ]);
1709 }
1710 }
1711}
1712
1713sub save_commits_by_signer {
1714 my (@lines) = @_;
1715
1716 my $commit = "";
1717 my $subject = "";
1718
1719 foreach my $line (@lines) {
1720 $commit = $1 if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
1721 $subject = $1 if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
1722 if ($line =~ /^[ \t]*${signature_pattern}.*\@.*$/) {
1723 my @signatures = ($line);
1724 my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
1725 my @types = @$types_ref;
1726 my @signers = @$signers_ref;
1727
1728 my $type = $types[0];
1729 my $signer = $signers[0];
1730
1731 $signer = deduplicate_email($signer);
1732
1733 my $exists = 0;
1734 foreach my $ref(@{$commit_signer_hash{$signer}}) {
1735 if (@{$ref}[0] eq $commit &&
1736 @{$ref}[1] eq $subject &&
1737 @{$ref}[2] eq $type) {
1738 $exists = 1;
1739 last;
1740 }
1741 }
1742 if (!$exists) {
1743 push(@{$commit_signer_hash{$signer}},
1744 [ ($commit, $subject, $type) ]);
1745 }
1746 }
1747 }
1748}
1749
1107sub vcs_assign { 1750sub vcs_assign {
1108 my ($role, $divisor, @lines) = @_; 1751 my ($role, $divisor, @lines) = @_;
1109 1752
@@ -1117,9 +1760,9 @@ sub vcs_assign {
1117 $divisor = 1; 1760 $divisor = 1;
1118 } 1761 }
1119 1762
1120 if ($email_remove_duplicates) { 1763 @lines = mailmap(@lines);
1121 @lines = mailmap(@lines); 1764
1122 } 1765 return if (@lines <= 0);
1123 1766
1124 @lines = sort(@lines); 1767 @lines = sort(@lines);
1125 1768
@@ -1152,12 +1795,18 @@ sub vcs_file_signoffs {
1152 my @signers = (); 1795 my @signers = ();
1153 my $commits; 1796 my $commits;
1154 1797
1155 return if (!vcs_exists()); 1798 $vcs_used = vcs_exists();
1799 return if (!$vcs_used);
1156 1800
1157 my $cmd = $VCS_cmds{"find_signers_cmd"}; 1801 my $cmd = $VCS_cmds{"find_signers_cmd"};
1158 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd 1802 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
1159 1803
1160 ($commits, @signers) = vcs_find_signers($cmd); 1804 ($commits, @signers) = vcs_find_signers($cmd);
1805
1806 foreach my $signer (@signers) {
1807 $signer = deduplicate_email($signer);
1808 }
1809
1161 vcs_assign("commit_signer", $commits, @signers); 1810 vcs_assign("commit_signer", $commits, @signers);
1162} 1811}
1163 1812
@@ -1165,29 +1814,114 @@ sub vcs_file_blame {
1165 my ($file) = @_; 1814 my ($file) = @_;
1166 1815
1167 my @signers = (); 1816 my @signers = ();
1817 my @all_commits = ();
1168 my @commits = (); 1818 my @commits = ();
1169 my $total_commits; 1819 my $total_commits;
1820 my $total_lines;
1170 1821
1171 return if (!vcs_exists()); 1822 $vcs_used = vcs_exists();
1823 return if (!$vcs_used);
1172 1824
1173 @commits = vcs_blame($file); 1825 @all_commits = vcs_blame($file);
1174 @commits = uniq(@commits); 1826 @commits = uniq(@all_commits);
1175 $total_commits = @commits; 1827 $total_commits = @commits;
1828 $total_lines = @all_commits;
1176 1829
1177 foreach my $commit (@commits) { 1830 if ($email_git_blame_signatures) {
1178 my $commit_count; 1831 if (vcs_is_hg()) {
1179 my @commit_signers = (); 1832 my $commit_count;
1833 my @commit_signers = ();
1834 my $commit = join(" -r ", @commits);
1835 my $cmd;
1836
1837 $cmd = $VCS_cmds{"find_commit_signers_cmd"};
1838 $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
1839
1840 ($commit_count, @commit_signers) = vcs_find_signers($cmd);
1841
1842 push(@signers, @commit_signers);
1843 } else {
1844 foreach my $commit (@commits) {
1845 my $commit_count;
1846 my @commit_signers = ();
1847 my $cmd;
1180 1848
1181 my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; 1849 $cmd = $VCS_cmds{"find_commit_signers_cmd"};
1182 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd 1850 $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
1183 1851
1184 ($commit_count, @commit_signers) = vcs_find_signers($cmd); 1852 ($commit_count, @commit_signers) = vcs_find_signers($cmd);
1185 push(@signers, @commit_signers); 1853
1854 push(@signers, @commit_signers);
1855 }
1856 }
1186 } 1857 }
1187 1858
1188 if ($from_filename) { 1859 if ($from_filename) {
1860 if ($output_rolestats) {
1861 my @blame_signers;
1862 if (vcs_is_hg()) {{ # Double brace for last exit
1863 my $commit_count;
1864 my @commit_signers = ();
1865 @commits = uniq(@commits);
1866 @commits = sort(@commits);
1867 my $commit = join(" -r ", @commits);
1868 my $cmd;
1869
1870 $cmd = $VCS_cmds{"find_commit_author_cmd"};
1871 $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
1872
1873 my @lines = ();
1874
1875 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
1876
1877 if (!$email_git_penguin_chiefs) {
1878 @lines = grep(!/${penguin_chiefs}/i, @lines);
1879 }
1880
1881 last if !@lines;
1882
1883 my @authors = ();
1884 foreach my $line (@lines) {
1885 if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
1886 my $author = $1;
1887 $author = deduplicate_email($author);
1888 push(@authors, $author);
1889 }
1890 }
1891
1892 save_commits_by_author(@lines) if ($interactive);
1893 save_commits_by_signer(@lines) if ($interactive);
1894
1895 push(@signers, @authors);
1896 }}
1897 else {
1898 foreach my $commit (@commits) {
1899 my $i;
1900 my $cmd = $VCS_cmds{"find_commit_author_cmd"};
1901 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1902 my @author = vcs_find_author($cmd);
1903 next if !@author;
1904
1905 my $formatted_author = deduplicate_email($author[0]);
1906
1907 my $count = grep(/$commit/, @all_commits);
1908 for ($i = 0; $i < $count ; $i++) {
1909 push(@blame_signers, $formatted_author);
1910 }
1911 }
1912 }
1913 if (@blame_signers) {
1914 vcs_assign("authored lines", $total_lines, @blame_signers);
1915 }
1916 }
1917 foreach my $signer (@signers) {
1918 $signer = deduplicate_email($signer);
1919 }
1189 vcs_assign("commits", $total_commits, @signers); 1920 vcs_assign("commits", $total_commits, @signers);
1190 } else { 1921 } else {
1922 foreach my $signer (@signers) {
1923 $signer = deduplicate_email($signer);
1924 }
1191 vcs_assign("modified commits", $total_commits, @signers); 1925 vcs_assign("modified commits", $total_commits, @signers);
1192 } 1926 }
1193} 1927}
diff --git a/scripts/kconfig/.gitignore b/scripts/kconfig/.gitignore
index 6a36a76e6606..624f6502e03e 100644
--- a/scripts/kconfig/.gitignore
+++ b/scripts/kconfig/.gitignore
@@ -17,6 +17,7 @@ gconf.glade.h
17# 17#
18conf 18conf
19mconf 19mconf
20nconf
20qconf 21qconf
21gconf 22gconf
22kxgettext 23kxgettext
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 7ea649da1940..de934def410f 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -21,17 +21,17 @@ menuconfig: $(obj)/mconf
21 $< $(Kconfig) 21 $< $(Kconfig)
22 22
23config: $(obj)/conf 23config: $(obj)/conf
24 $< $(Kconfig) 24 $< --oldaskconfig $(Kconfig)
25 25
26nconfig: $(obj)/nconf 26nconfig: $(obj)/nconf
27 $< $(Kconfig) 27 $< $(Kconfig)
28 28
29oldconfig: $(obj)/conf 29oldconfig: $(obj)/conf
30 $< -o $(Kconfig) 30 $< --$@ $(Kconfig)
31 31
32silentoldconfig: $(obj)/conf 32silentoldconfig: $(obj)/conf
33 $(Q)mkdir -p include/generated 33 $(Q)mkdir -p include/generated
34 $< -s $(Kconfig) 34 $< --$@ $(Kconfig)
35 35
36# if no path is given, then use src directory to find file 36# if no path is given, then use src directory to find file
37ifdef LSMOD 37ifdef LSMOD
@@ -44,15 +44,15 @@ endif
44localmodconfig: $(obj)/streamline_config.pl $(obj)/conf 44localmodconfig: $(obj)/streamline_config.pl $(obj)/conf
45 $(Q)mkdir -p include/generated 45 $(Q)mkdir -p include/generated
46 $(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config 46 $(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config
47 $(Q)if [ -f .config ]; then \ 47 $(Q)if [ -f .config ]; then \
48 cmp -s .tmp.config .config || \ 48 cmp -s .tmp.config .config || \
49 (mv -f .config .config.old.1; \ 49 (mv -f .config .config.old.1; \
50 mv -f .tmp.config .config; \ 50 mv -f .tmp.config .config; \
51 $(obj)/conf -s $(Kconfig); \ 51 $(obj)/conf --silentoldconfig $(Kconfig); \
52 mv -f .config.old.1 .config.old) \ 52 mv -f .config.old.1 .config.old) \
53 else \ 53 else \
54 mv -f .tmp.config .config; \ 54 mv -f .tmp.config .config; \
55 $(obj)/conf -s $(Kconfig); \ 55 $(obj)/conf --silentoldconfig $(Kconfig); \
56 fi 56 fi
57 $(Q)rm -f .tmp.config 57 $(Q)rm -f .tmp.config
58 58
@@ -60,15 +60,15 @@ localyesconfig: $(obj)/streamline_config.pl $(obj)/conf
60 $(Q)mkdir -p include/generated 60 $(Q)mkdir -p include/generated
61 $(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config 61 $(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config
62 $(Q)sed -i s/=m/=y/ .tmp.config 62 $(Q)sed -i s/=m/=y/ .tmp.config
63 $(Q)if [ -f .config ]; then \ 63 $(Q)if [ -f .config ]; then \
64 cmp -s .tmp.config .config || \ 64 cmp -s .tmp.config .config || \
65 (mv -f .config .config.old.1; \ 65 (mv -f .config .config.old.1; \
66 mv -f .tmp.config .config; \ 66 mv -f .tmp.config .config; \
67 $(obj)/conf -s $(Kconfig); \ 67 $(obj)/conf --silentoldconfig $(Kconfig); \
68 mv -f .config.old.1 .config.old) \ 68 mv -f .config.old.1 .config.old) \
69 else \ 69 else \
70 mv -f .tmp.config .config; \ 70 mv -f .tmp.config .config; \
71 $(obj)/conf -s $(Kconfig); \ 71 $(obj)/conf --silentoldconfig $(Kconfig); \
72 fi 72 fi
73 $(Q)rm -f .tmp.config 73 $(Q)rm -f .tmp.config
74 74
@@ -95,30 +95,29 @@ update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
95 $(Q)rm -f arch/um/Kconfig.arch 95 $(Q)rm -f arch/um/Kconfig.arch
96 $(Q)rm -f $(obj)/config.pot 96 $(Q)rm -f $(obj)/config.pot
97 97
98PHONY += randconfig allyesconfig allnoconfig allmodconfig defconfig 98PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
99 99
100randconfig: $(obj)/conf 100allnoconfig allyesconfig allmodconfig alldefconfig randconfig: $(obj)/conf
101 $< -r $(Kconfig) 101 $< --$@ $(Kconfig)
102 102
103allyesconfig: $(obj)/conf 103PHONY += listnewconfig oldnoconfig savedefconfig defconfig
104 $< -y $(Kconfig)
105 104
106allnoconfig: $(obj)/conf 105listnewconfig oldnoconfig: $(obj)/conf
107 $< -n $(Kconfig) 106 $< --$@ $(Kconfig)
108 107
109allmodconfig: $(obj)/conf 108savedefconfig: $(obj)/conf
110 $< -m $(Kconfig) 109 $< --$@=defconfig $(Kconfig)
111 110
112defconfig: $(obj)/conf 111defconfig: $(obj)/conf
113ifeq ($(KBUILD_DEFCONFIG),) 112ifeq ($(KBUILD_DEFCONFIG),)
114 $< -d $(Kconfig) 113 $< --defconfig $(Kconfig)
115else 114else
116 @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'" 115 @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
117 $(Q)$< -D arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig) 116 $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
118endif 117endif
119 118
120%_defconfig: $(obj)/conf 119%_defconfig: $(obj)/conf
121 $(Q)$< -D arch/$(SRCARCH)/configs/$@ $(Kconfig) 120 $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
122 121
123# Help text used by make help 122# Help text used by make help
124help: 123help:
@@ -131,11 +130,15 @@ help:
131 @echo ' localmodconfig - Update current config disabling modules not loaded' 130 @echo ' localmodconfig - Update current config disabling modules not loaded'
132 @echo ' localyesconfig - Update current config converting local mods to core' 131 @echo ' localyesconfig - Update current config converting local mods to core'
133 @echo ' silentoldconfig - Same as oldconfig, but quietly, additionally update deps' 132 @echo ' silentoldconfig - Same as oldconfig, but quietly, additionally update deps'
134 @echo ' randconfig - New config with random answer to all options' 133 @echo ' defconfig - New config with default from ARCH supplied defconfig'
135 @echo ' defconfig - New config with default answer to all options' 134 @echo ' savedefconfig - Save current config as ./defconfig (minimal config)'
136 @echo ' allmodconfig - New config selecting modules when possible'
137 @echo ' allyesconfig - New config where all options are accepted with yes'
138 @echo ' allnoconfig - New config where all options are answered with no' 135 @echo ' allnoconfig - New config where all options are answered with no'
136 @echo ' allyesconfig - New config where all options are accepted with yes'
137 @echo ' allmodconfig - New config selecting modules when possible'
138 @echo ' alldefconfig - New config with all symbols set to default'
139 @echo ' randconfig - New config with random answer to all options'
140 @echo ' listnewconfig - List new options'
141 @echo ' oldnoconfig - Same as silentoldconfig but set new symbols to n (unset)'
139 142
140# lxdialog stuff 143# lxdialog stuff
141check-lxdialog := $(srctree)/$(src)/lxdialog/check-lxdialog.sh 144check-lxdialog := $(srctree)/$(src)/lxdialog/check-lxdialog.sh
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 9960d1c303f8..7ef429cd5cb3 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -10,6 +10,7 @@
10#include <string.h> 10#include <string.h>
11#include <time.h> 11#include <time.h>
12#include <unistd.h> 12#include <unistd.h>
13#include <getopt.h>
13#include <sys/stat.h> 14#include <sys/stat.h>
14#include <sys/time.h> 15#include <sys/time.h>
15 16
@@ -19,16 +20,21 @@
19static void conf(struct menu *menu); 20static void conf(struct menu *menu);
20static void check_conf(struct menu *menu); 21static void check_conf(struct menu *menu);
21 22
22enum { 23enum input_mode {
23 ask_all, 24 oldaskconfig,
24 ask_new, 25 silentoldconfig,
25 ask_silent, 26 oldconfig,
26 set_default, 27 allnoconfig,
27 set_yes, 28 allyesconfig,
28 set_mod, 29 allmodconfig,
29 set_no, 30 alldefconfig,
30 set_random 31 randconfig,
31} input_mode = ask_all; 32 defconfig,
33 savedefconfig,
34 listnewconfig,
35 oldnoconfig,
36} input_mode = oldaskconfig;
37
32char *defconfig_file; 38char *defconfig_file;
33 39
34static int indent = 1; 40static int indent = 1;
@@ -93,16 +99,16 @@ static int conf_askvalue(struct symbol *sym, const char *def)
93 } 99 }
94 100
95 switch (input_mode) { 101 switch (input_mode) {
96 case ask_new: 102 case oldconfig:
97 case ask_silent: 103 case silentoldconfig:
98 if (sym_has_value(sym)) { 104 if (sym_has_value(sym)) {
99 printf("%s\n", def); 105 printf("%s\n", def);
100 return 0; 106 return 0;
101 } 107 }
102 check_stdin(); 108 check_stdin();
103 case ask_all: 109 case oldaskconfig:
104 fflush(stdout); 110 fflush(stdout);
105 fgets(line, 128, stdin); 111 xfgets(line, 128, stdin);
106 return 1; 112 return 1;
107 default: 113 default:
108 break; 114 break;
@@ -156,14 +162,12 @@ static int conf_string(struct menu *menu)
156static int conf_sym(struct menu *menu) 162static int conf_sym(struct menu *menu)
157{ 163{
158 struct symbol *sym = menu->sym; 164 struct symbol *sym = menu->sym;
159 int type;
160 tristate oldval, newval; 165 tristate oldval, newval;
161 166
162 while (1) { 167 while (1) {
163 printf("%*s%s ", indent - 1, "", _(menu->prompt->text)); 168 printf("%*s%s ", indent - 1, "", _(menu->prompt->text));
164 if (sym->name) 169 if (sym->name)
165 printf("(%s) ", sym->name); 170 printf("(%s) ", sym->name);
166 type = sym_get_type(sym);
167 putchar('['); 171 putchar('[');
168 oldval = sym_get_tristate_value(sym); 172 oldval = sym_get_tristate_value(sym);
169 switch (oldval) { 173 switch (oldval) {
@@ -228,11 +232,9 @@ static int conf_choice(struct menu *menu)
228{ 232{
229 struct symbol *sym, *def_sym; 233 struct symbol *sym, *def_sym;
230 struct menu *child; 234 struct menu *child;
231 int type;
232 bool is_new; 235 bool is_new;
233 236
234 sym = menu->sym; 237 sym = menu->sym;
235 type = sym_get_type(sym);
236 is_new = !sym_has_value(sym); 238 is_new = !sym_has_value(sym);
237 if (sym_is_changable(sym)) { 239 if (sym_is_changable(sym)) {
238 conf_sym(menu); 240 conf_sym(menu);
@@ -294,17 +296,17 @@ static int conf_choice(struct menu *menu)
294 printf("?"); 296 printf("?");
295 printf("]: "); 297 printf("]: ");
296 switch (input_mode) { 298 switch (input_mode) {
297 case ask_new: 299 case oldconfig:
298 case ask_silent: 300 case silentoldconfig:
299 if (!is_new) { 301 if (!is_new) {
300 cnt = def; 302 cnt = def;
301 printf("%d\n", cnt); 303 printf("%d\n", cnt);
302 break; 304 break;
303 } 305 }
304 check_stdin(); 306 check_stdin();
305 case ask_all: 307 case oldaskconfig:
306 fflush(stdout); 308 fflush(stdout);
307 fgets(line, 128, stdin); 309 xfgets(line, 128, stdin);
308 strip(line); 310 strip(line);
309 if (line[0] == '?') { 311 if (line[0] == '?') {
310 print_help(menu); 312 print_help(menu);
@@ -360,7 +362,10 @@ static void conf(struct menu *menu)
360 362
361 switch (prop->type) { 363 switch (prop->type) {
362 case P_MENU: 364 case P_MENU:
363 if (input_mode == ask_silent && rootEntry != menu) { 365 if ((input_mode == silentoldconfig ||
366 input_mode == listnewconfig ||
367 input_mode == oldnoconfig) &&
368 rootEntry != menu) {
364 check_conf(menu); 369 check_conf(menu);
365 return; 370 return;
366 } 371 }
@@ -418,10 +423,16 @@ static void check_conf(struct menu *menu)
418 if (sym && !sym_has_value(sym)) { 423 if (sym && !sym_has_value(sym)) {
419 if (sym_is_changable(sym) || 424 if (sym_is_changable(sym) ||
420 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { 425 (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
421 if (!conf_cnt++) 426 if (input_mode == listnewconfig) {
422 printf(_("*\n* Restart config...\n*\n")); 427 if (sym->name && !sym_is_choice_value(sym)) {
423 rootEntry = menu_get_parent_menu(menu); 428 printf("CONFIG_%s\n", sym->name);
424 conf(rootEntry); 429 }
430 } else if (input_mode != oldnoconfig) {
431 if (!conf_cnt++)
432 printf(_("*\n* Restart config...\n*\n"));
433 rootEntry = menu_get_parent_menu(menu);
434 conf(rootEntry);
435 }
425 } 436 }
426 } 437 }
427 438
@@ -429,6 +440,22 @@ static void check_conf(struct menu *menu)
429 check_conf(child); 440 check_conf(child);
430} 441}
431 442
443static struct option long_opts[] = {
444 {"oldaskconfig", no_argument, NULL, oldaskconfig},
445 {"oldconfig", no_argument, NULL, oldconfig},
446 {"silentoldconfig", no_argument, NULL, silentoldconfig},
447 {"defconfig", optional_argument, NULL, defconfig},
448 {"savedefconfig", required_argument, NULL, savedefconfig},
449 {"allnoconfig", no_argument, NULL, allnoconfig},
450 {"allyesconfig", no_argument, NULL, allyesconfig},
451 {"allmodconfig", no_argument, NULL, allmodconfig},
452 {"alldefconfig", no_argument, NULL, alldefconfig},
453 {"randconfig", no_argument, NULL, randconfig},
454 {"listnewconfig", no_argument, NULL, listnewconfig},
455 {"oldnoconfig", no_argument, NULL, oldnoconfig},
456 {NULL, 0, NULL, 0}
457};
458
432int main(int ac, char **av) 459int main(int ac, char **av)
433{ 460{
434 int opt; 461 int opt;
@@ -439,32 +466,17 @@ int main(int ac, char **av)
439 bindtextdomain(PACKAGE, LOCALEDIR); 466 bindtextdomain(PACKAGE, LOCALEDIR);
440 textdomain(PACKAGE); 467 textdomain(PACKAGE);
441 468
442 while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) { 469 while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
470 input_mode = (enum input_mode)opt;
443 switch (opt) { 471 switch (opt) {
444 case 'o': 472 case silentoldconfig:
445 input_mode = ask_silent;
446 break;
447 case 's':
448 input_mode = ask_silent;
449 sync_kconfig = 1; 473 sync_kconfig = 1;
450 break; 474 break;
451 case 'd': 475 case defconfig:
452 input_mode = set_default; 476 case savedefconfig:
453 break;
454 case 'D':
455 input_mode = set_default;
456 defconfig_file = optarg; 477 defconfig_file = optarg;
457 break; 478 break;
458 case 'n': 479 case randconfig:
459 input_mode = set_no;
460 break;
461 case 'm':
462 input_mode = set_mod;
463 break;
464 case 'y':
465 input_mode = set_yes;
466 break;
467 case 'r':
468 { 480 {
469 struct timeval now; 481 struct timeval now;
470 unsigned int seed; 482 unsigned int seed;
@@ -477,17 +489,12 @@ int main(int ac, char **av)
477 489
478 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); 490 seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
479 srand(seed); 491 srand(seed);
480
481 input_mode = set_random;
482 break; 492 break;
483 } 493 }
484 case 'h': 494 case '?':
485 printf(_("See README for usage info\n"));
486 exit(0);
487 break;
488 default:
489 fprintf(stderr, _("See README for usage info\n")); 495 fprintf(stderr, _("See README for usage info\n"));
490 exit(1); 496 exit(1);
497 break;
491 } 498 }
492 } 499 }
493 if (ac == optind) { 500 if (ac == optind) {
@@ -512,7 +519,7 @@ int main(int ac, char **av)
512 } 519 }
513 520
514 switch (input_mode) { 521 switch (input_mode) {
515 case set_default: 522 case defconfig:
516 if (!defconfig_file) 523 if (!defconfig_file)
517 defconfig_file = conf_get_default_confname(); 524 defconfig_file = conf_get_default_confname();
518 if (conf_read(defconfig_file)) { 525 if (conf_read(defconfig_file)) {
@@ -522,25 +529,32 @@ int main(int ac, char **av)
522 exit(1); 529 exit(1);
523 } 530 }
524 break; 531 break;
525 case ask_silent: 532 case savedefconfig:
526 case ask_all: 533 conf_read(NULL);
527 case ask_new: 534 break;
535 case silentoldconfig:
536 case oldaskconfig:
537 case oldconfig:
538 case listnewconfig:
539 case oldnoconfig:
528 conf_read(NULL); 540 conf_read(NULL);
529 break; 541 break;
530 case set_no: 542 case allnoconfig:
531 case set_mod: 543 case allyesconfig:
532 case set_yes: 544 case allmodconfig:
533 case set_random: 545 case alldefconfig:
546 case randconfig:
534 name = getenv("KCONFIG_ALLCONFIG"); 547 name = getenv("KCONFIG_ALLCONFIG");
535 if (name && !stat(name, &tmpstat)) { 548 if (name && !stat(name, &tmpstat)) {
536 conf_read_simple(name, S_DEF_USER); 549 conf_read_simple(name, S_DEF_USER);
537 break; 550 break;
538 } 551 }
539 switch (input_mode) { 552 switch (input_mode) {
540 case set_no: name = "allno.config"; break; 553 case allnoconfig: name = "allno.config"; break;
541 case set_mod: name = "allmod.config"; break; 554 case allyesconfig: name = "allyes.config"; break;
542 case set_yes: name = "allyes.config"; break; 555 case allmodconfig: name = "allmod.config"; break;
543 case set_random: name = "allrandom.config"; break; 556 case alldefconfig: name = "alldef.config"; break;
557 case randconfig: name = "allrandom.config"; break;
544 default: break; 558 default: break;
545 } 559 }
546 if (!stat(name, &tmpstat)) 560 if (!stat(name, &tmpstat))
@@ -565,33 +579,42 @@ int main(int ac, char **av)
565 } 579 }
566 580
567 switch (input_mode) { 581 switch (input_mode) {
568 case set_no: 582 case allnoconfig:
569 conf_set_all_new_symbols(def_no); 583 conf_set_all_new_symbols(def_no);
570 break; 584 break;
571 case set_yes: 585 case allyesconfig:
572 conf_set_all_new_symbols(def_yes); 586 conf_set_all_new_symbols(def_yes);
573 break; 587 break;
574 case set_mod: 588 case allmodconfig:
575 conf_set_all_new_symbols(def_mod); 589 conf_set_all_new_symbols(def_mod);
576 break; 590 break;
577 case set_random: 591 case alldefconfig:
592 conf_set_all_new_symbols(def_default);
593 break;
594 case randconfig:
578 conf_set_all_new_symbols(def_random); 595 conf_set_all_new_symbols(def_random);
579 break; 596 break;
580 case set_default: 597 case defconfig:
581 conf_set_all_new_symbols(def_default); 598 conf_set_all_new_symbols(def_default);
582 break; 599 break;
583 case ask_new: 600 case savedefconfig:
584 case ask_all: 601 break;
602 case oldaskconfig:
585 rootEntry = &rootmenu; 603 rootEntry = &rootmenu;
586 conf(&rootmenu); 604 conf(&rootmenu);
587 input_mode = ask_silent; 605 input_mode = silentoldconfig;
588 /* fall through */ 606 /* fall through */
589 case ask_silent: 607 case oldconfig:
608 case listnewconfig:
609 case oldnoconfig:
610 case silentoldconfig:
590 /* Update until a loop caused no more changes */ 611 /* Update until a loop caused no more changes */
591 do { 612 do {
592 conf_cnt = 0; 613 conf_cnt = 0;
593 check_conf(&rootmenu); 614 check_conf(&rootmenu);
594 } while (conf_cnt); 615 } while (conf_cnt &&
616 (input_mode != listnewconfig &&
617 input_mode != oldnoconfig));
595 break; 618 break;
596 } 619 }
597 620
@@ -607,7 +630,13 @@ int main(int ac, char **av)
607 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n")); 630 fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
608 return 1; 631 return 1;
609 } 632 }
610 } else { 633 } else if (input_mode == savedefconfig) {
634 if (conf_write_defconfig(defconfig_file)) {
635 fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
636 defconfig_file);
637 return 1;
638 }
639 } else if (input_mode != listnewconfig) {
611 if (conf_write(NULL)) { 640 if (conf_write(NULL)) {
612 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); 641 fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
613 exit(1); 642 exit(1);
@@ -615,3 +644,14 @@ int main(int ac, char **av)
615 } 644 }
616 return 0; 645 return 0;
617} 646}
647/*
648 * Helper function to facilitate fgets() by Jean Sacren.
649 */
650void xfgets(str, size, in)
651 char *str;
652 int size;
653 FILE *in;
654{
655 if (fgets(str, size, in) == NULL)
656 fprintf(stderr, "\nError in reading or end of file.\n");
657}
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index c4dec80cfd8e..515253fe46cf 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -170,8 +170,11 @@ int conf_read_simple(const char *name, int def)
170 if (in) 170 if (in)
171 goto load; 171 goto load;
172 sym_add_change_count(1); 172 sym_add_change_count(1);
173 if (!sym_defconfig_list) 173 if (!sym_defconfig_list) {
174 if (modules_sym)
175 sym_calc_value(modules_sym);
174 return 1; 176 return 1;
177 }
175 178
176 for_all_defaults(sym_defconfig_list, prop) { 179 for_all_defaults(sym_defconfig_list, prop) {
177 if (expr_calc_value(prop->visible.expr) == no || 180 if (expr_calc_value(prop->visible.expr) == no ||
@@ -396,15 +399,150 @@ int conf_read(const char *name)
396 return 0; 399 return 0;
397} 400}
398 401
402/* Write a S_STRING */
403static void conf_write_string(bool headerfile, const char *name,
404 const char *str, FILE *out)
405{
406 int l;
407 if (headerfile)
408 fprintf(out, "#define CONFIG_%s \"", name);
409 else
410 fprintf(out, "CONFIG_%s=\"", name);
411
412 while (1) {
413 l = strcspn(str, "\"\\");
414 if (l) {
415 xfwrite(str, l, 1, out);
416 str += l;
417 }
418 if (!*str)
419 break;
420 fprintf(out, "\\%c", *str++);
421 }
422 fputs("\"\n", out);
423}
424
425static void conf_write_symbol(struct symbol *sym, enum symbol_type type,
426 FILE *out, bool write_no)
427{
428 const char *str;
429
430 switch (type) {
431 case S_BOOLEAN:
432 case S_TRISTATE:
433 switch (sym_get_tristate_value(sym)) {
434 case no:
435 if (write_no)
436 fprintf(out, "# CONFIG_%s is not set\n", sym->name);
437 break;
438 case mod:
439 fprintf(out, "CONFIG_%s=m\n", sym->name);
440 break;
441 case yes:
442 fprintf(out, "CONFIG_%s=y\n", sym->name);
443 break;
444 }
445 break;
446 case S_STRING:
447 conf_write_string(false, sym->name, sym_get_string_value(sym), out);
448 break;
449 case S_HEX:
450 case S_INT:
451 str = sym_get_string_value(sym);
452 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
453 break;
454 case S_OTHER:
455 case S_UNKNOWN:
456 break;
457 }
458}
459
460/*
461 * Write out a minimal config.
462 * All values that has default values are skipped as this is redundant.
463 */
464int conf_write_defconfig(const char *filename)
465{
466 struct symbol *sym;
467 struct menu *menu;
468 FILE *out;
469
470 out = fopen(filename, "w");
471 if (!out)
472 return 1;
473
474 sym_clear_all_valid();
475
476 /* Traverse all menus to find all relevant symbols */
477 menu = rootmenu.list;
478
479 while (menu != NULL)
480 {
481 sym = menu->sym;
482 if (sym == NULL) {
483 if (!menu_is_visible(menu))
484 goto next_menu;
485 } else if (!sym_is_choice(sym)) {
486 sym_calc_value(sym);
487 if (!(sym->flags & SYMBOL_WRITE))
488 goto next_menu;
489 sym->flags &= ~SYMBOL_WRITE;
490 /* If we cannot change the symbol - skip */
491 if (!sym_is_changable(sym))
492 goto next_menu;
493 /* If symbol equals to default value - skip */
494 if (strcmp(sym_get_string_value(sym), sym_get_string_default(sym)) == 0)
495 goto next_menu;
496
497 /*
498 * If symbol is a choice value and equals to the
499 * default for a choice - skip.
500 * But only if value is bool and equal to "y" and
501 * choice is not "optional".
502 * (If choice is "optional" then all values can be "n")
503 */
504 if (sym_is_choice_value(sym)) {
505 struct symbol *cs;
506 struct symbol *ds;
507
508 cs = prop_get_symbol(sym_get_choice_prop(sym));
509 ds = sym_choice_default(cs);
510 if (!sym_is_optional(cs) && sym == ds) {
511 if ((sym->type == S_BOOLEAN) &&
512 sym_get_tristate_value(sym) == yes)
513 goto next_menu;
514 }
515 }
516 conf_write_symbol(sym, sym->type, out, true);
517 }
518next_menu:
519 if (menu->list != NULL) {
520 menu = menu->list;
521 }
522 else if (menu->next != NULL) {
523 menu = menu->next;
524 } else {
525 while ((menu = menu->parent)) {
526 if (menu->next != NULL) {
527 menu = menu->next;
528 break;
529 }
530 }
531 }
532 }
533 fclose(out);
534 return 0;
535}
536
399int conf_write(const char *name) 537int conf_write(const char *name)
400{ 538{
401 FILE *out; 539 FILE *out;
402 struct symbol *sym; 540 struct symbol *sym;
403 struct menu *menu; 541 struct menu *menu;
404 const char *basename; 542 const char *basename;
405 char dirname[128], tmpname[128], newname[128];
406 int type, l;
407 const char *str; 543 const char *str;
544 char dirname[128], tmpname[128], newname[128];
545 enum symbol_type type;
408 time_t now; 546 time_t now;
409 int use_timestamp = 1; 547 int use_timestamp = 1;
410 char *env; 548 char *env;
@@ -484,50 +622,11 @@ int conf_write(const char *name)
484 if (modules_sym->curr.tri == no) 622 if (modules_sym->curr.tri == no)
485 type = S_BOOLEAN; 623 type = S_BOOLEAN;
486 } 624 }
487 switch (type) { 625 /* Write config symbol to file */
488 case S_BOOLEAN: 626 conf_write_symbol(sym, type, out, true);
489 case S_TRISTATE:
490 switch (sym_get_tristate_value(sym)) {
491 case no:
492 fprintf(out, "# CONFIG_%s is not set\n", sym->name);
493 break;
494 case mod:
495 fprintf(out, "CONFIG_%s=m\n", sym->name);
496 break;
497 case yes:
498 fprintf(out, "CONFIG_%s=y\n", sym->name);
499 break;
500 }
501 break;
502 case S_STRING:
503 str = sym_get_string_value(sym);
504 fprintf(out, "CONFIG_%s=\"", sym->name);
505 while (1) {
506 l = strcspn(str, "\"\\");
507 if (l) {
508 fwrite(str, l, 1, out);
509 str += l;
510 }
511 if (!*str)
512 break;
513 fprintf(out, "\\%c", *str++);
514 }
515 fputs("\"\n", out);
516 break;
517 case S_HEX:
518 str = sym_get_string_value(sym);
519 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
520 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
521 break;
522 }
523 case S_INT:
524 str = sym_get_string_value(sym);
525 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
526 break;
527 }
528 } 627 }
529 628
530 next: 629next:
531 if (menu->list) { 630 if (menu->list) {
532 menu = menu->list; 631 menu = menu->list;
533 continue; 632 continue;
@@ -679,7 +778,7 @@ int conf_write_autoconf(void)
679 const char *name; 778 const char *name;
680 FILE *out, *tristate, *out_h; 779 FILE *out, *tristate, *out_h;
681 time_t now; 780 time_t now;
682 int i, l; 781 int i;
683 782
684 sym_clear_all_valid(); 783 sym_clear_all_valid();
685 784
@@ -729,6 +828,11 @@ int conf_write_autoconf(void)
729 sym_calc_value(sym); 828 sym_calc_value(sym);
730 if (!(sym->flags & SYMBOL_WRITE) || !sym->name) 829 if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
731 continue; 830 continue;
831
832 /* write symbol to config file */
833 conf_write_symbol(sym, sym->type, out, false);
834
835 /* update autoconf and tristate files */
732 switch (sym->type) { 836 switch (sym->type) {
733 case S_BOOLEAN: 837 case S_BOOLEAN:
734 case S_TRISTATE: 838 case S_TRISTATE:
@@ -736,12 +840,10 @@ int conf_write_autoconf(void)
736 case no: 840 case no:
737 break; 841 break;
738 case mod: 842 case mod:
739 fprintf(out, "CONFIG_%s=m\n", sym->name);
740 fprintf(tristate, "CONFIG_%s=M\n", sym->name); 843 fprintf(tristate, "CONFIG_%s=M\n", sym->name);
741 fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); 844 fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
742 break; 845 break;
743 case yes: 846 case yes:
744 fprintf(out, "CONFIG_%s=y\n", sym->name);
745 if (sym->type == S_TRISTATE) 847 if (sym->type == S_TRISTATE)
746 fprintf(tristate, "CONFIG_%s=Y\n", 848 fprintf(tristate, "CONFIG_%s=Y\n",
747 sym->name); 849 sym->name);
@@ -750,35 +852,16 @@ int conf_write_autoconf(void)
750 } 852 }
751 break; 853 break;
752 case S_STRING: 854 case S_STRING:
753 str = sym_get_string_value(sym); 855 conf_write_string(true, sym->name, sym_get_string_value(sym), out_h);
754 fprintf(out, "CONFIG_%s=\"", sym->name);
755 fprintf(out_h, "#define CONFIG_%s \"", sym->name);
756 while (1) {
757 l = strcspn(str, "\"\\");
758 if (l) {
759 fwrite(str, l, 1, out);
760 fwrite(str, l, 1, out_h);
761 str += l;
762 }
763 if (!*str)
764 break;
765 fprintf(out, "\\%c", *str);
766 fprintf(out_h, "\\%c", *str);
767 str++;
768 }
769 fputs("\"\n", out);
770 fputs("\"\n", out_h);
771 break; 856 break;
772 case S_HEX: 857 case S_HEX:
773 str = sym_get_string_value(sym); 858 str = sym_get_string_value(sym);
774 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) { 859 if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
775 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
776 fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str); 860 fprintf(out_h, "#define CONFIG_%s 0x%s\n", sym->name, str);
777 break; 861 break;
778 } 862 }
779 case S_INT: 863 case S_INT:
780 str = sym_get_string_value(sym); 864 str = sym_get_string_value(sym);
781 fprintf(out, "CONFIG_%s=%s\n", sym->name, str);
782 fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str); 865 fprintf(out_h, "#define CONFIG_%s %s\n", sym->name, str);
783 break; 866 break;
784 default: 867 default:
@@ -837,13 +920,73 @@ void conf_set_changed_callback(void (*fn)(void))
837 conf_changed_callback = fn; 920 conf_changed_callback = fn;
838} 921}
839 922
923static void randomize_choice_values(struct symbol *csym)
924{
925 struct property *prop;
926 struct symbol *sym;
927 struct expr *e;
928 int cnt, def;
840 929
841void conf_set_all_new_symbols(enum conf_def_mode mode) 930 /*
931 * If choice is mod then we may have more items slected
932 * and if no then no-one.
933 * In both cases stop.
934 */
935 if (csym->curr.tri != yes)
936 return;
937
938 prop = sym_get_choice_prop(csym);
939
940 /* count entries in choice block */
941 cnt = 0;
942 expr_list_for_each_sym(prop->expr, e, sym)
943 cnt++;
944
945 /*
946 * find a random value and set it to yes,
947 * set the rest to no so we have only one set
948 */
949 def = (rand() % cnt);
950
951 cnt = 0;
952 expr_list_for_each_sym(prop->expr, e, sym) {
953 if (def == cnt++) {
954 sym->def[S_DEF_USER].tri = yes;
955 csym->def[S_DEF_USER].val = sym;
956 }
957 else {
958 sym->def[S_DEF_USER].tri = no;
959 }
960 }
961 csym->flags |= SYMBOL_DEF_USER;
962 /* clear VALID to get value calculated */
963 csym->flags &= ~(SYMBOL_VALID);
964}
965
966static void set_all_choice_values(struct symbol *csym)
842{ 967{
843 struct symbol *sym, *csym;
844 struct property *prop; 968 struct property *prop;
969 struct symbol *sym;
845 struct expr *e; 970 struct expr *e;
846 int i, cnt, def; 971
972 prop = sym_get_choice_prop(csym);
973
974 /*
975 * Set all non-assinged choice values to no
976 */
977 expr_list_for_each_sym(prop->expr, e, sym) {
978 if (!sym_has_value(sym))
979 sym->def[S_DEF_USER].tri = no;
980 }
981 csym->flags |= SYMBOL_DEF_USER;
982 /* clear VALID to get value calculated */
983 csym->flags &= ~(SYMBOL_VALID);
984}
985
986void conf_set_all_new_symbols(enum conf_def_mode mode)
987{
988 struct symbol *sym, *csym;
989 int i, cnt;
847 990
848 for_all_symbols(i, sym) { 991 for_all_symbols(i, sym) {
849 if (sym_has_value(sym)) 992 if (sym_has_value(sym))
@@ -862,7 +1005,8 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
862 sym->def[S_DEF_USER].tri = no; 1005 sym->def[S_DEF_USER].tri = no;
863 break; 1006 break;
864 case def_random: 1007 case def_random:
865 sym->def[S_DEF_USER].tri = (tristate)(rand() % 3); 1008 cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;
1009 sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
866 break; 1010 break;
867 default: 1011 default:
868 continue; 1012 continue;
@@ -878,8 +1022,6 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
878 1022
879 sym_clear_all_valid(); 1023 sym_clear_all_valid();
880 1024
881 if (mode != def_random)
882 return;
883 /* 1025 /*
884 * We have different type of choice blocks. 1026 * We have different type of choice blocks.
885 * If curr.tri equal to mod then we can select several 1027 * If curr.tri equal to mod then we can select several
@@ -894,35 +1036,9 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
894 continue; 1036 continue;
895 1037
896 sym_calc_value(csym); 1038 sym_calc_value(csym);
897 1039 if (mode == def_random)
898 if (csym->curr.tri != yes) 1040 randomize_choice_values(csym);
899 continue; 1041 else
900 1042 set_all_choice_values(csym);
901 prop = sym_get_choice_prop(csym);
902
903 /* count entries in choice block */
904 cnt = 0;
905 expr_list_for_each_sym(prop->expr, e, sym)
906 cnt++;
907
908 /*
909 * find a random value and set it to yes,
910 * set the rest to no so we have only one set
911 */
912 def = (rand() % cnt);
913
914 cnt = 0;
915 expr_list_for_each_sym(prop->expr, e, sym) {
916 if (def == cnt++) {
917 sym->def[S_DEF_USER].tri = yes;
918 csym->def[S_DEF_USER].val = sym;
919 }
920 else {
921 sym->def[S_DEF_USER].tri = no;
922 }
923 }
924 csym->flags |= SYMBOL_DEF_USER;
925 /* clear VALID to get value calculated */
926 csym->flags &= ~(SYMBOL_VALID);
927 } 1043 }
928} 1044}
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index d83f2322893a..330e7c0048a8 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1087,7 +1087,7 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *
1087 1087
1088static void expr_print_file_helper(void *data, struct symbol *sym, const char *str) 1088static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
1089{ 1089{
1090 fwrite(str, strlen(str), 1, data); 1090 xfwrite(str, strlen(str), 1, data);
1091} 1091}
1092 1092
1093void expr_fprint(struct expr *e, FILE *out) 1093void expr_fprint(struct expr *e, FILE *out)
@@ -1121,7 +1121,7 @@ static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *s
1121 } 1121 }
1122 1122
1123 str_append(gs, str); 1123 str_append(gs, str);
1124 if (sym) 1124 if (sym && sym->type != S_UNKNOWN)
1125 str_printf(gs, " [=%s]", sym_str); 1125 str_printf(gs, " [=%s]", sym_str);
1126} 1126}
1127 1127
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 891cd9ce9ba2..170459c224a1 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -83,6 +83,7 @@ struct symbol {
83 tristate visible; 83 tristate visible;
84 int flags; 84 int flags;
85 struct property *prop; 85 struct property *prop;
86 struct expr_value dir_dep;
86 struct expr_value rev_dep; 87 struct expr_value rev_dep;
87}; 88};
88 89
@@ -131,6 +132,7 @@ enum prop_type {
131 P_SELECT, /* select BAR */ 132 P_SELECT, /* select BAR */
132 P_RANGE, /* range 7..100 (for a symbol) */ 133 P_RANGE, /* range 7..100 (for a symbol) */
133 P_ENV, /* value from environment variable */ 134 P_ENV, /* value from environment variable */
135 P_SYMBOL, /* where a symbol is defined */
134}; 136};
135 137
136struct property { 138struct property {
diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index bef10411837f..d66988265f89 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -1114,7 +1114,7 @@ static gchar **fill_row(struct menu *menu)
1114 1114
1115 row[COL_OPTION] = 1115 row[COL_OPTION] =
1116 g_strdup_printf("%s %s", _(menu_get_prompt(menu)), 1116 g_strdup_printf("%s %s", _(menu_get_prompt(menu)),
1117 sym && sym_has_value(sym) ? "(NEW)" : ""); 1117 sym && !sym_has_value(sym) ? "(NEW)" : "");
1118 1118
1119 if (opt_mode == OPT_ALL && !menu_is_visible(menu)) 1119 if (opt_mode == OPT_ALL && !menu_is_visible(menu))
1120 row[COL_COLOR] = g_strdup("DarkGray"); 1120 row[COL_COLOR] = g_strdup("DarkGray");
@@ -1343,7 +1343,8 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
1343#endif 1343#endif
1344 1344
1345 if ((opt_mode == OPT_NORMAL && !menu_is_visible(child1)) || 1345 if ((opt_mode == OPT_NORMAL && !menu_is_visible(child1)) ||
1346 (opt_mode == OPT_PROMPT && !menu_has_prompt(child1))) { 1346 (opt_mode == OPT_PROMPT && !menu_has_prompt(child1)) ||
1347 (opt_mode == OPT_ALL && !menu_get_prompt(child1))) {
1347 1348
1348 /* remove node */ 1349 /* remove node */
1349 if (gtktree_iter_find_node(dst, menu1) != NULL) { 1350 if (gtktree_iter_find_node(dst, menu1) != NULL) {
@@ -1425,7 +1426,7 @@ static void display_tree(struct menu *menu)
1425 1426
1426 if ((opt_mode == OPT_NORMAL && menu_is_visible(child)) || 1427 if ((opt_mode == OPT_NORMAL && menu_is_visible(child)) ||
1427 (opt_mode == OPT_PROMPT && menu_has_prompt(child)) || 1428 (opt_mode == OPT_PROMPT && menu_has_prompt(child)) ||
1428 (opt_mode == OPT_ALL)) 1429 (opt_mode == OPT_ALL && menu_get_prompt(child)))
1429 place_node(child, fill_row(child)); 1430 place_node(child, fill_row(child));
1430#ifdef DEBUG 1431#ifdef DEBUG
1431 printf("%*c%s: ", indent, ' ', menu_get_prompt(child)); 1432 printf("%*c%s: ", indent, ' ', menu_get_prompt(child));
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index ce6549cdaccf..bdf71bd31412 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -72,6 +72,9 @@ void zconf_nextfile(const char *name);
72int zconf_lineno(void); 72int zconf_lineno(void);
73char *zconf_curname(void); 73char *zconf_curname(void);
74 74
75/* conf.c */
76void xfgets(char *str, int size, FILE *in);
77
75/* confdata.c */ 78/* confdata.c */
76const char *conf_get_configname(void); 79const char *conf_get_configname(void);
77const char *conf_get_autoconfig_name(void); 80const char *conf_get_autoconfig_name(void);
@@ -80,6 +83,13 @@ void sym_set_change_count(int count);
80void sym_add_change_count(int count); 83void sym_add_change_count(int count);
81void conf_set_all_new_symbols(enum conf_def_mode mode); 84void conf_set_all_new_symbols(enum conf_def_mode mode);
82 85
86/* confdata.c and expr.c */
87static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
88{
89 if (fwrite(str, len, count, out) < count)
90 fprintf(stderr, "\nError in writing or end of file.\n");
91}
92
83/* kconfig_load.c */ 93/* kconfig_load.c */
84void kconfig_load(void); 94void kconfig_load(void);
85 95
@@ -126,6 +136,8 @@ void sym_init(void);
126void sym_clear_all_valid(void); 136void sym_clear_all_valid(void);
127void sym_set_all_changed(void); 137void sym_set_all_changed(void);
128void sym_set_changed(struct symbol *sym); 138void sym_set_changed(struct symbol *sym);
139struct symbol *sym_choice_default(struct symbol *sym);
140const char *sym_get_string_default(struct symbol *sym);
129struct symbol *sym_check_deps(struct symbol *sym); 141struct symbol *sym_check_deps(struct symbol *sym);
130struct property *prop_alloc(enum prop_type type, struct symbol *sym); 142struct property *prop_alloc(enum prop_type type, struct symbol *sym);
131struct symbol *prop_get_symbol(struct property *prop); 143struct symbol *prop_get_symbol(struct property *prop);
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 7cadcad8233b..9a948c9ce44e 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -3,6 +3,7 @@
3P(conf_parse,void,(const char *name)); 3P(conf_parse,void,(const char *name));
4P(conf_read,int,(const char *name)); 4P(conf_read,int,(const char *name));
5P(conf_read_simple,int,(const char *name, int)); 5P(conf_read_simple,int,(const char *name, int));
6P(conf_write_defconfig,int,(const char *name));
6P(conf_write,int,(const char *name)); 7P(conf_write,int,(const char *name));
7P(conf_write_autoconf,int,(void)); 8P(conf_write_autoconf,int,(void));
8P(conf_get_changed,bool,(void)); 9P(conf_get_changed,bool,(void));
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index bcc6f19c3a35..a2eb80fbc896 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -31,6 +31,10 @@ static int list_width, check_x, item_x;
31static void print_item(WINDOW * win, int choice, int selected) 31static void print_item(WINDOW * win, int choice, int selected)
32{ 32{
33 int i; 33 int i;
34 char *list_item = malloc(list_width + 1);
35
36 strncpy(list_item, item_str(), list_width - item_x);
37 list_item[list_width - item_x] = '\0';
34 38
35 /* Clear 'residue' of last item */ 39 /* Clear 'residue' of last item */
36 wattrset(win, dlg.menubox.atr); 40 wattrset(win, dlg.menubox.atr);
@@ -45,13 +49,14 @@ static void print_item(WINDOW * win, int choice, int selected)
45 wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); 49 wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');
46 50
47 wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); 51 wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
48 mvwaddch(win, choice, item_x, item_str()[0]); 52 mvwaddch(win, choice, item_x, list_item[0]);
49 wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); 53 wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
50 waddstr(win, (char *)item_str() + 1); 54 waddstr(win, list_item + 1);
51 if (selected) { 55 if (selected) {
52 wmove(win, choice, check_x + 1); 56 wmove(win, choice, check_x + 1);
53 wrefresh(win); 57 wrefresh(win);
54 } 58 }
59 free(list_item);
55} 60}
56 61
57/* 62/*
@@ -175,6 +180,7 @@ do_resize:
175 check_x = 0; 180 check_x = 0;
176 item_foreach() 181 item_foreach()
177 check_x = MAX(check_x, strlen(item_str()) + 4); 182 check_x = MAX(check_x, strlen(item_str()) + 4);
183 check_x = MIN(check_x, list_width);
178 184
179 check_x = (list_width - check_x) / 2; 185 check_x = (list_width - check_x) / 2;
180 item_x = check_x + 4; 186 item_x = check_x + 4;
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 2c83d3234d30..d2f6e056c058 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -74,7 +74,7 @@ static const char mconf_readme[] = N_(
74"\n" 74"\n"
75" Shortcut: Press <H> or <?>.\n" 75" Shortcut: Press <H> or <?>.\n"
76"\n" 76"\n"
77"o To show hidden options, press <Z>.\n" 77"o To toggle the display of hidden options, press <Z>.\n"
78"\n" 78"\n"
79"\n" 79"\n"
80"Radiolists (Choice lists)\n" 80"Radiolists (Choice lists)\n"
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 203632cc30bd..edda8b49619d 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -58,6 +58,8 @@ void menu_add_entry(struct symbol *sym)
58 *last_entry_ptr = menu; 58 *last_entry_ptr = menu;
59 last_entry_ptr = &menu->next; 59 last_entry_ptr = &menu->next;
60 current_entry = menu; 60 current_entry = menu;
61 if (sym)
62 menu_add_symbol(P_SYMBOL, sym, NULL);
61} 63}
62 64
63void menu_end_entry(void) 65void menu_end_entry(void)
@@ -318,6 +320,8 @@ void menu_finalize(struct menu *parent)
318 parent->next = last_menu->next; 320 parent->next = last_menu->next;
319 last_menu->next = NULL; 321 last_menu->next = NULL;
320 } 322 }
323
324 sym->dir_dep.expr = parent->dep;
321 } 325 }
322 for (menu = parent->list; menu; menu = menu->next) { 326 for (menu = parent->list; menu; menu = menu->next) {
323 if (sym && sym_is_choice(sym) && 327 if (sym && sym_is_choice(sym) &&
@@ -419,9 +423,13 @@ bool menu_is_visible(struct menu *menu)
419 if (!sym || sym_get_tristate_value(menu->sym) == no) 423 if (!sym || sym_get_tristate_value(menu->sym) == no)
420 return false; 424 return false;
421 425
422 for (child = menu->list; child; child = child->next) 426 for (child = menu->list; child; child = child->next) {
423 if (menu_is_visible(child)) 427 if (menu_is_visible(child)) {
428 if (sym)
429 sym->flags |= SYMBOL_DEF_USER;
424 return true; 430 return true;
431 }
432 }
425 433
426 return false; 434 return false;
427} 435}
@@ -501,9 +509,19 @@ void get_symbol_str(struct gstr *r, struct symbol *sym)
501 bool hit; 509 bool hit;
502 struct property *prop; 510 struct property *prop;
503 511
504 if (sym && sym->name) 512 if (sym && sym->name) {
505 str_printf(r, "Symbol: %s [=%s]\n", sym->name, 513 str_printf(r, "Symbol: %s [=%s]\n", sym->name,
506 sym_get_string_value(sym)); 514 sym_get_string_value(sym));
515 str_printf(r, "Type : %s\n", sym_type_name(sym->type));
516 if (sym->type == S_INT || sym->type == S_HEX) {
517 prop = sym_get_range_prop(sym);
518 if (prop) {
519 str_printf(r, "Range : ");
520 expr_gstr_print(prop->expr, r);
521 str_append(r, "\n");
522 }
523 }
524 }
507 for_all_prompts(sym, prop) 525 for_all_prompts(sym, prop)
508 get_prompt_str(r, prop); 526 get_prompt_str(r, prop);
509 hit = false; 527 hit = false;
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 762caf80ce37..2ba71bcd38e6 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -676,6 +676,8 @@ static void *item_data(void)
676 struct mitem *mcur; 676 struct mitem *mcur;
677 677
678 cur = current_item(curses_menu); 678 cur = current_item(curses_menu);
679 if (!cur)
680 return NULL;
679 mcur = (struct mitem *) item_userptr(cur); 681 mcur = (struct mitem *) item_userptr(cur);
680 return mcur->usrptr; 682 return mcur->usrptr;
681 683
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index 00c51507cfcc..820df2d1217b 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -58,11 +58,10 @@ QValueList<int> ConfigSettings::readSizes(const QString& key, bool *ok)
58{ 58{
59 QValueList<int> result; 59 QValueList<int> result;
60 QStringList entryList = readListEntry(key, ok); 60 QStringList entryList = readListEntry(key, ok);
61 if (ok) { 61 QStringList::Iterator it;
62 QStringList::Iterator it; 62
63 for (it = entryList.begin(); it != entryList.end(); ++it) 63 for (it = entryList.begin(); it != entryList.end(); ++it)
64 result.push_back((*it).toInt()); 64 result.push_back((*it).toInt());
65 }
66 65
67 return result; 66 return result;
68} 67}
@@ -149,7 +148,7 @@ void ConfigItem::updateMenu(void)
149 case S_TRISTATE: 148 case S_TRISTATE:
150 char ch; 149 char ch;
151 150
152 if (!sym_is_changable(sym) && !list->showAll) { 151 if (!sym_is_changable(sym) && list->optMode == normalOpt) {
153 setPixmap(promptColIdx, 0); 152 setPixmap(promptColIdx, 0);
154 setText(noColIdx, QString::null); 153 setText(noColIdx, QString::null);
155 setText(modColIdx, QString::null); 154 setText(modColIdx, QString::null);
@@ -320,7 +319,7 @@ ConfigList::ConfigList(ConfigView* p, const char *name)
320 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no), 319 symbolYesPix(xpm_symbol_yes), symbolModPix(xpm_symbol_mod), symbolNoPix(xpm_symbol_no),
321 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no), 320 choiceYesPix(xpm_choice_yes), choiceNoPix(xpm_choice_no),
322 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void), 321 menuPix(xpm_menu), menuInvPix(xpm_menu_inv), menuBackPix(xpm_menuback), voidPix(xpm_void),
323 showAll(false), showName(false), showRange(false), showData(false), 322 showName(false), showRange(false), showData(false), optMode(normalOpt),
324 rootEntry(0), headerPopup(0) 323 rootEntry(0), headerPopup(0)
325{ 324{
326 int i; 325 int i;
@@ -337,10 +336,10 @@ ConfigList::ConfigList(ConfigView* p, const char *name)
337 336
338 if (name) { 337 if (name) {
339 configSettings->beginGroup(name); 338 configSettings->beginGroup(name);
340 showAll = configSettings->readBoolEntry("/showAll", false);
341 showName = configSettings->readBoolEntry("/showName", false); 339 showName = configSettings->readBoolEntry("/showName", false);
342 showRange = configSettings->readBoolEntry("/showRange", false); 340 showRange = configSettings->readBoolEntry("/showRange", false);
343 showData = configSettings->readBoolEntry("/showData", false); 341 showData = configSettings->readBoolEntry("/showData", false);
342 optMode = (enum optionMode)configSettings->readNumEntry("/optionMode", false);
344 configSettings->endGroup(); 343 configSettings->endGroup();
345 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings())); 344 connect(configApp, SIGNAL(aboutToQuit()), SLOT(saveSettings()));
346 } 345 }
@@ -352,6 +351,17 @@ ConfigList::ConfigList(ConfigView* p, const char *name)
352 reinit(); 351 reinit();
353} 352}
354 353
354bool ConfigList::menuSkip(struct menu *menu)
355{
356 if (optMode == normalOpt && menu_is_visible(menu))
357 return false;
358 if (optMode == promptOpt && menu_has_prompt(menu))
359 return false;
360 if (optMode == allOpt)
361 return false;
362 return true;
363}
364
355void ConfigList::reinit(void) 365void ConfigList::reinit(void)
356{ 366{
357 removeColumn(dataColIdx); 367 removeColumn(dataColIdx);
@@ -380,7 +390,7 @@ void ConfigList::saveSettings(void)
380 configSettings->writeEntry("/showName", showName); 390 configSettings->writeEntry("/showName", showName);
381 configSettings->writeEntry("/showRange", showRange); 391 configSettings->writeEntry("/showRange", showRange);
382 configSettings->writeEntry("/showData", showData); 392 configSettings->writeEntry("/showData", showData);
383 configSettings->writeEntry("/showAll", showAll); 393 configSettings->writeEntry("/optionMode", (int)optMode);
384 configSettings->endGroup(); 394 configSettings->endGroup();
385 } 395 }
386} 396}
@@ -606,7 +616,7 @@ void ConfigList::updateMenuList(P* parent, struct menu* menu)
606 } 616 }
607 617
608 visible = menu_is_visible(child); 618 visible = menu_is_visible(child);
609 if (showAll || visible) { 619 if (!menuSkip(child)) {
610 if (!child->sym && !child->list && !child->prompt) 620 if (!child->sym && !child->list && !child->prompt)
611 continue; 621 continue;
612 if (!item || item->menu != child) 622 if (!item || item->menu != child)
@@ -835,7 +845,10 @@ void ConfigList::contextMenuEvent(QContextMenuEvent *e)
835 e->ignore(); 845 e->ignore();
836} 846}
837 847
838ConfigView* ConfigView::viewList; 848ConfigView*ConfigView::viewList;
849QAction *ConfigView::showNormalAction;
850QAction *ConfigView::showAllAction;
851QAction *ConfigView::showPromptAction;
839 852
840ConfigView::ConfigView(QWidget* parent, const char *name) 853ConfigView::ConfigView(QWidget* parent, const char *name)
841 : Parent(parent, name) 854 : Parent(parent, name)
@@ -860,13 +873,16 @@ ConfigView::~ConfigView(void)
860 } 873 }
861} 874}
862 875
863void ConfigView::setShowAll(bool b) 876void ConfigView::setOptionMode(QAction *act)
864{ 877{
865 if (list->showAll != b) { 878 if (act == showNormalAction)
866 list->showAll = b; 879 list->optMode = normalOpt;
867 list->updateListAll(); 880 else if (act == showAllAction)
868 emit showAllChanged(b); 881 list->optMode = allOpt;
869 } 882 else
883 list->optMode = promptOpt;
884
885 list->updateListAll();
870} 886}
871 887
872void ConfigView::setShowName(bool b) 888void ConfigView::setShowName(bool b)
@@ -964,34 +980,6 @@ void ConfigInfoView::setInfo(struct menu *m)
964 menuInfo(); 980 menuInfo();
965} 981}
966 982
967void ConfigInfoView::setSource(const QString& name)
968{
969 const char *p = name.latin1();
970
971 menu = NULL;
972 sym = NULL;
973
974 switch (p[0]) {
975 case 'm':
976 struct menu *m;
977
978 if (sscanf(p, "m%p", &m) == 1 && menu != m) {
979 menu = m;
980 menuInfo();
981 emit menuSelected(menu);
982 }
983 break;
984 case 's':
985 struct symbol *s;
986
987 if (sscanf(p, "s%p", &s) == 1 && sym != s) {
988 sym = s;
989 symbolInfo();
990 }
991 break;
992 }
993}
994
995void ConfigInfoView::symbolInfo(void) 983void ConfigInfoView::symbolInfo(void)
996{ 984{
997 QString str; 985 QString str;
@@ -1349,11 +1337,24 @@ ConfigMainWindow::ConfigMainWindow(void)
1349 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool))); 1337 connect(showDataAction, SIGNAL(toggled(bool)), configView, SLOT(setShowData(bool)));
1350 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool))); 1338 connect(configView, SIGNAL(showDataChanged(bool)), showDataAction, SLOT(setOn(bool)));
1351 showDataAction->setOn(configList->showData); 1339 showDataAction->setOn(configList->showData);
1352 QAction *showAllAction = new QAction(NULL, _("Show All Options"), 0, this); 1340
1353 showAllAction->setToggleAction(TRUE); 1341 QActionGroup *optGroup = new QActionGroup(this);
1354 connect(showAllAction, SIGNAL(toggled(bool)), configView, SLOT(setShowAll(bool))); 1342 optGroup->setExclusive(TRUE);
1355 connect(showAllAction, SIGNAL(toggled(bool)), menuView, SLOT(setShowAll(bool))); 1343 connect(optGroup, SIGNAL(selected(QAction *)), configView,
1356 showAllAction->setOn(configList->showAll); 1344 SLOT(setOptionMode(QAction *)));
1345 connect(optGroup, SIGNAL(selected(QAction *)), menuView,
1346 SLOT(setOptionMode(QAction *)));
1347
1348 configView->showNormalAction = new QAction(NULL, _("Show Normal Options"), 0, optGroup);
1349 configView->showAllAction = new QAction(NULL, _("Show All Options"), 0, optGroup);
1350 configView->showPromptAction = new QAction(NULL, _("Show Prompt Options"), 0, optGroup);
1351 configView->showNormalAction->setToggleAction(TRUE);
1352 configView->showNormalAction->setOn(configList->optMode == normalOpt);
1353 configView->showAllAction->setToggleAction(TRUE);
1354 configView->showAllAction->setOn(configList->optMode == allOpt);
1355 configView->showPromptAction->setToggleAction(TRUE);
1356 configView->showPromptAction->setOn(configList->optMode == promptOpt);
1357
1357 QAction *showDebugAction = new QAction(NULL, _("Show Debug Info"), 0, this); 1358 QAction *showDebugAction = new QAction(NULL, _("Show Debug Info"), 0, this);
1358 showDebugAction->setToggleAction(TRUE); 1359 showDebugAction->setToggleAction(TRUE);
1359 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool))); 1360 connect(showDebugAction, SIGNAL(toggled(bool)), helpText, SLOT(setShowDebug(bool)));
@@ -1396,7 +1397,8 @@ ConfigMainWindow::ConfigMainWindow(void)
1396 showRangeAction->addTo(optionMenu); 1397 showRangeAction->addTo(optionMenu);
1397 showDataAction->addTo(optionMenu); 1398 showDataAction->addTo(optionMenu);
1398 optionMenu->insertSeparator(); 1399 optionMenu->insertSeparator();
1399 showAllAction->addTo(optionMenu); 1400 optGroup->addTo(optionMenu);
1401 optionMenu->insertSeparator();
1400 showDebugAction->addTo(optionMenu); 1402 showDebugAction->addTo(optionMenu);
1401 1403
1402 // create help menu 1404 // create help menu
@@ -1491,7 +1493,7 @@ void ConfigMainWindow::setMenuLink(struct menu *menu)
1491 ConfigList* list = NULL; 1493 ConfigList* list = NULL;
1492 ConfigItem* item; 1494 ConfigItem* item;
1493 1495
1494 if (!menu_is_visible(menu) && !configView->showAll()) 1496 if (configList->menuSkip(menu))
1495 return; 1497 return;
1496 1498
1497 switch (configList->mode) { 1499 switch (configList->mode) {
diff --git a/scripts/kconfig/qconf.h b/scripts/kconfig/qconf.h
index b3b5657b6b35..636a74b23bf9 100644
--- a/scripts/kconfig/qconf.h
+++ b/scripts/kconfig/qconf.h
@@ -44,6 +44,9 @@ enum colIdx {
44enum listMode { 44enum listMode {
45 singleMode, menuMode, symbolMode, fullMode, listMode 45 singleMode, menuMode, symbolMode, fullMode, listMode
46}; 46};
47enum optionMode {
48 normalOpt = 0, allOpt, promptOpt
49};
47 50
48class ConfigList : public QListView { 51class ConfigList : public QListView {
49 Q_OBJECT 52 Q_OBJECT
@@ -115,6 +118,8 @@ public:
115 void setAllOpen(bool open); 118 void setAllOpen(bool open);
116 void setParentMenu(void); 119 void setParentMenu(void);
117 120
121 bool menuSkip(struct menu *);
122
118 template <class P> 123 template <class P>
119 void updateMenuList(P*, struct menu*); 124 void updateMenuList(P*, struct menu*);
120 125
@@ -124,8 +129,9 @@ public:
124 QPixmap choiceYesPix, choiceNoPix; 129 QPixmap choiceYesPix, choiceNoPix;
125 QPixmap menuPix, menuInvPix, menuBackPix, voidPix; 130 QPixmap menuPix, menuInvPix, menuBackPix, voidPix;
126 131
127 bool showAll, showName, showRange, showData; 132 bool showName, showRange, showData;
128 enum listMode mode; 133 enum listMode mode;
134 enum optionMode optMode;
129 struct menu *rootEntry; 135 struct menu *rootEntry;
130 QColorGroup disabledColorGroup; 136 QColorGroup disabledColorGroup;
131 QColorGroup inactivedColorGroup; 137 QColorGroup inactivedColorGroup;
@@ -222,17 +228,15 @@ public:
222 static void updateList(ConfigItem* item); 228 static void updateList(ConfigItem* item);
223 static void updateListAll(void); 229 static void updateListAll(void);
224 230
225 bool showAll(void) const { return list->showAll; }
226 bool showName(void) const { return list->showName; } 231 bool showName(void) const { return list->showName; }
227 bool showRange(void) const { return list->showRange; } 232 bool showRange(void) const { return list->showRange; }
228 bool showData(void) const { return list->showData; } 233 bool showData(void) const { return list->showData; }
229public slots: 234public slots:
230 void setShowAll(bool);
231 void setShowName(bool); 235 void setShowName(bool);
232 void setShowRange(bool); 236 void setShowRange(bool);
233 void setShowData(bool); 237 void setShowData(bool);
238 void setOptionMode(QAction *);
234signals: 239signals:
235 void showAllChanged(bool);
236 void showNameChanged(bool); 240 void showNameChanged(bool);
237 void showRangeChanged(bool); 241 void showRangeChanged(bool);
238 void showDataChanged(bool); 242 void showDataChanged(bool);
@@ -242,6 +246,10 @@ public:
242 246
243 static ConfigView* viewList; 247 static ConfigView* viewList;
244 ConfigView* nextView; 248 ConfigView* nextView;
249
250 static QAction *showNormalAction;
251 static QAction *showAllAction;
252 static QAction *showPromptAction;
245}; 253};
246 254
247class ConfigInfoView : public QTextBrowser { 255class ConfigInfoView : public QTextBrowser {
@@ -254,7 +262,6 @@ public:
254public slots: 262public slots:
255 void setInfo(struct menu *menu); 263 void setInfo(struct menu *menu);
256 void saveSettings(void); 264 void saveSettings(void);
257 void setSource(const QString& name);
258 void setShowDebug(bool); 265 void setShowDebug(bool);
259 266
260signals: 267signals:
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 2e7a048e0cfc..1f8b305449db 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -205,6 +205,16 @@ static void sym_calc_visibility(struct symbol *sym)
205 } 205 }
206 if (sym_is_choice_value(sym)) 206 if (sym_is_choice_value(sym))
207 return; 207 return;
208 /* defaulting to "yes" if no explicit "depends on" are given */
209 tri = yes;
210 if (sym->dir_dep.expr)
211 tri = expr_calc_value(sym->dir_dep.expr);
212 if (tri == mod)
213 tri = yes;
214 if (sym->dir_dep.tri != tri) {
215 sym->dir_dep.tri = tri;
216 sym_set_changed(sym);
217 }
208 tri = no; 218 tri = no;
209 if (sym->rev_dep.expr) 219 if (sym->rev_dep.expr)
210 tri = expr_calc_value(sym->rev_dep.expr); 220 tri = expr_calc_value(sym->rev_dep.expr);
@@ -216,44 +226,63 @@ static void sym_calc_visibility(struct symbol *sym)
216 } 226 }
217} 227}
218 228
219static struct symbol *sym_calc_choice(struct symbol *sym) 229/*
230 * Find the default symbol for a choice.
231 * First try the default values for the choice symbol
232 * Next locate the first visible choice value
233 * Return NULL if none was found
234 */
235struct symbol *sym_choice_default(struct symbol *sym)
220{ 236{
221 struct symbol *def_sym; 237 struct symbol *def_sym;
222 struct property *prop; 238 struct property *prop;
223 struct expr *e; 239 struct expr *e;
224 240
225 /* is the user choice visible? */
226 def_sym = sym->def[S_DEF_USER].val;
227 if (def_sym) {
228 sym_calc_visibility(def_sym);
229 if (def_sym->visible != no)
230 return def_sym;
231 }
232
233 /* any of the defaults visible? */ 241 /* any of the defaults visible? */
234 for_all_defaults(sym, prop) { 242 for_all_defaults(sym, prop) {
235 prop->visible.tri = expr_calc_value(prop->visible.expr); 243 prop->visible.tri = expr_calc_value(prop->visible.expr);
236 if (prop->visible.tri == no) 244 if (prop->visible.tri == no)
237 continue; 245 continue;
238 def_sym = prop_get_symbol(prop); 246 def_sym = prop_get_symbol(prop);
239 sym_calc_visibility(def_sym);
240 if (def_sym->visible != no) 247 if (def_sym->visible != no)
241 return def_sym; 248 return def_sym;
242 } 249 }
243 250
244 /* just get the first visible value */ 251 /* just get the first visible value */
245 prop = sym_get_choice_prop(sym); 252 prop = sym_get_choice_prop(sym);
246 expr_list_for_each_sym(prop->expr, e, def_sym) { 253 expr_list_for_each_sym(prop->expr, e, def_sym)
247 sym_calc_visibility(def_sym);
248 if (def_sym->visible != no) 254 if (def_sym->visible != no)
249 return def_sym; 255 return def_sym;
250 }
251 256
252 /* no choice? reset tristate value */ 257 /* failed to locate any defaults */
253 sym->curr.tri = no;
254 return NULL; 258 return NULL;
255} 259}
256 260
261static struct symbol *sym_calc_choice(struct symbol *sym)
262{
263 struct symbol *def_sym;
264 struct property *prop;
265 struct expr *e;
266
267 /* first calculate all choice values' visibilities */
268 prop = sym_get_choice_prop(sym);
269 expr_list_for_each_sym(prop->expr, e, def_sym)
270 sym_calc_visibility(def_sym);
271
272 /* is the user choice visible? */
273 def_sym = sym->def[S_DEF_USER].val;
274 if (def_sym && def_sym->visible != no)
275 return def_sym;
276
277 def_sym = sym_choice_default(sym);
278
279 if (def_sym == NULL)
280 /* no choice? reset tristate value */
281 sym->curr.tri = no;
282
283 return def_sym;
284}
285
257void sym_calc_value(struct symbol *sym) 286void sym_calc_value(struct symbol *sym)
258{ 287{
259 struct symbol_value newval, oldval; 288 struct symbol_value newval, oldval;
@@ -321,6 +350,16 @@ void sym_calc_value(struct symbol *sym)
321 } 350 }
322 } 351 }
323 calc_newval: 352 calc_newval:
353#if 0
354 if (sym->dir_dep.tri == no && sym->rev_dep.tri != no) {
355 fprintf(stderr, "warning: (");
356 expr_fprint(sym->rev_dep.expr, stderr);
357 fprintf(stderr, ") selects %s which has unmet direct dependencies (",
358 sym->name);
359 expr_fprint(sym->dir_dep.expr, stderr);
360 fprintf(stderr, ")\n");
361 }
362#endif
324 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri); 363 newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
325 } 364 }
326 if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN) 365 if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
@@ -365,12 +404,13 @@ void sym_calc_value(struct symbol *sym)
365 404
366 if (sym_is_choice(sym)) { 405 if (sym_is_choice(sym)) {
367 struct symbol *choice_sym; 406 struct symbol *choice_sym;
368 int flags = sym->flags & (SYMBOL_CHANGED | SYMBOL_WRITE);
369 407
370 prop = sym_get_choice_prop(sym); 408 prop = sym_get_choice_prop(sym);
371 expr_list_for_each_sym(prop->expr, e, choice_sym) { 409 expr_list_for_each_sym(prop->expr, e, choice_sym) {
372 choice_sym->flags |= flags; 410 if ((sym->flags & SYMBOL_WRITE) &&
373 if (flags & SYMBOL_CHANGED) 411 choice_sym->visible != no)
412 choice_sym->flags |= SYMBOL_WRITE;
413 if (sym->flags & SYMBOL_CHANGED)
374 sym_set_changed(choice_sym); 414 sym_set_changed(choice_sym);
375 } 415 }
376 } 416 }
@@ -623,6 +663,80 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
623 return true; 663 return true;
624} 664}
625 665
666/*
667 * Find the default value associated to a symbol.
668 * For tristate symbol handle the modules=n case
669 * in which case "m" becomes "y".
670 * If the symbol does not have any default then fallback
671 * to the fixed default values.
672 */
673const char *sym_get_string_default(struct symbol *sym)
674{
675 struct property *prop;
676 struct symbol *ds;
677 const char *str;
678 tristate val;
679
680 sym_calc_visibility(sym);
681 sym_calc_value(modules_sym);
682 val = symbol_no.curr.tri;
683 str = symbol_empty.curr.val;
684
685 /* If symbol has a default value look it up */
686 prop = sym_get_default_prop(sym);
687 if (prop != NULL) {
688 switch (sym->type) {
689 case S_BOOLEAN:
690 case S_TRISTATE:
691 /* The visibility imay limit the value from yes => mod */
692 val = EXPR_AND(expr_calc_value(prop->expr), prop->visible.tri);
693 break;
694 default:
695 /*
696 * The following fails to handle the situation
697 * where a default value is further limited by
698 * the valid range.
699 */
700 ds = prop_get_symbol(prop);
701 if (ds != NULL) {
702 sym_calc_value(ds);
703 str = (const char *)ds->curr.val;
704 }
705 }
706 }
707
708 /* Handle select statements */
709 val = EXPR_OR(val, sym->rev_dep.tri);
710
711 /* transpose mod to yes if modules are not enabled */
712 if (val == mod)
713 if (!sym_is_choice_value(sym) && modules_sym->curr.tri == no)
714 val = yes;
715
716 /* transpose mod to yes if type is bool */
717 if (sym->type == S_BOOLEAN && val == mod)
718 val = yes;
719
720 switch (sym->type) {
721 case S_BOOLEAN:
722 case S_TRISTATE:
723 switch (val) {
724 case no: return "n";
725 case mod: return "m";
726 case yes: return "y";
727 }
728 case S_INT:
729 case S_HEX:
730 return str;
731 case S_STRING:
732 return str;
733 case S_OTHER:
734 case S_UNKNOWN:
735 break;
736 }
737 return "";
738}
739
626const char *sym_get_string_value(struct symbol *sym) 740const char *sym_get_string_value(struct symbol *sym)
627{ 741{
628 tristate val; 742 tristate val;
@@ -765,6 +879,112 @@ struct symbol **sym_re_search(const char *pattern)
765 return sym_arr; 879 return sym_arr;
766} 880}
767 881
882/*
883 * When we check for recursive dependencies we use a stack to save
884 * current state so we can print out relevant info to user.
885 * The entries are located on the call stack so no need to free memory.
886 * Note inser() remove() must always match to properly clear the stack.
887 */
888static struct dep_stack {
889 struct dep_stack *prev, *next;
890 struct symbol *sym;
891 struct property *prop;
892 struct expr *expr;
893} *check_top;
894
895static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym)
896{
897 memset(stack, 0, sizeof(*stack));
898 if (check_top)
899 check_top->next = stack;
900 stack->prev = check_top;
901 stack->sym = sym;
902 check_top = stack;
903}
904
905static void dep_stack_remove(void)
906{
907 check_top = check_top->prev;
908 if (check_top)
909 check_top->next = NULL;
910}
911
912/*
913 * Called when we have detected a recursive dependency.
914 * check_top point to the top of the stact so we use
915 * the ->prev pointer to locate the bottom of the stack.
916 */
917static void sym_check_print_recursive(struct symbol *last_sym)
918{
919 struct dep_stack *stack;
920 struct symbol *sym, *next_sym;
921 struct menu *menu = NULL;
922 struct property *prop;
923 struct dep_stack cv_stack;
924
925 if (sym_is_choice_value(last_sym)) {
926 dep_stack_insert(&cv_stack, last_sym);
927 last_sym = prop_get_symbol(sym_get_choice_prop(last_sym));
928 }
929
930 for (stack = check_top; stack != NULL; stack = stack->prev)
931 if (stack->sym == last_sym)
932 break;
933 if (!stack) {
934 fprintf(stderr, "unexpected recursive dependency error\n");
935 return;
936 }
937
938 for (; stack; stack = stack->next) {
939 sym = stack->sym;
940 next_sym = stack->next ? stack->next->sym : last_sym;
941 prop = stack->prop;
942 if (prop == NULL)
943 prop = stack->sym->prop;
944
945 /* for choice values find the menu entry (used below) */
946 if (sym_is_choice(sym) || sym_is_choice_value(sym)) {
947 for (prop = sym->prop; prop; prop = prop->next) {
948 menu = prop->menu;
949 if (prop->menu)
950 break;
951 }
952 }
953 if (stack->sym == last_sym)
954 fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
955 prop->file->name, prop->lineno);
956 if (stack->expr) {
957 fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
958 prop->file->name, prop->lineno,
959 sym->name ? sym->name : "<choice>",
960 prop_get_type_name(prop->type),
961 next_sym->name ? next_sym->name : "<choice>");
962 } else if (stack->prop) {
963 fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
964 prop->file->name, prop->lineno,
965 sym->name ? sym->name : "<choice>",
966 next_sym->name ? next_sym->name : "<choice>");
967 } else if (sym_is_choice(sym)) {
968 fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
969 menu->file->name, menu->lineno,
970 sym->name ? sym->name : "<choice>",
971 next_sym->name ? next_sym->name : "<choice>");
972 } else if (sym_is_choice_value(sym)) {
973 fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
974 menu->file->name, menu->lineno,
975 sym->name ? sym->name : "<choice>",
976 next_sym->name ? next_sym->name : "<choice>");
977 } else {
978 fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
979 prop->file->name, prop->lineno,
980 sym->name ? sym->name : "<choice>",
981 next_sym->name ? next_sym->name : "<choice>");
982 }
983 }
984
985 if (check_top == &cv_stack)
986 dep_stack_remove();
987}
768 988
769static struct symbol *sym_check_expr_deps(struct expr *e) 989static struct symbol *sym_check_expr_deps(struct expr *e)
770{ 990{
@@ -801,24 +1021,33 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
801{ 1021{
802 struct symbol *sym2; 1022 struct symbol *sym2;
803 struct property *prop; 1023 struct property *prop;
1024 struct dep_stack stack;
1025
1026 dep_stack_insert(&stack, sym);
804 1027
805 sym2 = sym_check_expr_deps(sym->rev_dep.expr); 1028 sym2 = sym_check_expr_deps(sym->rev_dep.expr);
806 if (sym2) 1029 if (sym2)
807 return sym2; 1030 goto out;
808 1031
809 for (prop = sym->prop; prop; prop = prop->next) { 1032 for (prop = sym->prop; prop; prop = prop->next) {
810 if (prop->type == P_CHOICE || prop->type == P_SELECT) 1033 if (prop->type == P_CHOICE || prop->type == P_SELECT)
811 continue; 1034 continue;
1035 stack.prop = prop;
812 sym2 = sym_check_expr_deps(prop->visible.expr); 1036 sym2 = sym_check_expr_deps(prop->visible.expr);
813 if (sym2) 1037 if (sym2)
814 break; 1038 break;
815 if (prop->type != P_DEFAULT || sym_is_choice(sym)) 1039 if (prop->type != P_DEFAULT || sym_is_choice(sym))
816 continue; 1040 continue;
1041 stack.expr = prop->expr;
817 sym2 = sym_check_expr_deps(prop->expr); 1042 sym2 = sym_check_expr_deps(prop->expr);
818 if (sym2) 1043 if (sym2)
819 break; 1044 break;
1045 stack.expr = NULL;
820 } 1046 }
821 1047
1048out:
1049 dep_stack_remove();
1050
822 return sym2; 1051 return sym2;
823} 1052}
824 1053
@@ -827,6 +1056,9 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
827 struct symbol *sym, *sym2; 1056 struct symbol *sym, *sym2;
828 struct property *prop; 1057 struct property *prop;
829 struct expr *e; 1058 struct expr *e;
1059 struct dep_stack stack;
1060
1061 dep_stack_insert(&stack, choice);
830 1062
831 prop = sym_get_choice_prop(choice); 1063 prop = sym_get_choice_prop(choice);
832 expr_list_for_each_sym(prop->expr, e, sym) 1064 expr_list_for_each_sym(prop->expr, e, sym)
@@ -840,10 +1072,8 @@ static struct symbol *sym_check_choice_deps(struct symbol *choice)
840 1072
841 expr_list_for_each_sym(prop->expr, e, sym) { 1073 expr_list_for_each_sym(prop->expr, e, sym) {
842 sym2 = sym_check_sym_deps(sym); 1074 sym2 = sym_check_sym_deps(sym);
843 if (sym2) { 1075 if (sym2)
844 fprintf(stderr, " -> %s", sym->name);
845 break; 1076 break;
846 }
847 } 1077 }
848out: 1078out:
849 expr_list_for_each_sym(prop->expr, e, sym) 1079 expr_list_for_each_sym(prop->expr, e, sym)
@@ -853,6 +1083,8 @@ out:
853 prop_get_symbol(sym_get_choice_prop(sym2)) == choice) 1083 prop_get_symbol(sym_get_choice_prop(sym2)) == choice)
854 sym2 = choice; 1084 sym2 = choice;
855 1085
1086 dep_stack_remove();
1087
856 return sym2; 1088 return sym2;
857} 1089}
858 1090
@@ -862,18 +1094,20 @@ struct symbol *sym_check_deps(struct symbol *sym)
862 struct property *prop; 1094 struct property *prop;
863 1095
864 if (sym->flags & SYMBOL_CHECK) { 1096 if (sym->flags & SYMBOL_CHECK) {
865 fprintf(stderr, "%s:%d:error: found recursive dependency: %s", 1097 sym_check_print_recursive(sym);
866 sym->prop->file->name, sym->prop->lineno,
867 sym->name ? sym->name : "<choice>");
868 return sym; 1098 return sym;
869 } 1099 }
870 if (sym->flags & SYMBOL_CHECKED) 1100 if (sym->flags & SYMBOL_CHECKED)
871 return NULL; 1101 return NULL;
872 1102
873 if (sym_is_choice_value(sym)) { 1103 if (sym_is_choice_value(sym)) {
1104 struct dep_stack stack;
1105
874 /* for choice groups start the check with main choice symbol */ 1106 /* for choice groups start the check with main choice symbol */
1107 dep_stack_insert(&stack, sym);
875 prop = sym_get_choice_prop(sym); 1108 prop = sym_get_choice_prop(sym);
876 sym2 = sym_check_deps(prop_get_symbol(prop)); 1109 sym2 = sym_check_deps(prop_get_symbol(prop));
1110 dep_stack_remove();
877 } else if (sym_is_choice(sym)) { 1111 } else if (sym_is_choice(sym)) {
878 sym2 = sym_check_choice_deps(sym); 1112 sym2 = sym_check_choice_deps(sym);
879 } else { 1113 } else {
@@ -882,14 +1116,8 @@ struct symbol *sym_check_deps(struct symbol *sym)
882 sym->flags &= ~SYMBOL_CHECK; 1116 sym->flags &= ~SYMBOL_CHECK;
883 } 1117 }
884 1118
885 if (sym2) { 1119 if (sym2 && sym2 == sym)
886 fprintf(stderr, " -> %s", sym->name ? sym->name : "<choice>"); 1120 sym2 = NULL;
887 if (sym2 == sym) {
888 fprintf(stderr, "\n");
889 zconfnerrs++;
890 sym2 = NULL;
891 }
892 }
893 1121
894 return sym2; 1122 return sym2;
895} 1123}
@@ -943,6 +1171,8 @@ const char *prop_get_type_name(enum prop_type type)
943 return "select"; 1171 return "select";
944 case P_RANGE: 1172 case P_RANGE:
945 return "range"; 1173 return "range";
1174 case P_SYMBOL:
1175 return "symbol";
946 case P_UNKNOWN: 1176 case P_UNKNOWN:
947 break; 1177 break;
948 } 1178 }
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index fcdfb245a575..cdb6dc1f6458 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -44,12 +44,13 @@ use strict;
44# Note: This only supports 'c'. 44# Note: This only supports 'c'.
45 45
46# usage: 46# usage:
47# kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ] 47# kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ]
48# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile 48# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
49# or 49# or
50# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile 50# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
51# 51#
52# Set output format using one of -docbook -html -text or -man. Default is man. 52# Set output format using one of -docbook -html -text or -man. Default is man.
53# The -list format is for internal use by docproc.
53# 54#
54# -no-doc-sections 55# -no-doc-sections
55# Do not output DOC: sections 56# Do not output DOC: sections
@@ -210,9 +211,16 @@ my %highlights_text = ( $type_constant, "\$1",
210 $type_param, "\$1" ); 211 $type_param, "\$1" );
211my $blankline_text = ""; 212my $blankline_text = "";
212 213
214# list mode
215my %highlights_list = ( $type_constant, "\$1",
216 $type_func, "\$1",
217 $type_struct, "\$1",
218 $type_param, "\$1" );
219my $blankline_list = "";
213 220
214sub usage { 221sub usage {
215 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n"; 222 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n";
223 print " [ -no-doc-sections ]\n";
216 print " [ -function funcname [ -function funcname ...] ]\n"; 224 print " [ -function funcname [ -function funcname ...] ]\n";
217 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 225 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
218 print " c source file(s) > outputfile\n"; 226 print " c source file(s) > outputfile\n";
@@ -318,6 +326,10 @@ while ($ARGV[0] =~ m/^-(.*)/) {
318 $output_mode = "xml"; 326 $output_mode = "xml";
319 %highlights = %highlights_xml; 327 %highlights = %highlights_xml;
320 $blankline = $blankline_xml; 328 $blankline = $blankline_xml;
329 } elsif ($cmd eq "-list") {
330 $output_mode = "list";
331 %highlights = %highlights_list;
332 $blankline = $blankline_list;
321 } elsif ($cmd eq "-gnome") { 333 } elsif ($cmd eq "-gnome") {
322 $output_mode = "gnome"; 334 $output_mode = "gnome";
323 %highlights = %highlights_gnome; 335 %highlights = %highlights_gnome;
@@ -1361,6 +1373,42 @@ sub output_blockhead_text(%) {
1361 } 1373 }
1362} 1374}
1363 1375
1376## list mode output functions
1377
1378sub output_function_list(%) {
1379 my %args = %{$_[0]};
1380
1381 print $args{'function'} . "\n";
1382}
1383
1384# output enum in list
1385sub output_enum_list(%) {
1386 my %args = %{$_[0]};
1387 print $args{'enum'} . "\n";
1388}
1389
1390# output typedef in list
1391sub output_typedef_list(%) {
1392 my %args = %{$_[0]};
1393 print $args{'typedef'} . "\n";
1394}
1395
1396# output struct as list
1397sub output_struct_list(%) {
1398 my %args = %{$_[0]};
1399
1400 print $args{'struct'} . "\n";
1401}
1402
1403sub output_blockhead_list(%) {
1404 my %args = %{$_[0]};
1405 my ($parameter, $section);
1406
1407 foreach $section (@{$args{'sectionlist'}}) {
1408 print "DOC: $section\n";
1409 }
1410}
1411
1364## 1412##
1365# generic output function for all types (function, struct/union, typedef, enum); 1413# generic output function for all types (function, struct/union, typedef, enum);
1366# calls the generated, variable output_ function name based on 1414# calls the generated, variable output_ function name based on
@@ -1454,6 +1502,8 @@ sub dump_enum($$) {
1454 my $file = shift; 1502 my $file = shift;
1455 1503
1456 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1504 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1505 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1506
1457 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 1507 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1458 $declaration_name = $1; 1508 $declaration_name = $1;
1459 my $members = $2; 1509 my $members = $2;
@@ -1677,7 +1727,7 @@ sub check_sections($$$$$$) {
1677 foreach $px (0 .. $#prms) { 1727 foreach $px (0 .. $#prms) {
1678 $prm_clean = $prms[$px]; 1728 $prm_clean = $prms[$px];
1679 $prm_clean =~ s/\[.*\]//; 1729 $prm_clean =~ s/\[.*\]//;
1680 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//; 1730 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1681 # ignore array size in a parameter string; 1731 # ignore array size in a parameter string;
1682 # however, the original param string may contain 1732 # however, the original param string may contain
1683 # spaces, e.g.: addr[6 + 2] 1733 # spaces, e.g.: addr[6 + 2]
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
index 67d59c7a18dc..5325423ceab4 100644
--- a/scripts/mkmakefile
+++ b/scripts/mkmakefile
@@ -44,7 +44,9 @@ all:
44 44
45Makefile:; 45Makefile:;
46 46
47\$(all) %/: all 47\$(all): all
48 @: 48 @:
49 49
50%/: all
51 @:
50EOF 52EOF
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 859bee4972e9..33122ca04e7c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -14,6 +14,7 @@
14#define _GNU_SOURCE 14#define _GNU_SOURCE
15#include <stdio.h> 15#include <stdio.h>
16#include <ctype.h> 16#include <ctype.h>
17#include <string.h>
17#include "modpost.h" 18#include "modpost.h"
18#include "../../include/generated/autoconf.h" 19#include "../../include/generated/autoconf.h"
19#include "../../include/linux/license.h" 20#include "../../include/linux/license.h"
@@ -789,6 +790,7 @@ static const char *section_white_list[] =
789{ 790{
790 ".comment*", 791 ".comment*",
791 ".debug*", 792 ".debug*",
793 ".GCC-command-line", /* mn10300 */
792 ".mdebug*", /* alpha, score, mips etc. */ 794 ".mdebug*", /* alpha, score, mips etc. */
793 ".pdr", /* alpha, score, mips etc. */ 795 ".pdr", /* alpha, score, mips etc. */
794 ".stab*", 796 ".stab*",
@@ -1033,6 +1035,13 @@ static const struct sectioncheck *section_mismatch(
1033 * fromsec = .data* 1035 * fromsec = .data*
1034 * atsym =__param* 1036 * atsym =__param*
1035 * 1037 *
1038 * Pattern 1a:
1039 * module_param_call() ops can refer to __init set function if permissions=0
1040 * The pattern is identified by:
1041 * tosec = .init.text
1042 * fromsec = .data*
1043 * atsym = __param_ops_*
1044 *
1036 * Pattern 2: 1045 * Pattern 2:
1037 * Many drivers utilise a *driver container with references to 1046 * Many drivers utilise a *driver container with references to
1038 * add, remove, probe functions etc. 1047 * add, remove, probe functions etc.
@@ -1067,6 +1076,12 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
1067 (strncmp(fromsym, "__param", strlen("__param")) == 0)) 1076 (strncmp(fromsym, "__param", strlen("__param")) == 0))
1068 return 0; 1077 return 0;
1069 1078
1079 /* Check for pattern 1a */
1080 if (strcmp(tosec, ".init.text") == 0 &&
1081 match(fromsec, data_sections) &&
1082 (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0))
1083 return 0;
1084
1070 /* Check for pattern 2 */ 1085 /* Check for pattern 2 */
1071 if (match(tosec, init_exit_sections) && 1086 if (match(tosec, init_exit_sections) &&
1072 match(fromsec, data_sections) && 1087 match(fromsec, data_sections) &&
@@ -1220,7 +1235,7 @@ static char *sec2annotation(const char *s)
1220 strcat(p, " "); 1235 strcat(p, " ");
1221 return r; 1236 return r;
1222 } else { 1237 } else {
1223 return ""; 1238 return strdup("");
1224 } 1239 }
1225} 1240}
1226 1241
@@ -1248,6 +1263,8 @@ static void report_sec_mismatch(const char *modname,
1248{ 1263{
1249 const char *from, *from_p; 1264 const char *from, *from_p;
1250 const char *to, *to_p; 1265 const char *to, *to_p;
1266 char *prl_from;
1267 char *prl_to;
1251 1268
1252 switch (from_is_func) { 1269 switch (from_is_func) {
1253 case 0: from = "variable"; from_p = ""; break; 1270 case 0: from = "variable"; from_p = ""; break;
@@ -1271,16 +1288,21 @@ static void report_sec_mismatch(const char *modname,
1271 1288
1272 switch (mismatch->mismatch) { 1289 switch (mismatch->mismatch) {
1273 case TEXT_TO_ANY_INIT: 1290 case TEXT_TO_ANY_INIT:
1291 prl_from = sec2annotation(fromsec);
1292 prl_to = sec2annotation(tosec);
1274 fprintf(stderr, 1293 fprintf(stderr,
1275 "The function %s%s() references\n" 1294 "The function %s%s() references\n"
1276 "the %s %s%s%s.\n" 1295 "the %s %s%s%s.\n"
1277 "This is often because %s lacks a %s\n" 1296 "This is often because %s lacks a %s\n"
1278 "annotation or the annotation of %s is wrong.\n", 1297 "annotation or the annotation of %s is wrong.\n",
1279 sec2annotation(fromsec), fromsym, 1298 prl_from, fromsym,
1280 to, sec2annotation(tosec), tosym, to_p, 1299 to, prl_to, tosym, to_p,
1281 fromsym, sec2annotation(tosec), tosym); 1300 fromsym, prl_to, tosym);
1301 free(prl_from);
1302 free(prl_to);
1282 break; 1303 break;
1283 case DATA_TO_ANY_INIT: { 1304 case DATA_TO_ANY_INIT: {
1305 prl_to = sec2annotation(tosec);
1284 const char *const *s = mismatch->symbol_white_list; 1306 const char *const *s = mismatch->symbol_white_list;
1285 fprintf(stderr, 1307 fprintf(stderr,
1286 "The variable %s references\n" 1308 "The variable %s references\n"
@@ -1288,20 +1310,24 @@ static void report_sec_mismatch(const char *modname,
1288 "If the reference is valid then annotate the\n" 1310 "If the reference is valid then annotate the\n"
1289 "variable with __init* or __refdata (see linux/init.h) " 1311 "variable with __init* or __refdata (see linux/init.h) "
1290 "or name the variable:\n", 1312 "or name the variable:\n",
1291 fromsym, to, sec2annotation(tosec), tosym, to_p); 1313 fromsym, to, prl_to, tosym, to_p);
1292 while (*s) 1314 while (*s)
1293 fprintf(stderr, "%s, ", *s++); 1315 fprintf(stderr, "%s, ", *s++);
1294 fprintf(stderr, "\n"); 1316 fprintf(stderr, "\n");
1317 free(prl_to);
1295 break; 1318 break;
1296 } 1319 }
1297 case TEXT_TO_ANY_EXIT: 1320 case TEXT_TO_ANY_EXIT:
1321 prl_to = sec2annotation(tosec);
1298 fprintf(stderr, 1322 fprintf(stderr,
1299 "The function %s() references a %s in an exit section.\n" 1323 "The function %s() references a %s in an exit section.\n"
1300 "Often the %s %s%s has valid usage outside the exit section\n" 1324 "Often the %s %s%s has valid usage outside the exit section\n"
1301 "and the fix is to remove the %sannotation of %s.\n", 1325 "and the fix is to remove the %sannotation of %s.\n",
1302 fromsym, to, to, tosym, to_p, sec2annotation(tosec), tosym); 1326 fromsym, to, to, tosym, to_p, prl_to, tosym);
1327 free(prl_to);
1303 break; 1328 break;
1304 case DATA_TO_ANY_EXIT: { 1329 case DATA_TO_ANY_EXIT: {
1330 prl_to = sec2annotation(tosec);
1305 const char *const *s = mismatch->symbol_white_list; 1331 const char *const *s = mismatch->symbol_white_list;
1306 fprintf(stderr, 1332 fprintf(stderr,
1307 "The variable %s references\n" 1333 "The variable %s references\n"
@@ -1309,24 +1335,31 @@ static void report_sec_mismatch(const char *modname,
1309 "If the reference is valid then annotate the\n" 1335 "If the reference is valid then annotate the\n"
1310 "variable with __exit* (see linux/init.h) or " 1336 "variable with __exit* (see linux/init.h) or "
1311 "name the variable:\n", 1337 "name the variable:\n",
1312 fromsym, to, sec2annotation(tosec), tosym, to_p); 1338 fromsym, to, prl_to, tosym, to_p);
1313 while (*s) 1339 while (*s)
1314 fprintf(stderr, "%s, ", *s++); 1340 fprintf(stderr, "%s, ", *s++);
1315 fprintf(stderr, "\n"); 1341 fprintf(stderr, "\n");
1342 free(prl_to);
1316 break; 1343 break;
1317 } 1344 }
1318 case XXXINIT_TO_SOME_INIT: 1345 case XXXINIT_TO_SOME_INIT:
1319 case XXXEXIT_TO_SOME_EXIT: 1346 case XXXEXIT_TO_SOME_EXIT:
1347 prl_from = sec2annotation(fromsec);
1348 prl_to = sec2annotation(tosec);
1320 fprintf(stderr, 1349 fprintf(stderr,
1321 "The %s %s%s%s references\n" 1350 "The %s %s%s%s references\n"
1322 "a %s %s%s%s.\n" 1351 "a %s %s%s%s.\n"
1323 "If %s is only used by %s then\n" 1352 "If %s is only used by %s then\n"
1324 "annotate %s with a matching annotation.\n", 1353 "annotate %s with a matching annotation.\n",
1325 from, sec2annotation(fromsec), fromsym, from_p, 1354 from, prl_from, fromsym, from_p,
1326 to, sec2annotation(tosec), tosym, to_p, 1355 to, prl_to, tosym, to_p,
1327 tosym, fromsym, tosym); 1356 tosym, fromsym, tosym);
1357 free(prl_from);
1358 free(prl_to);
1328 break; 1359 break;
1329 case ANY_INIT_TO_ANY_EXIT: 1360 case ANY_INIT_TO_ANY_EXIT:
1361 prl_from = sec2annotation(fromsec);
1362 prl_to = sec2annotation(tosec);
1330 fprintf(stderr, 1363 fprintf(stderr,
1331 "The %s %s%s%s references\n" 1364 "The %s %s%s%s references\n"
1332 "a %s %s%s%s.\n" 1365 "a %s %s%s%s.\n"
@@ -1335,11 +1368,15 @@ static void report_sec_mismatch(const char *modname,
1335 "uses functionality in the exit path.\n" 1368 "uses functionality in the exit path.\n"
1336 "The fix is often to remove the %sannotation of\n" 1369 "The fix is often to remove the %sannotation of\n"
1337 "%s%s so it may be used outside an exit section.\n", 1370 "%s%s so it may be used outside an exit section.\n",
1338 from, sec2annotation(fromsec), fromsym, from_p, 1371 from, prl_from, fromsym, from_p,
1339 to, sec2annotation(tosec), tosym, to_p, 1372 to, prl_to, tosym, to_p,
1340 sec2annotation(tosec), tosym, to_p); 1373 prl_to, tosym, to_p);
1374 free(prl_from);
1375 free(prl_to);
1341 break; 1376 break;
1342 case ANY_EXIT_TO_ANY_INIT: 1377 case ANY_EXIT_TO_ANY_INIT:
1378 prl_from = sec2annotation(fromsec);
1379 prl_to = sec2annotation(tosec);
1343 fprintf(stderr, 1380 fprintf(stderr,
1344 "The %s %s%s%s references\n" 1381 "The %s %s%s%s references\n"
1345 "a %s %s%s%s.\n" 1382 "a %s %s%s%s.\n"
@@ -1348,16 +1385,20 @@ static void report_sec_mismatch(const char *modname,
1348 "uses functionality in the init path.\n" 1385 "uses functionality in the init path.\n"
1349 "The fix is often to remove the %sannotation of\n" 1386 "The fix is often to remove the %sannotation of\n"
1350 "%s%s so it may be used outside an init section.\n", 1387 "%s%s so it may be used outside an init section.\n",
1351 from, sec2annotation(fromsec), fromsym, from_p, 1388 from, prl_from, fromsym, from_p,
1352 to, sec2annotation(tosec), tosym, to_p, 1389 to, prl_to, tosym, to_p,
1353 sec2annotation(tosec), tosym, to_p); 1390 prl_to, tosym, to_p);
1391 free(prl_from);
1392 free(prl_to);
1354 break; 1393 break;
1355 case EXPORT_TO_INIT_EXIT: 1394 case EXPORT_TO_INIT_EXIT:
1395 prl_to = sec2annotation(tosec);
1356 fprintf(stderr, 1396 fprintf(stderr,
1357 "The symbol %s is exported and annotated %s\n" 1397 "The symbol %s is exported and annotated %s\n"
1358 "Fix this by removing the %sannotation of %s " 1398 "Fix this by removing the %sannotation of %s "
1359 "or drop the export.\n", 1399 "or drop the export.\n",
1360 tosym, sec2annotation(tosec), sec2annotation(tosec), tosym); 1400 tosym, prl_to, prl_to, tosym);
1401 free(prl_to);
1361 break; 1402 break;
1362 } 1403 }
1363 fprintf(stderr, "\n"); 1404 fprintf(stderr, "\n");
diff --git a/scripts/package/Makefile b/scripts/package/Makefile
index d2c29b63adda..d0b931b994fc 100644
--- a/scripts/package/Makefile
+++ b/scripts/package/Makefile
@@ -111,13 +111,38 @@ tar%pkg: FORCE
111clean-dirs += $(objtree)/tar-install/ 111clean-dirs += $(objtree)/tar-install/
112 112
113 113
114# perf-pkg - generate a source tarball with perf source
115# ---------------------------------------------------------------------------
116
117perf-tar=perf-$(KERNELVERSION)
118
119quiet_cmd_perf_tar = TAR
120 cmd_perf_tar = \
121git archive --prefix=$(perf-tar)/ HEAD^{tree} \
122 $$(cat $(srctree)/tools/perf/MANIFEST) -o $(perf-tar).tar; \
123mkdir -p $(perf-tar); \
124git rev-parse HEAD > $(perf-tar)/HEAD; \
125tar rf $(perf-tar).tar $(perf-tar)/HEAD; \
126rm -r $(perf-tar); \
127$(if $(findstring tar-src,$@),, \
128$(if $(findstring bz2,$@),bzip2, \
129$(if $(findstring gz,$@),gzip, \
130$(error unknown target $@))) \
131 -f -9 $(perf-tar).tar)
132
133perf-%pkg: FORCE
134 $(call cmd,perf_tar)
135
114# Help text displayed when executing 'make help' 136# Help text displayed when executing 'make help'
115# --------------------------------------------------------------------------- 137# ---------------------------------------------------------------------------
116help: FORCE 138help: FORCE
117 @echo ' rpm-pkg - Build both source and binary RPM kernel packages' 139 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
118 @echo ' binrpm-pkg - Build only the binary kernel package' 140 @echo ' binrpm-pkg - Build only the binary kernel package'
119 @echo ' deb-pkg - Build the kernel as an deb package' 141 @echo ' deb-pkg - Build the kernel as an deb package'
120 @echo ' tar-pkg - Build the kernel as an uncompressed tarball' 142 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
121 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' 143 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
122 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 144 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
145 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
146 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
147 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
123 148
diff --git a/scripts/package/builddeb b/scripts/package/builddeb
index 07f2fbde2abf..5f1e2fc7f171 100644
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -148,10 +148,11 @@ EOF
148# Generate a control file 148# Generate a control file
149cat <<EOF > debian/control 149cat <<EOF > debian/control
150Source: linux-upstream 150Source: linux-upstream
151Section: admin 151Section: kernel
152Priority: optional 152Priority: optional
153Maintainer: $maintainer 153Maintainer: $maintainer
154Standards-Version: 3.8.1 154Standards-Version: 3.8.4
155Homepage: http://www.kernel.org/
155EOF 156EOF
156 157
157if [ "$ARCH" = "um" ]; then 158if [ "$ARCH" = "um" ]; then
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
new file mode 100644
index 000000000000..26e1271259ba
--- /dev/null
+++ b/scripts/recordmcount.c
@@ -0,0 +1,363 @@
1/*
2 * recordmcount.c: construct a table of the locations of calls to 'mcount'
3 * so that ftrace can find them quickly.
4 * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved.
5 * Licensed under the GNU General Public License, version 2 (GPLv2).
6 *
7 * Restructured to fit Linux format, as well as other updates:
8 * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
9 */
10
11/*
12 * Strategy: alter the .o file in-place.
13 *
14 * Append a new STRTAB that has the new section names, followed by a new array
15 * ElfXX_Shdr[] that has the new section headers, followed by the section
16 * contents for __mcount_loc and its relocations. The old shstrtab strings,
17 * and the old ElfXX_Shdr[] array, remain as "garbage" (commonly, a couple
18 * kilobytes.) Subsequent processing by /bin/ld (or the kernel module loader)
19 * will ignore the garbage regions, because they are not designated by the
20 * new .e_shoff nor the new ElfXX_Shdr[]. [In order to remove the garbage,
21 * then use "ld -r" to create a new file that omits the garbage.]
22 */
23
24#include <sys/types.h>
25#include <sys/mman.h>
26#include <sys/stat.h>
27#include <elf.h>
28#include <fcntl.h>
29#include <setjmp.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <unistd.h>
34
35static int fd_map; /* File descriptor for file being modified. */
36static int mmap_failed; /* Boolean flag. */
37static void *ehdr_curr; /* current ElfXX_Ehdr * for resource cleanup */
38static char gpfx; /* prefix for global symbol name (sometimes '_') */
39static struct stat sb; /* Remember .st_size, etc. */
40static jmp_buf jmpenv; /* setjmp/longjmp per-file error escape */
41
42/* setjmp() return values */
43enum {
44 SJ_SETJMP = 0, /* hardwired first return */
45 SJ_FAIL,
46 SJ_SUCCEED
47};
48
49/* Per-file resource cleanup when multiple files. */
50static void
51cleanup(void)
52{
53 if (!mmap_failed)
54 munmap(ehdr_curr, sb.st_size);
55 else
56 free(ehdr_curr);
57 close(fd_map);
58}
59
60static void __attribute__((noreturn))
61fail_file(void)
62{
63 cleanup();
64 longjmp(jmpenv, SJ_FAIL);
65}
66
67static void __attribute__((noreturn))
68succeed_file(void)
69{
70 cleanup();
71 longjmp(jmpenv, SJ_SUCCEED);
72}
73
74/* ulseek, uread, ...: Check return value for errors. */
75
76static off_t
77ulseek(int const fd, off_t const offset, int const whence)
78{
79 off_t const w = lseek(fd, offset, whence);
80 if ((off_t)-1 == w) {
81 perror("lseek");
82 fail_file();
83 }
84 return w;
85}
86
87static size_t
88uread(int const fd, void *const buf, size_t const count)
89{
90 size_t const n = read(fd, buf, count);
91 if (n != count) {
92 perror("read");
93 fail_file();
94 }
95 return n;
96}
97
98static size_t
99uwrite(int const fd, void const *const buf, size_t const count)
100{
101 size_t const n = write(fd, buf, count);
102 if (n != count) {
103 perror("write");
104 fail_file();
105 }
106 return n;
107}
108
109static void *
110umalloc(size_t size)
111{
112 void *const addr = malloc(size);
113 if (0 == addr) {
114 fprintf(stderr, "malloc failed: %zu bytes\n", size);
115 fail_file();
116 }
117 return addr;
118}
119
120/*
121 * Get the whole file as a programming convenience in order to avoid
122 * malloc+lseek+read+free of many pieces. If successful, then mmap
123 * avoids copying unused pieces; else just read the whole file.
124 * Open for both read and write; new info will be appended to the file.
125 * Use MAP_PRIVATE so that a few changes to the in-memory ElfXX_Ehdr
126 * do not propagate to the file until an explicit overwrite at the last.
127 * This preserves most aspects of consistency (all except .st_size)
128 * for simultaneous readers of the file while we are appending to it.
129 * However, multiple writers still are bad. We choose not to use
130 * locking because it is expensive and the use case of kernel build
131 * makes multiple writers unlikely.
132 */
133static void *mmap_file(char const *fname)
134{
135 void *addr;
136
137 fd_map = open(fname, O_RDWR);
138 if (0 > fd_map || 0 > fstat(fd_map, &sb)) {
139 perror(fname);
140 fail_file();
141 }
142 if (!S_ISREG(sb.st_mode)) {
143 fprintf(stderr, "not a regular file: %s\n", fname);
144 fail_file();
145 }
146 addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,
147 fd_map, 0);
148 mmap_failed = 0;
149 if (MAP_FAILED == addr) {
150 mmap_failed = 1;
151 addr = umalloc(sb.st_size);
152 uread(fd_map, addr, sb.st_size);
153 }
154 return addr;
155}
156
157/* w8rev, w8nat, ...: Handle endianness. */
158
159static uint64_t w8rev(uint64_t const x)
160{
161 return ((0xff & (x >> (0 * 8))) << (7 * 8))
162 | ((0xff & (x >> (1 * 8))) << (6 * 8))
163 | ((0xff & (x >> (2 * 8))) << (5 * 8))
164 | ((0xff & (x >> (3 * 8))) << (4 * 8))
165 | ((0xff & (x >> (4 * 8))) << (3 * 8))
166 | ((0xff & (x >> (5 * 8))) << (2 * 8))
167 | ((0xff & (x >> (6 * 8))) << (1 * 8))
168 | ((0xff & (x >> (7 * 8))) << (0 * 8));
169}
170
171static uint32_t w4rev(uint32_t const x)
172{
173 return ((0xff & (x >> (0 * 8))) << (3 * 8))
174 | ((0xff & (x >> (1 * 8))) << (2 * 8))
175 | ((0xff & (x >> (2 * 8))) << (1 * 8))
176 | ((0xff & (x >> (3 * 8))) << (0 * 8));
177}
178
179static uint32_t w2rev(uint16_t const x)
180{
181 return ((0xff & (x >> (0 * 8))) << (1 * 8))
182 | ((0xff & (x >> (1 * 8))) << (0 * 8));
183}
184
185static uint64_t w8nat(uint64_t const x)
186{
187 return x;
188}
189
190static uint32_t w4nat(uint32_t const x)
191{
192 return x;
193}
194
195static uint32_t w2nat(uint16_t const x)
196{
197 return x;
198}
199
200static uint64_t (*w8)(uint64_t);
201static uint32_t (*w)(uint32_t);
202static uint32_t (*w2)(uint16_t);
203
204/* Names of the sections that could contain calls to mcount. */
205static int
206is_mcounted_section_name(char const *const txtname)
207{
208 return 0 == strcmp(".text", txtname) ||
209 0 == strcmp(".sched.text", txtname) ||
210 0 == strcmp(".spinlock.text", txtname) ||
211 0 == strcmp(".irqentry.text", txtname) ||
212 0 == strcmp(".text.unlikely", txtname);
213}
214
215/* 32 bit and 64 bit are very similar */
216#include "recordmcount.h"
217#define RECORD_MCOUNT_64
218#include "recordmcount.h"
219
220static void
221do_file(char const *const fname)
222{
223 Elf32_Ehdr *const ehdr = mmap_file(fname);
224 unsigned int reltype = 0;
225
226 ehdr_curr = ehdr;
227 w = w4nat;
228 w2 = w2nat;
229 w8 = w8nat;
230 switch (ehdr->e_ident[EI_DATA]) {
231 static unsigned int const endian = 1;
232 default: {
233 fprintf(stderr, "unrecognized ELF data encoding %d: %s\n",
234 ehdr->e_ident[EI_DATA], fname);
235 fail_file();
236 } break;
237 case ELFDATA2LSB: {
238 if (1 != *(unsigned char const *)&endian) {
239 /* main() is big endian, file.o is little endian. */
240 w = w4rev;
241 w2 = w2rev;
242 w8 = w8rev;
243 }
244 } break;
245 case ELFDATA2MSB: {
246 if (0 != *(unsigned char const *)&endian) {
247 /* main() is little endian, file.o is big endian. */
248 w = w4rev;
249 w2 = w2rev;
250 w8 = w8rev;
251 }
252 } break;
253 } /* end switch */
254 if (0 != memcmp(ELFMAG, ehdr->e_ident, SELFMAG)
255 || ET_REL != w2(ehdr->e_type)
256 || EV_CURRENT != ehdr->e_ident[EI_VERSION]) {
257 fprintf(stderr, "unrecognized ET_REL file %s\n", fname);
258 fail_file();
259 }
260
261 gpfx = 0;
262 switch (w2(ehdr->e_machine)) {
263 default: {
264 fprintf(stderr, "unrecognized e_machine %d %s\n",
265 w2(ehdr->e_machine), fname);
266 fail_file();
267 } break;
268 case EM_386: reltype = R_386_32; break;
269 case EM_ARM: reltype = R_ARM_ABS32; break;
270 case EM_IA_64: reltype = R_IA64_IMM64; gpfx = '_'; break;
271 case EM_PPC: reltype = R_PPC_ADDR32; gpfx = '_'; break;
272 case EM_PPC64: reltype = R_PPC64_ADDR64; gpfx = '_'; break;
273 case EM_S390: /* reltype: e_class */ gpfx = '_'; break;
274 case EM_SH: reltype = R_SH_DIR32; break;
275 case EM_SPARCV9: reltype = R_SPARC_64; gpfx = '_'; break;
276 case EM_X86_64: reltype = R_X86_64_64; break;
277 } /* end switch */
278
279 switch (ehdr->e_ident[EI_CLASS]) {
280 default: {
281 fprintf(stderr, "unrecognized ELF class %d %s\n",
282 ehdr->e_ident[EI_CLASS], fname);
283 fail_file();
284 } break;
285 case ELFCLASS32: {
286 if (sizeof(Elf32_Ehdr) != w2(ehdr->e_ehsize)
287 || sizeof(Elf32_Shdr) != w2(ehdr->e_shentsize)) {
288 fprintf(stderr,
289 "unrecognized ET_REL file: %s\n", fname);
290 fail_file();
291 }
292 if (EM_S390 == w2(ehdr->e_machine))
293 reltype = R_390_32;
294 do32(ehdr, fname, reltype);
295 } break;
296 case ELFCLASS64: {
297 Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr;
298 if (sizeof(Elf64_Ehdr) != w2(ghdr->e_ehsize)
299 || sizeof(Elf64_Shdr) != w2(ghdr->e_shentsize)) {
300 fprintf(stderr,
301 "unrecognized ET_REL file: %s\n", fname);
302 fail_file();
303 }
304 if (EM_S390 == w2(ghdr->e_machine))
305 reltype = R_390_64;
306 do64(ghdr, fname, reltype);
307 } break;
308 } /* end switch */
309
310 cleanup();
311}
312
313int
314main(int argc, char const *argv[])
315{
316 const char ftrace[] = "kernel/trace/ftrace.o";
317 int ftrace_size = sizeof(ftrace) - 1;
318 int n_error = 0; /* gcc-4.3.0 false positive complaint */
319
320 if (argc <= 1) {
321 fprintf(stderr, "usage: recordmcount file.o...\n");
322 return 0;
323 }
324
325 /* Process each file in turn, allowing deep failure. */
326 for (--argc, ++argv; 0 < argc; --argc, ++argv) {
327 int const sjval = setjmp(jmpenv);
328 int len;
329
330 /*
331 * The file kernel/trace/ftrace.o references the mcount
332 * function but does not call it. Since ftrace.o should
333 * not be traced anyway, we just skip it.
334 */
335 len = strlen(argv[0]);
336 if (len >= ftrace_size &&
337 strcmp(argv[0] + (len - ftrace_size), ftrace) == 0)
338 continue;
339
340 switch (sjval) {
341 default: {
342 fprintf(stderr, "internal error: %s\n", argv[0]);
343 exit(1);
344 } break;
345 case SJ_SETJMP: { /* normal sequence */
346 /* Avoid problems if early cleanup() */
347 fd_map = -1;
348 ehdr_curr = NULL;
349 mmap_failed = 1;
350 do_file(argv[0]);
351 } break;
352 case SJ_FAIL: { /* error in do_file or below */
353 ++n_error;
354 } break;
355 case SJ_SUCCEED: { /* premature success */
356 /* do nothing */
357 } break;
358 } /* end switch */
359 }
360 return !!n_error;
361}
362
363
diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
new file mode 100644
index 000000000000..7f39d0943d2d
--- /dev/null
+++ b/scripts/recordmcount.h
@@ -0,0 +1,366 @@
1/*
2 * recordmcount.h
3 *
4 * This code was taken out of recordmcount.c written by
5 * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved.
6 *
7 * The original code had the same algorithms for both 32bit
8 * and 64bit ELF files, but the code was duplicated to support
9 * the difference in structures that were used. This
10 * file creates a macro of everything that is different between
11 * the 64 and 32 bit code, such that by including this header
12 * twice we can create both sets of functions by including this
13 * header once with RECORD_MCOUNT_64 undefined, and again with
14 * it defined.
15 *
16 * This conversion to macros was done by:
17 * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
18 *
19 * Licensed under the GNU General Public License, version 2 (GPLv2).
20 */
21#undef append_func
22#undef sift_rel_mcount
23#undef find_secsym_ndx
24#undef __has_rel_mcount
25#undef has_rel_mcount
26#undef tot_relsize
27#undef do_func
28#undef Elf_Ehdr
29#undef Elf_Shdr
30#undef Elf_Rel
31#undef Elf_Rela
32#undef Elf_Sym
33#undef ELF_R_SYM
34#undef ELF_R_INFO
35#undef ELF_ST_BIND
36#undef uint_t
37#undef _w
38#undef _align
39#undef _size
40
41#ifdef RECORD_MCOUNT_64
42# define append_func append64
43# define sift_rel_mcount sift64_rel_mcount
44# define find_secsym_ndx find64_secsym_ndx
45# define __has_rel_mcount __has64_rel_mcount
46# define has_rel_mcount has64_rel_mcount
47# define tot_relsize tot64_relsize
48# define do_func do64
49# define Elf_Ehdr Elf64_Ehdr
50# define Elf_Shdr Elf64_Shdr
51# define Elf_Rel Elf64_Rel
52# define Elf_Rela Elf64_Rela
53# define Elf_Sym Elf64_Sym
54# define ELF_R_SYM ELF64_R_SYM
55# define ELF_R_INFO ELF64_R_INFO
56# define ELF_ST_BIND ELF64_ST_BIND
57# define uint_t uint64_t
58# define _w w8
59# define _align 7u
60# define _size 8
61#else
62# define append_func append32
63# define sift_rel_mcount sift32_rel_mcount
64# define find_secsym_ndx find32_secsym_ndx
65# define __has_rel_mcount __has32_rel_mcount
66# define has_rel_mcount has32_rel_mcount
67# define tot_relsize tot32_relsize
68# define do_func do32
69# define Elf_Ehdr Elf32_Ehdr
70# define Elf_Shdr Elf32_Shdr
71# define Elf_Rel Elf32_Rel
72# define Elf_Rela Elf32_Rela
73# define Elf_Sym Elf32_Sym
74# define ELF_R_SYM ELF32_R_SYM
75# define ELF_R_INFO ELF32_R_INFO
76# define ELF_ST_BIND ELF32_ST_BIND
77# define uint_t uint32_t
78# define _w w
79# define _align 3u
80# define _size 4
81#endif
82
83/* Append the new shstrtab, Elf_Shdr[], __mcount_loc and its relocations. */
84static void append_func(Elf_Ehdr *const ehdr,
85 Elf_Shdr *const shstr,
86 uint_t const *const mloc0,
87 uint_t const *const mlocp,
88 Elf_Rel const *const mrel0,
89 Elf_Rel const *const mrelp,
90 unsigned int const rel_entsize,
91 unsigned int const symsec_sh_link)
92{
93 /* Begin constructing output file */
94 Elf_Shdr mcsec;
95 char const *mc_name = (sizeof(Elf_Rela) == rel_entsize)
96 ? ".rela__mcount_loc"
97 : ".rel__mcount_loc";
98 unsigned const old_shnum = w2(ehdr->e_shnum);
99 uint_t const old_shoff = _w(ehdr->e_shoff);
100 uint_t const old_shstr_sh_size = _w(shstr->sh_size);
101 uint_t const old_shstr_sh_offset = _w(shstr->sh_offset);
102 uint_t t = 1 + strlen(mc_name) + _w(shstr->sh_size);
103 uint_t new_e_shoff;
104
105 shstr->sh_size = _w(t);
106 shstr->sh_offset = _w(sb.st_size);
107 t += sb.st_size;
108 t += (_align & -t); /* word-byte align */
109 new_e_shoff = t;
110
111 /* body for new shstrtab */
112 ulseek(fd_map, sb.st_size, SEEK_SET);
113 uwrite(fd_map, old_shstr_sh_offset + (void *)ehdr, old_shstr_sh_size);
114 uwrite(fd_map, mc_name, 1 + strlen(mc_name));
115
116 /* old(modified) Elf_Shdr table, word-byte aligned */
117 ulseek(fd_map, t, SEEK_SET);
118 t += sizeof(Elf_Shdr) * old_shnum;
119 uwrite(fd_map, old_shoff + (void *)ehdr,
120 sizeof(Elf_Shdr) * old_shnum);
121
122 /* new sections __mcount_loc and .rel__mcount_loc */
123 t += 2*sizeof(mcsec);
124 mcsec.sh_name = w((sizeof(Elf_Rela) == rel_entsize) + strlen(".rel")
125 + old_shstr_sh_size);
126 mcsec.sh_type = w(SHT_PROGBITS);
127 mcsec.sh_flags = _w(SHF_ALLOC);
128 mcsec.sh_addr = 0;
129 mcsec.sh_offset = _w(t);
130 mcsec.sh_size = _w((void *)mlocp - (void *)mloc0);
131 mcsec.sh_link = 0;
132 mcsec.sh_info = 0;
133 mcsec.sh_addralign = _w(_size);
134 mcsec.sh_entsize = _w(_size);
135 uwrite(fd_map, &mcsec, sizeof(mcsec));
136
137 mcsec.sh_name = w(old_shstr_sh_size);
138 mcsec.sh_type = (sizeof(Elf_Rela) == rel_entsize)
139 ? w(SHT_RELA)
140 : w(SHT_REL);
141 mcsec.sh_flags = 0;
142 mcsec.sh_addr = 0;
143 mcsec.sh_offset = _w((void *)mlocp - (void *)mloc0 + t);
144 mcsec.sh_size = _w((void *)mrelp - (void *)mrel0);
145 mcsec.sh_link = w(symsec_sh_link);
146 mcsec.sh_info = w(old_shnum);
147 mcsec.sh_addralign = _w(_size);
148 mcsec.sh_entsize = _w(rel_entsize);
149 uwrite(fd_map, &mcsec, sizeof(mcsec));
150
151 uwrite(fd_map, mloc0, (void *)mlocp - (void *)mloc0);
152 uwrite(fd_map, mrel0, (void *)mrelp - (void *)mrel0);
153
154 ehdr->e_shoff = _w(new_e_shoff);
155 ehdr->e_shnum = w2(2 + w2(ehdr->e_shnum)); /* {.rel,}__mcount_loc */
156 ulseek(fd_map, 0, SEEK_SET);
157 uwrite(fd_map, ehdr, sizeof(*ehdr));
158}
159
160
161/*
162 * Look at the relocations in order to find the calls to mcount.
163 * Accumulate the section offsets that are found, and their relocation info,
164 * onto the end of the existing arrays.
165 */
166static uint_t *sift_rel_mcount(uint_t *mlocp,
167 unsigned const offbase,
168 Elf_Rel **const mrelpp,
169 Elf_Shdr const *const relhdr,
170 Elf_Ehdr const *const ehdr,
171 unsigned const recsym,
172 uint_t const recval,
173 unsigned const reltype)
174{
175 uint_t *const mloc0 = mlocp;
176 Elf_Rel *mrelp = *mrelpp;
177 Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
178 + (void *)ehdr);
179 unsigned const symsec_sh_link = w(relhdr->sh_link);
180 Elf_Shdr const *const symsec = &shdr0[symsec_sh_link];
181 Elf_Sym const *const sym0 = (Elf_Sym const *)(_w(symsec->sh_offset)
182 + (void *)ehdr);
183
184 Elf_Shdr const *const strsec = &shdr0[w(symsec->sh_link)];
185 char const *const str0 = (char const *)(_w(strsec->sh_offset)
186 + (void *)ehdr);
187
188 Elf_Rel const *const rel0 = (Elf_Rel const *)(_w(relhdr->sh_offset)
189 + (void *)ehdr);
190 unsigned rel_entsize = _w(relhdr->sh_entsize);
191 unsigned const nrel = _w(relhdr->sh_size) / rel_entsize;
192 Elf_Rel const *relp = rel0;
193
194 unsigned mcountsym = 0;
195 unsigned t;
196
197 for (t = nrel; t; --t) {
198 if (!mcountsym) {
199 Elf_Sym const *const symp =
200 &sym0[ELF_R_SYM(_w(relp->r_info))];
201 char const *symname = &str0[w(symp->st_name)];
202
203 if ('.' == symname[0])
204 ++symname; /* ppc64 hack */
205 if (0 == strcmp((('_' == gpfx) ? "_mcount" : "mcount"),
206 symname))
207 mcountsym = ELF_R_SYM(_w(relp->r_info));
208 }
209
210 if (mcountsym == ELF_R_SYM(_w(relp->r_info))) {
211 uint_t const addend = _w(_w(relp->r_offset) - recval);
212
213 mrelp->r_offset = _w(offbase
214 + ((void *)mlocp - (void *)mloc0));
215 mrelp->r_info = _w(ELF_R_INFO(recsym, reltype));
216 if (sizeof(Elf_Rela) == rel_entsize) {
217 ((Elf_Rela *)mrelp)->r_addend = addend;
218 *mlocp++ = 0;
219 } else
220 *mlocp++ = addend;
221
222 mrelp = (Elf_Rel *)(rel_entsize + (void *)mrelp);
223 }
224 relp = (Elf_Rel const *)(rel_entsize + (void *)relp);
225 }
226 *mrelpp = mrelp;
227 return mlocp;
228}
229
230
231/*
232 * Find a symbol in the given section, to be used as the base for relocating
233 * the table of offsets of calls to mcount. A local or global symbol suffices,
234 * but avoid a Weak symbol because it may be overridden; the change in value
235 * would invalidate the relocations of the offsets of the calls to mcount.
236 * Often the found symbol will be the unnamed local symbol generated by
237 * GNU 'as' for the start of each section. For example:
238 * Num: Value Size Type Bind Vis Ndx Name
239 * 2: 00000000 0 SECTION LOCAL DEFAULT 1
240 */
241static unsigned find_secsym_ndx(unsigned const txtndx,
242 char const *const txtname,
243 uint_t *const recvalp,
244 Elf_Shdr const *const symhdr,
245 Elf_Ehdr const *const ehdr)
246{
247 Elf_Sym const *const sym0 = (Elf_Sym const *)(_w(symhdr->sh_offset)
248 + (void *)ehdr);
249 unsigned const nsym = _w(symhdr->sh_size) / _w(symhdr->sh_entsize);
250 Elf_Sym const *symp;
251 unsigned t;
252
253 for (symp = sym0, t = nsym; t; --t, ++symp) {
254 unsigned int const st_bind = ELF_ST_BIND(symp->st_info);
255
256 if (txtndx == w2(symp->st_shndx)
257 /* avoid STB_WEAK */
258 && (STB_LOCAL == st_bind || STB_GLOBAL == st_bind)) {
259 *recvalp = _w(symp->st_value);
260 return symp - sym0;
261 }
262 }
263 fprintf(stderr, "Cannot find symbol for section %d: %s.\n",
264 txtndx, txtname);
265 fail_file();
266}
267
268
269/* Evade ISO C restriction: no declaration after statement in has_rel_mcount. */
270static char const *
271__has_rel_mcount(Elf_Shdr const *const relhdr, /* is SHT_REL or SHT_RELA */
272 Elf_Shdr const *const shdr0,
273 char const *const shstrtab,
274 char const *const fname)
275{
276 /* .sh_info depends on .sh_type == SHT_REL[,A] */
277 Elf_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)];
278 char const *const txtname = &shstrtab[w(txthdr->sh_name)];
279
280 if (0 == strcmp("__mcount_loc", txtname)) {
281 fprintf(stderr, "warning: __mcount_loc already exists: %s\n",
282 fname);
283 succeed_file();
284 }
285 if (SHT_PROGBITS != w(txthdr->sh_type) ||
286 !is_mcounted_section_name(txtname))
287 return NULL;
288 return txtname;
289}
290
291static char const *has_rel_mcount(Elf_Shdr const *const relhdr,
292 Elf_Shdr const *const shdr0,
293 char const *const shstrtab,
294 char const *const fname)
295{
296 if (SHT_REL != w(relhdr->sh_type) && SHT_RELA != w(relhdr->sh_type))
297 return NULL;
298 return __has_rel_mcount(relhdr, shdr0, shstrtab, fname);
299}
300
301
302static unsigned tot_relsize(Elf_Shdr const *const shdr0,
303 unsigned nhdr,
304 const char *const shstrtab,
305 const char *const fname)
306{
307 unsigned totrelsz = 0;
308 Elf_Shdr const *shdrp = shdr0;
309
310 for (; nhdr; --nhdr, ++shdrp) {
311 if (has_rel_mcount(shdrp, shdr0, shstrtab, fname))
312 totrelsz += _w(shdrp->sh_size);
313 }
314 return totrelsz;
315}
316
317
318/* Overall supervision for Elf32 ET_REL file. */
319static void
320do_func(Elf_Ehdr *const ehdr, char const *const fname, unsigned const reltype)
321{
322 Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
323 + (void *)ehdr);
324 unsigned const nhdr = w2(ehdr->e_shnum);
325 Elf_Shdr *const shstr = &shdr0[w2(ehdr->e_shstrndx)];
326 char const *const shstrtab = (char const *)(_w(shstr->sh_offset)
327 + (void *)ehdr);
328
329 Elf_Shdr const *relhdr;
330 unsigned k;
331
332 /* Upper bound on space: assume all relevant relocs are for mcount. */
333 unsigned const totrelsz = tot_relsize(shdr0, nhdr, shstrtab, fname);
334 Elf_Rel *const mrel0 = umalloc(totrelsz);
335 Elf_Rel * mrelp = mrel0;
336
337 /* 2*sizeof(address) <= sizeof(Elf_Rel) */
338 uint_t *const mloc0 = umalloc(totrelsz>>1);
339 uint_t * mlocp = mloc0;
340
341 unsigned rel_entsize = 0;
342 unsigned symsec_sh_link = 0;
343
344 for (relhdr = shdr0, k = nhdr; k; --k, ++relhdr) {
345 char const *const txtname = has_rel_mcount(relhdr, shdr0,
346 shstrtab, fname);
347 if (txtname) {
348 uint_t recval = 0;
349 unsigned const recsym = find_secsym_ndx(
350 w(relhdr->sh_info), txtname, &recval,
351 &shdr0[symsec_sh_link = w(relhdr->sh_link)],
352 ehdr);
353
354 rel_entsize = _w(relhdr->sh_entsize);
355 mlocp = sift_rel_mcount(mlocp,
356 (void *)mlocp - (void *)mloc0, &mrelp,
357 relhdr, ehdr, recsym, recval, reltype);
358 }
359 }
360 if (mloc0 != mlocp) {
361 append_func(ehdr, shstr, mloc0, mlocp, mrel0, mrelp,
362 rel_entsize, symsec_sh_link);
363 }
364 free(mrel0);
365 free(mloc0);
366}
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index f3c9c0a90b98..1d7963f4ee79 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -159,6 +159,7 @@ my $section_regex; # Find the start of a section
159my $function_regex; # Find the name of a function 159my $function_regex; # Find the name of a function
160 # (return offset and func name) 160 # (return offset and func name)
161my $mcount_regex; # Find the call site to mcount (return offset) 161my $mcount_regex; # Find the call site to mcount (return offset)
162my $mcount_adjust; # Address adjustment to mcount offset
162my $alignment; # The .align value to use for $mcount_section 163my $alignment; # The .align value to use for $mcount_section
163my $section_type; # Section header plus possible alignment command 164my $section_type; # Section header plus possible alignment command
164my $can_use_local = 0; # If we can use local function references 165my $can_use_local = 0; # If we can use local function references
@@ -213,6 +214,7 @@ $section_regex = "Disassembly of section\\s+(\\S+):";
213$function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:"; 214$function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:";
214$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$"; 215$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$";
215$section_type = '@progbits'; 216$section_type = '@progbits';
217$mcount_adjust = 0;
216$type = ".long"; 218$type = ".long";
217 219
218if ($arch eq "x86_64") { 220if ($arch eq "x86_64") {
@@ -268,6 +270,8 @@ if ($arch eq "x86_64") {
268} elsif ($arch eq "arm") { 270} elsif ($arch eq "arm") {
269 $alignment = 2; 271 $alignment = 2;
270 $section_type = '%progbits'; 272 $section_type = '%progbits';
273 $mcount_regex = "^\\s*([0-9a-fA-F]+):\\s*R_ARM_(CALL|PC24|THM_CALL)" .
274 "\\s+(__gnu_mcount_nc|mcount)\$";
271 275
272} elsif ($arch eq "ia64") { 276} elsif ($arch eq "ia64") {
273 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; 277 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
@@ -326,7 +330,7 @@ if ($arch eq "x86_64") {
326 # 14: R_MIPS_NONE *ABS* 330 # 14: R_MIPS_NONE *ABS*
327 # 18: 00020021 nop 331 # 18: 00020021 nop
328 if ($is_module eq "0") { 332 if ($is_module eq "0") {
329 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; 333 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_26\\s+_mcount\$";
330 } else { 334 } else {
331 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$"; 335 $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$";
332 } 336 }
@@ -351,6 +355,9 @@ if ($arch eq "x86_64") {
351} elsif ($arch eq "microblaze") { 355} elsif ($arch eq "microblaze") {
352 # Microblaze calls '_mcount' instead of plain 'mcount'. 356 # Microblaze calls '_mcount' instead of plain 'mcount'.
353 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; 357 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
358} elsif ($arch eq "blackfin") {
359 $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s__mcount\$";
360 $mcount_adjust = -4;
354} else { 361} else {
355 die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; 362 die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD";
356} 363}
@@ -511,7 +518,7 @@ while (<IN>) {
511 } 518 }
512 # is this a call site to mcount? If so, record it to print later 519 # is this a call site to mcount? If so, record it to print later
513 if ($text_found && /$mcount_regex/) { 520 if ($text_found && /$mcount_regex/) {
514 push(@offsets, hex $1); 521 push(@offsets, (hex $1) + $mcount_adjust);
515 } 522 }
516} 523}
517 524
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index dc54b1982958..ef8729f48586 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -43,7 +43,7 @@ scm_version()
43 fi 43 fi
44 44
45 # Check for git and a git repo. 45 # Check for git and a git repo.
46 if head=`git rev-parse --verify --short HEAD 2>/dev/null`; then 46 if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
47 47
48 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore 48 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
49 # it, because this version is defined in the top level Makefile. 49 # it, because this version is defined in the top level Makefile.
@@ -85,7 +85,7 @@ scm_version()
85 fi 85 fi
86 86
87 # Check for mercurial and a mercurial repo. 87 # Check for mercurial and a mercurial repo.
88 if hgid=`hg id 2>/dev/null`; then 88 if test -d .hg && hgid=`hg id 2>/dev/null`; then
89 tag=`printf '%s' "$hgid" | cut -s -d' ' -f2` 89 tag=`printf '%s' "$hgid" | cut -s -d' ' -f2`
90 90
91 # Do we have an untagged version? 91 # Do we have an untagged version?