aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.headersinst20
-rw-r--r--scripts/Makefile.lib9
-rwxr-xr-xscripts/checkpatch.pl652
-rwxr-xr-xscripts/coccicheck76
-rw-r--r--scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci2
-rw-r--r--scripts/coccinelle/api/alloc/kzalloc-simple.cocci2
-rw-r--r--scripts/coccinelle/api/d_find_alias.cocci2
-rw-r--r--scripts/coccinelle/api/devm_request_and_ioremap.cocci2
-rw-r--r--scripts/coccinelle/api/kstrdup.cocci2
-rw-r--r--scripts/coccinelle/api/memdup.cocci2
-rw-r--r--scripts/coccinelle/api/memdup_user.cocci2
-rw-r--r--scripts/coccinelle/api/ptr_ret.cocci2
-rw-r--r--scripts/coccinelle/api/simple_open.cocci2
-rw-r--r--scripts/coccinelle/free/devm_free.cocci2
-rw-r--r--scripts/coccinelle/free/kfree.cocci2
-rw-r--r--scripts/coccinelle/free/kfreeaddr.cocci32
-rw-r--r--scripts/coccinelle/free/pci_free_consistent.cocci52
-rw-r--r--scripts/coccinelle/iterators/fen.cocci2
-rw-r--r--scripts/coccinelle/iterators/itnull.cocci2
-rw-r--r--scripts/coccinelle/iterators/list_entry_update.cocci2
-rw-r--r--scripts/coccinelle/iterators/use_after_iter.cocci2
-rw-r--r--scripts/coccinelle/locks/call_kern.cocci2
-rw-r--r--scripts/coccinelle/locks/double_lock.cocci2
-rw-r--r--scripts/coccinelle/locks/flags.cocci2
-rw-r--r--scripts/coccinelle/locks/mini_lock.cocci2
-rw-r--r--scripts/coccinelle/misc/boolinit.cocci2
-rw-r--r--scripts/coccinelle/misc/cstptr.cocci2
-rw-r--r--scripts/coccinelle/misc/doubleinit.cocci2
-rw-r--r--scripts/coccinelle/misc/ifaddr.cocci2
-rw-r--r--scripts/coccinelle/misc/ifcol.cocci2
-rw-r--r--scripts/coccinelle/misc/noderef.cocci2
-rw-r--r--scripts/coccinelle/misc/orplus.cocci2
-rw-r--r--scripts/coccinelle/misc/warn.cocci2
-rw-r--r--scripts/coccinelle/null/eno.cocci2
-rw-r--r--scripts/coccinelle/null/kmerr.cocci2
-rw-r--r--scripts/coccinelle/tests/doublebitand.cocci2
-rw-r--r--scripts/coccinelle/tests/doubletest.cocci2
-rw-r--r--scripts/coccinelle/tests/odd_ptr_err.cocci2
-rwxr-xr-xscripts/config12
-rw-r--r--scripts/headers_install.sh7
-rw-r--r--scripts/kconfig/conf.c6
-rw-r--r--scripts/kconfig/confdata.c33
-rw-r--r--scripts/kconfig/expr.h3
-rw-r--r--scripts/kconfig/lkc.h3
-rw-r--r--scripts/kconfig/lkc_proto.h1
-rw-r--r--scripts/kconfig/lxdialog/checklist.c8
-rw-r--r--scripts/kconfig/lxdialog/dialog.h14
-rw-r--r--scripts/kconfig/lxdialog/inputbox.c8
-rw-r--r--scripts/kconfig/lxdialog/menubox.c6
-rw-r--r--scripts/kconfig/lxdialog/textbox.c6
-rw-r--r--scripts/kconfig/lxdialog/util.c46
-rw-r--r--scripts/kconfig/lxdialog/yesno.c8
-rw-r--r--scripts/kconfig/mconf.c21
-rw-r--r--scripts/kconfig/menu.c16
-rw-r--r--scripts/kconfig/nconf.c39
-rw-r--r--scripts/kconfig/nconf.gui.c20
-rw-r--r--scripts/kconfig/symbol.c99
-rw-r--r--scripts/mod/Makefile15
-rw-r--r--scripts/mod/devicetable-offsets.c6
-rw-r--r--scripts/mod/file2alias.c30
-rw-r--r--scripts/mod/modpost.c54
-rwxr-xr-xscripts/package/mkspec1
-rwxr-xr-xscripts/setlocalversion3
-rw-r--r--scripts/sortextable.c5
64 files changed, 1042 insertions, 333 deletions
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
index 182084d728c8..8ccf83056a7a 100644
--- a/scripts/Makefile.headersinst
+++ b/scripts/Makefile.headersinst
@@ -47,18 +47,24 @@ header-y := $(filter-out $(generic-y), $(header-y))
47all-files := $(header-y) $(genhdr-y) $(wrapper-files) 47all-files := $(header-y) $(genhdr-y) $(wrapper-files)
48output-files := $(addprefix $(installdir)/, $(all-files)) 48output-files := $(addprefix $(installdir)/, $(all-files))
49 49
50input-files := $(foreach hdr, $(header-y), \ 50input-files1 := $(foreach hdr, $(header-y), \
51 $(if $(wildcard $(srcdir)/$(hdr)), \ 51 $(if $(wildcard $(srcdir)/$(hdr)), \
52 $(wildcard $(srcdir)/$(hdr)), \ 52 $(wildcard $(srcdir)/$(hdr))) \
53 )
54input-files1-name := $(notdir $(input-files1))
55input-files2 := $(foreach hdr, $(header-y), \
56 $(if $(wildcard $(srcdir)/$(hdr)),, \
53 $(if $(wildcard $(oldsrcdir)/$(hdr)), \ 57 $(if $(wildcard $(oldsrcdir)/$(hdr)), \
54 $(wildcard $(oldsrcdir)/$(hdr)), \ 58 $(wildcard $(oldsrcdir)/$(hdr)), \
55 $(error Missing UAPI file $(srcdir)/$(hdr))) \ 59 $(error Missing UAPI file $(srcdir)/$(hdr))) \
56 )) \ 60 ))
57 $(foreach hdr, $(genhdr-y), \ 61input-files2-name := $(notdir $(input-files2))
62input-files3 := $(foreach hdr, $(genhdr-y), \
58 $(if $(wildcard $(gendir)/$(hdr)), \ 63 $(if $(wildcard $(gendir)/$(hdr)), \
59 $(wildcard $(gendir)/$(hdr)), \ 64 $(wildcard $(gendir)/$(hdr)), \
60 $(error Missing generated UAPI file $(gendir)/$(hdr)) \ 65 $(error Missing generated UAPI file $(gendir)/$(hdr)) \
61 )) 66 ))
67input-files3-name := $(notdir $(input-files3))
62 68
63# Work out what needs to be removed 69# Work out what needs to be removed
64oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 70oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
@@ -72,7 +78,9 @@ printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
72quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 78quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
73 file$(if $(word 2, $(all-files)),s)) 79 file$(if $(word 2, $(all-files)),s))
74 cmd_install = \ 80 cmd_install = \
75 $(CONFIG_SHELL) $< $(installdir) $(input-files); \ 81 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \
82 $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \
83 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \
76 for F in $(wrapper-files); do \ 84 for F in $(wrapper-files); do \
77 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ 85 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
78 done; \ 86 done; \
@@ -98,7 +106,7 @@ __headersinst: $(subdirs) $(install-file)
98 @: 106 @:
99 107
100targets += $(install-file) 108targets += $(install-file)
101$(install-file): scripts/headers_install.sh $(input-files) FORCE 109$(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE
102 $(if $(unwanted),$(call cmd,remove),) 110 $(if $(unwanted),$(call cmd,remove),)
103 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 111 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
104 $(call if_changed,install) 112 $(call if_changed,install)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index f97869f1f09b..49392ecbef17 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -63,7 +63,7 @@ multi-objs := $(multi-objs-y) $(multi-objs-m)
63subdir-obj-y := $(filter %/built-in.o, $(obj-y)) 63subdir-obj-y := $(filter %/built-in.o, $(obj-y))
64 64
65# $(obj-dirs) is a list of directories that contain object files 65# $(obj-dirs) is a list of directories that contain object files
66obj-dirs := $(dir $(multi-objs) $(subdir-obj-y)) 66obj-dirs := $(dir $(multi-objs) $(obj-y))
67 67
68# Replace multi-part objects by their individual parts, look at local dir only 68# Replace multi-part objects by their individual parts, look at local dir only
69real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) 69real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
@@ -244,7 +244,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
244# --------------------------------------------------------------------------- 244# ---------------------------------------------------------------------------
245 245
246# Generate an assembly file to wrap the output of the device tree compiler 246# Generate an assembly file to wrap the output of the device tree compiler
247quiet_cmd_dt_S_dtb= DTB $@ 247quiet_cmd_dt_S_dtb= DTB $@
248cmd_dt_S_dtb= \ 248cmd_dt_S_dtb= \
249( \ 249( \
250 echo '\#include <asm-generic/vmlinux.lds.h>'; \ 250 echo '\#include <asm-generic/vmlinux.lds.h>'; \
@@ -311,6 +311,11 @@ cmd_lzo = (cat $(filter-out FORCE,$^) | \
311 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 311 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
312 (rm -f $@ ; false) 312 (rm -f $@ ; false)
313 313
314quiet_cmd_lz4 = LZ4 $@
315cmd_lz4 = (cat $(filter-out FORCE,$^) | \
316 lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
317 (rm -f $@ ; false)
318
314# U-Boot mkimage 319# U-Boot mkimage
315# --------------------------------------------------------------------------- 320# ---------------------------------------------------------------------------
316 321
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b954de58304f..2ee9eb750560 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6,6 +6,7 @@
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;
9use POSIX;
9 10
10my $P = $0; 11my $P = $0;
11$P =~ s@.*/@@g; 12$P =~ s@.*/@@g;
@@ -27,9 +28,11 @@ my $summary = 1;
27my $mailback = 0; 28my $mailback = 0;
28my $summary_file = 0; 29my $summary_file = 0;
29my $show_types = 0; 30my $show_types = 0;
31my $fix = 0;
30my $root; 32my $root;
31my %debug; 33my %debug;
32my %ignore_type = (); 34my %ignore_type = ();
35my %camelcase = ();
33my @ignore = (); 36my @ignore = ();
34my $help = 0; 37my $help = 0;
35my $configuration_file = ".checkpatch.conf"; 38my $configuration_file = ".checkpatch.conf";
@@ -63,6 +66,11 @@ Options:
63 is all off) 66 is all off)
64 --test-only=WORD report only warnings/errors containing WORD 67 --test-only=WORD report only warnings/errors containing WORD
65 literally 68 literally
69 --fix EXPERIMENTAL - may create horrible results
70 If correctable single-line errors exist, create
71 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
72 with potential errors corrected to the preferred
73 checkpatch style
66 -h, --help, --version display this help and exit 74 -h, --help, --version display this help and exit
67 75
68When FILE is - read standard input. 76When FILE is - read standard input.
@@ -114,7 +122,7 @@ GetOptions(
114 'summary!' => \$summary, 122 'summary!' => \$summary,
115 'mailback!' => \$mailback, 123 'mailback!' => \$mailback,
116 'summary-file!' => \$summary_file, 124 'summary-file!' => \$summary_file,
117 125 'fix!' => \$fix,
118 'debug=s' => \%debug, 126 'debug=s' => \%debug,
119 'test-only=s' => \$tst_only, 127 'test-only=s' => \$tst_only,
120 'h|help' => \$help, 128 'h|help' => \$help,
@@ -230,17 +238,22 @@ our $Inline = qr{inline|__always_inline|noinline};
230our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; 238our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
231our $Lval = qr{$Ident(?:$Member)*}; 239our $Lval = qr{$Ident(?:$Member)*};
232 240
241our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
242our $Binary = qr{(?i)0b[01]+$Int_type?};
243our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
244our $Int = qr{[0-9]+$Int_type?};
233our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; 245our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
234our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; 246our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
235our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; 247our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
236our $Float = qr{$Float_hex|$Float_dec|$Float_int}; 248our $Float = qr{$Float_hex|$Float_dec|$Float_int};
237our $Constant = qr{$Float|(?i)(?:0x[0-9a-f]+|[0-9]+)[ul]*}; 249our $Constant = qr{$Float|$Binary|$Hex|$Int};
238our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; 250our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
239our $Compare = qr{<=|>=|==|!=|<|>}; 251our $Compare = qr{<=|>=|==|!=|<|>};
252our $Arithmetic = qr{\+|-|\*|\/|%};
240our $Operators = qr{ 253our $Operators = qr{
241 <=|>=|==|!=| 254 <=|>=|==|!=|
242 =>|->|<<|>>|<|>|!|~| 255 =>|->|<<|>>|<|>|!|~|
243 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% 256 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
244 }x; 257 }x;
245 258
246our $NonptrType; 259our $NonptrType;
@@ -269,7 +282,7 @@ our $typeTypedefs = qr{(?x:
269 282
270our $logFunctions = qr{(?x: 283our $logFunctions = qr{(?x:
271 printk(?:_ratelimited|_once|)| 284 printk(?:_ratelimited|_once|)|
272 [a-z0-9]+_(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| 285 (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
273 WARN(?:_RATELIMIT|_ONCE|)| 286 WARN(?:_RATELIMIT|_ONCE|)|
274 panic| 287 panic|
275 MODULE_[A-Z_]+ 288 MODULE_[A-Z_]+
@@ -338,7 +351,6 @@ sub build_types {
338} 351}
339build_types(); 352build_types();
340 353
341
342our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; 354our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
343 355
344# Using $balanced_parens, $LvalOrFunc, or $FuncArg 356# Using $balanced_parens, $LvalOrFunc, or $FuncArg
@@ -358,10 +370,94 @@ sub deparenthesize {
358 return $string; 370 return $string;
359} 371}
360 372
373sub seed_camelcase_file {
374 my ($file) = @_;
375
376 return if (!(-f $file));
377
378 local $/;
379
380 open(my $include_file, '<', "$file")
381 or warn "$P: Can't read '$file' $!\n";
382 my $text = <$include_file>;
383 close($include_file);
384
385 my @lines = split('\n', $text);
386
387 foreach my $line (@lines) {
388 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
389 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
390 $camelcase{$1} = 1;
391 }
392 elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*\(/) {
393 $camelcase{$1} = 1;
394 }
395 }
396}
397
398my $camelcase_seeded = 0;
399sub seed_camelcase_includes {
400 return if ($camelcase_seeded);
401
402 my $files;
403 my $camelcase_cache = "";
404 my @include_files = ();
405
406 $camelcase_seeded = 1;
407
408 if (-d ".git") {
409 my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
410 chomp $git_last_include_commit;
411 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
412 } else {
413 my $last_mod_date = 0;
414 $files = `find $root/include -name "*.h"`;
415 @include_files = split('\n', $files);
416 foreach my $file (@include_files) {
417 my $date = POSIX::strftime("%Y%m%d%H%M",
418 localtime((stat $file)[9]));
419 $last_mod_date = $date if ($last_mod_date < $date);
420 }
421 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
422 }
423
424 if ($camelcase_cache ne "" && -f $camelcase_cache) {
425 open(my $camelcase_file, '<', "$camelcase_cache")
426 or warn "$P: Can't read '$camelcase_cache' $!\n";
427 while (<$camelcase_file>) {
428 chomp;
429 $camelcase{$_} = 1;
430 }
431 close($camelcase_file);
432
433 return;
434 }
435
436 if (-d ".git") {
437 $files = `git ls-files "include/*.h"`;
438 @include_files = split('\n', $files);
439 }
440
441 foreach my $file (@include_files) {
442 seed_camelcase_file($file);
443 }
444
445 if ($camelcase_cache ne "") {
446 unlink glob ".checkpatch-camelcase.*";
447 open(my $camelcase_file, '>', "$camelcase_cache")
448 or warn "$P: Can't write '$camelcase_cache' $!\n";
449 foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
450 print $camelcase_file ("$_\n");
451 }
452 close($camelcase_file);
453 }
454}
455
361$chk_signoff = 0 if ($file); 456$chk_signoff = 0 if ($file);
362 457
363my @rawlines = (); 458my @rawlines = ();
364my @lines = (); 459my @lines = ();
460my @fixed = ();
365my $vname; 461my $vname;
366for my $filename (@ARGV) { 462for my $filename (@ARGV) {
367 my $FILE; 463 my $FILE;
@@ -389,6 +485,7 @@ for my $filename (@ARGV) {
389 } 485 }
390 @rawlines = (); 486 @rawlines = ();
391 @lines = (); 487 @lines = ();
488 @fixed = ();
392} 489}
393 490
394exit($exit); 491exit($exit);
@@ -429,7 +526,7 @@ sub parse_email {
429 $comment = $2 if defined $2; 526 $comment = $2 if defined $2;
430 $formatted_email =~ s/$address.*$//; 527 $formatted_email =~ s/$address.*$//;
431 $name = $formatted_email; 528 $name = $formatted_email;
432 $name =~ s/^\s+|\s+$//g; 529 $name = trim($name);
433 $name =~ s/^\"|\"$//g; 530 $name =~ s/^\"|\"$//g;
434 # If there's a name left after stripping spaces and 531 # If there's a name left after stripping spaces and
435 # leading quotes, and the address doesn't have both 532 # leading quotes, and the address doesn't have both
@@ -444,9 +541,9 @@ sub parse_email {
444 } 541 }
445 } 542 }
446 543
447 $name =~ s/^\s+|\s+$//g; 544 $name = trim($name);
448 $name =~ s/^\"|\"$//g; 545 $name =~ s/^\"|\"$//g;
449 $address =~ s/^\s+|\s+$//g; 546 $address = trim($address);
450 $address =~ s/^\<|\>$//g; 547 $address =~ s/^\<|\>$//g;
451 548
452 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars 549 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
@@ -462,9 +559,9 @@ sub format_email {
462 559
463 my $formatted_email; 560 my $formatted_email;
464 561
465 $name =~ s/^\s+|\s+$//g; 562 $name = trim($name);
466 $name =~ s/^\"|\"$//g; 563 $name =~ s/^\"|\"$//g;
467 $address =~ s/^\s+|\s+$//g; 564 $address = trim($address);
468 565
469 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars 566 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
470 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes 567 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
@@ -1286,19 +1383,25 @@ sub ERROR {
1286 if (report("ERROR", $_[0], $_[1])) { 1383 if (report("ERROR", $_[0], $_[1])) {
1287 our $clean = 0; 1384 our $clean = 0;
1288 our $cnt_error++; 1385 our $cnt_error++;
1386 return 1;
1289 } 1387 }
1388 return 0;
1290} 1389}
1291sub WARN { 1390sub WARN {
1292 if (report("WARNING", $_[0], $_[1])) { 1391 if (report("WARNING", $_[0], $_[1])) {
1293 our $clean = 0; 1392 our $clean = 0;
1294 our $cnt_warn++; 1393 our $cnt_warn++;
1394 return 1;
1295 } 1395 }
1396 return 0;
1296} 1397}
1297sub CHK { 1398sub CHK {
1298 if ($check && report("CHECK", $_[0], $_[1])) { 1399 if ($check && report("CHECK", $_[0], $_[1])) {
1299 our $clean = 0; 1400 our $clean = 0;
1300 our $cnt_chk++; 1401 our $cnt_chk++;
1402 return 1;
1301 } 1403 }
1404 return 0;
1302} 1405}
1303 1406
1304sub check_absolute_file { 1407sub check_absolute_file {
@@ -1329,6 +1432,29 @@ sub check_absolute_file {
1329 } 1432 }
1330} 1433}
1331 1434
1435sub trim {
1436 my ($string) = @_;
1437
1438 $string =~ s/(^\s+|\s+$)//g;
1439
1440 return $string;
1441}
1442
1443sub tabify {
1444 my ($leading) = @_;
1445
1446 my $source_indent = 8;
1447 my $max_spaces_before_tab = $source_indent - 1;
1448 my $spaces_to_tab = " " x $source_indent;
1449
1450 #convert leading spaces to tabs
1451 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
1452 #Remove spaces before a tab
1453 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
1454
1455 return "$leading";
1456}
1457
1332sub pos_last_openparen { 1458sub pos_last_openparen {
1333 my ($line) = @_; 1459 my ($line) = @_;
1334 1460
@@ -1406,7 +1532,6 @@ sub process {
1406 my %suppress_export; 1532 my %suppress_export;
1407 my $suppress_statement = 0; 1533 my $suppress_statement = 0;
1408 1534
1409 my %camelcase = ();
1410 1535
1411 # Pre-scan the patch sanitizing the lines. 1536 # Pre-scan the patch sanitizing the lines.
1412 # Pre-scan the patch looking for any __setup documentation. 1537 # Pre-scan the patch looking for any __setup documentation.
@@ -1420,6 +1545,8 @@ sub process {
1420 $linenr++; 1545 $linenr++;
1421 $line = $rawline; 1546 $line = $rawline;
1422 1547
1548 push(@fixed, $rawline) if ($fix);
1549
1423 if ($rawline=~/^\+\+\+\s+(\S+)/) { 1550 if ($rawline=~/^\+\+\+\s+(\S+)/) {
1424 $setup_docs = 0; 1551 $setup_docs = 0;
1425 if ($1 =~ m@Documentation/kernel-parameters.txt$@) { 1552 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
@@ -1611,16 +1738,29 @@ sub process {
1611 "Non-standard signature: $sign_off\n" . $herecurr); 1738 "Non-standard signature: $sign_off\n" . $herecurr);
1612 } 1739 }
1613 if (defined $space_before && $space_before ne "") { 1740 if (defined $space_before && $space_before ne "") {
1614 WARN("BAD_SIGN_OFF", 1741 if (WARN("BAD_SIGN_OFF",
1615 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); 1742 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
1743 $fix) {
1744 $fixed[$linenr - 1] =
1745 "$ucfirst_sign_off $email";
1746 }
1616 } 1747 }
1617 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { 1748 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
1618 WARN("BAD_SIGN_OFF", 1749 if (WARN("BAD_SIGN_OFF",
1619 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr); 1750 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
1751 $fix) {
1752 $fixed[$linenr - 1] =
1753 "$ucfirst_sign_off $email";
1754 }
1755
1620 } 1756 }
1621 if (!defined $space_after || $space_after ne " ") { 1757 if (!defined $space_after || $space_after ne " ") {
1622 WARN("BAD_SIGN_OFF", 1758 if (WARN("BAD_SIGN_OFF",
1623 "Use a single space after $ucfirst_sign_off\n" . $herecurr); 1759 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
1760 $fix) {
1761 $fixed[$linenr - 1] =
1762 "$ucfirst_sign_off $email";
1763 }
1624 } 1764 }
1625 1765
1626 my ($email_name, $email_address, $comment) = parse_email($email); 1766 my ($email_name, $email_address, $comment) = parse_email($email);
@@ -1710,8 +1850,12 @@ sub process {
1710 1850
1711 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { 1851 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1712 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1852 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1713 ERROR("TRAILING_WHITESPACE", 1853 if (ERROR("TRAILING_WHITESPACE",
1714 "trailing whitespace\n" . $herevet); 1854 "trailing whitespace\n" . $herevet) &&
1855 $fix) {
1856 $fixed[$linenr - 1] =~ s/^(\+.*?)\s+$/$1/;
1857 }
1858
1715 $rpt_cleaners = 1; 1859 $rpt_cleaners = 1;
1716 } 1860 }
1717 1861
@@ -1806,8 +1950,12 @@ sub process {
1806 1950
1807# check for spaces before a quoted newline 1951# check for spaces before a quoted newline
1808 if ($rawline =~ /^.*\".*\s\\n/) { 1952 if ($rawline =~ /^.*\".*\s\\n/) {
1809 WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", 1953 if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
1810 "unnecessary whitespace before a quoted newline\n" . $herecurr); 1954 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
1955 $fix) {
1956 $fixed[$linenr - 1] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
1957 }
1958
1811 } 1959 }
1812 1960
1813# check for adding lines without a newline. 1961# check for adding lines without a newline.
@@ -1838,16 +1986,23 @@ sub process {
1838 if ($rawline =~ /^\+\s* \t\s*\S/ || 1986 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1839 $rawline =~ /^\+\s* \s*/) { 1987 $rawline =~ /^\+\s* \s*/) {
1840 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1988 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1841 ERROR("CODE_INDENT",
1842 "code indent should use tabs where possible\n" . $herevet);
1843 $rpt_cleaners = 1; 1989 $rpt_cleaners = 1;
1990 if (ERROR("CODE_INDENT",
1991 "code indent should use tabs where possible\n" . $herevet) &&
1992 $fix) {
1993 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
1994 }
1844 } 1995 }
1845 1996
1846# check for space before tabs. 1997# check for space before tabs.
1847 if ($rawline =~ /^\+/ && $rawline =~ / \t/) { 1998 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1848 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1999 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1849 WARN("SPACE_BEFORE_TAB", 2000 if (WARN("SPACE_BEFORE_TAB",
1850 "please, no space before tabs\n" . $herevet); 2001 "please, no space before tabs\n" . $herevet) &&
2002 $fix) {
2003 $fixed[$linenr - 1] =~
2004 s/(^\+.*) +\t/$1\t/;
2005 }
1851 } 2006 }
1852 2007
1853# check for && or || at the start of a line 2008# check for && or || at the start of a line
@@ -1875,25 +2030,42 @@ sub process {
1875 2030
1876 if ($newindent ne $goodtabindent && 2031 if ($newindent ne $goodtabindent &&
1877 $newindent ne $goodspaceindent) { 2032 $newindent ne $goodspaceindent) {
1878 CHK("PARENTHESIS_ALIGNMENT", 2033
1879 "Alignment should match open parenthesis\n" . $hereprev); 2034 if (CHK("PARENTHESIS_ALIGNMENT",
2035 "Alignment should match open parenthesis\n" . $hereprev) &&
2036 $fix && $line =~ /^\+/) {
2037 $fixed[$linenr - 1] =~
2038 s/^\+[ \t]*/\+$goodtabindent/;
2039 }
1880 } 2040 }
1881 } 2041 }
1882 } 2042 }
1883 2043
1884 if ($line =~ /^\+.*\*[ \t]*\)[ \t]+/) { 2044 if ($line =~ /^\+.*\*[ \t]*\)[ \t]+(?!$Assignment|$Arithmetic)/) {
1885 CHK("SPACING", 2045 if (CHK("SPACING",
1886 "No space is necessary after a cast\n" . $hereprev); 2046 "No space is necessary after a cast\n" . $hereprev) &&
2047 $fix) {
2048 $fixed[$linenr - 1] =~
2049 s/^(\+.*\*[ \t]*\))[ \t]+/$1/;
2050 }
1887 } 2051 }
1888 2052
1889 if ($realfile =~ m@^(drivers/net/|net/)@ && 2053 if ($realfile =~ m@^(drivers/net/|net/)@ &&
1890 $rawline =~ /^\+[ \t]*\/\*[ \t]*$/ && 2054 $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
1891 $prevrawline =~ /^\+[ \t]*$/) { 2055 $rawline =~ /^\+[ \t]*\*/) {
1892 WARN("NETWORKING_BLOCK_COMMENT_STYLE", 2056 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
1893 "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); 2057 "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
1894 } 2058 }
1895 2059
1896 if ($realfile =~ m@^(drivers/net/|net/)@ && 2060 if ($realfile =~ m@^(drivers/net/|net/)@ &&
2061 $prevrawline =~ /^\+[ \t]*\/\*/ && #starting /*
2062 $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
2063 $rawline !~ /^\+[ \t]*\*/) { #no leading *
2064 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
2065 "networking block comments start with * on subsequent lines\n" . $hereprev);
2066 }
2067
2068 if ($realfile =~ m@^(drivers/net/|net/)@ &&
1897 $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */ 2069 $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
1898 $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/ 2070 $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
1899 $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/ 2071 $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
@@ -1907,10 +2079,13 @@ sub process {
1907# 1) within comments 2079# 1) within comments
1908# 2) indented preprocessor commands 2080# 2) indented preprocessor commands
1909# 3) hanging labels 2081# 3) hanging labels
1910 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { 2082 if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) {
1911 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 2083 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1912 WARN("LEADING_SPACE", 2084 if (WARN("LEADING_SPACE",
1913 "please, no spaces at the start of a line\n" . $herevet); 2085 "please, no spaces at the start of a line\n" . $herevet) &&
2086 $fix) {
2087 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
2088 }
1914 } 2089 }
1915 2090
1916# check we are in a valid C source file if not then ignore this hunk 2091# check we are in a valid C source file if not then ignore this hunk
@@ -2200,7 +2375,7 @@ sub process {
2200 $prev_values = substr($curr_values, -1); 2375 $prev_values = substr($curr_values, -1);
2201 2376
2202#ignore lines not being added 2377#ignore lines not being added
2203 if ($line=~/^[^\+]/) {next;} 2378 next if ($line =~ /^[^\+]/);
2204 2379
2205# TEST: allow direct testing of the type matcher. 2380# TEST: allow direct testing of the type matcher.
2206 if ($dbg_type) { 2381 if ($dbg_type) {
@@ -2251,8 +2426,15 @@ sub process {
2251 2426
2252# no C99 // comments 2427# no C99 // comments
2253 if ($line =~ m{//}) { 2428 if ($line =~ m{//}) {
2254 ERROR("C99_COMMENTS", 2429 if (ERROR("C99_COMMENTS",
2255 "do not use C99 // comments\n" . $herecurr); 2430 "do not use C99 // comments\n" . $herecurr) &&
2431 $fix) {
2432 my $line = $fixed[$linenr - 1];
2433 if ($line =~ /\/\/(.*)$/) {
2434 my $comment = trim($1);
2435 $fixed[$linenr - 1] =~ s@\/\/(.*)$@/\* $comment \*/@;
2436 }
2437 }
2256 } 2438 }
2257 # Remove C99 comments. 2439 # Remove C99 comments.
2258 $line =~ s@//.*@@; 2440 $line =~ s@//.*@@;
@@ -2351,7 +2533,7 @@ sub process {
2351 # (char*[ const]) 2533 # (char*[ const])
2352 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) { 2534 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
2353 #print "AA<$1>\n"; 2535 #print "AA<$1>\n";
2354 my ($from, $to) = ($2, $2); 2536 my ($ident, $from, $to) = ($1, $2, $2);
2355 2537
2356 # Should start with a space. 2538 # Should start with a space.
2357 $to =~ s/^(\S)/ $1/; 2539 $to =~ s/^(\S)/ $1/;
@@ -2361,15 +2543,22 @@ sub process {
2361 while ($to =~ s/\*\s+\*/\*\*/) { 2543 while ($to =~ s/\*\s+\*/\*\*/) {
2362 } 2544 }
2363 2545
2364 #print "from<$from> to<$to>\n"; 2546## print "1: from<$from> to<$to> ident<$ident>\n";
2365 if ($from ne $to) { 2547 if ($from ne $to) {
2366 ERROR("POINTER_LOCATION", 2548 if (ERROR("POINTER_LOCATION",
2367 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); 2549 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) &&
2550 $fix) {
2551 my $sub_from = $ident;
2552 my $sub_to = $ident;
2553 $sub_to =~ s/\Q$from\E/$to/;
2554 $fixed[$linenr - 1] =~
2555 s@\Q$sub_from\E@$sub_to@;
2556 }
2368 } 2557 }
2369 } 2558 }
2370 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) { 2559 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
2371 #print "BB<$1>\n"; 2560 #print "BB<$1>\n";
2372 my ($from, $to, $ident) = ($2, $2, $3); 2561 my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
2373 2562
2374 # Should start with a space. 2563 # Should start with a space.
2375 $to =~ s/^(\S)/ $1/; 2564 $to =~ s/^(\S)/ $1/;
@@ -2381,10 +2570,18 @@ sub process {
2381 # Modifiers should have spaces. 2570 # Modifiers should have spaces.
2382 $to =~ s/(\b$Modifier$)/$1 /; 2571 $to =~ s/(\b$Modifier$)/$1 /;
2383 2572
2384 #print "from<$from> to<$to> ident<$ident>\n"; 2573## print "2: from<$from> to<$to> ident<$ident>\n";
2385 if ($from ne $to && $ident !~ /^$Modifier$/) { 2574 if ($from ne $to && $ident !~ /^$Modifier$/) {
2386 ERROR("POINTER_LOCATION", 2575 if (ERROR("POINTER_LOCATION",
2387 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); 2576 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) &&
2577 $fix) {
2578
2579 my $sub_from = $match;
2580 my $sub_to = $match;
2581 $sub_to =~ s/\Q$from\E/$to/;
2582 $fixed[$linenr - 1] =~
2583 s@\Q$sub_from\E@$sub_to@;
2584 }
2388 } 2585 }
2389 } 2586 }
2390 2587
@@ -2470,9 +2667,13 @@ sub process {
2470 } 2667 }
2471 2668
2472# missing space after union, struct or enum definition 2669# missing space after union, struct or enum definition
2473 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) { 2670 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
2474 WARN("SPACING", 2671 if (WARN("SPACING",
2475 "missing space after $1 definition\n" . $herecurr); 2672 "missing space after $1 definition\n" . $herecurr) &&
2673 $fix) {
2674 $fixed[$linenr - 1] =~
2675 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
2676 }
2476 } 2677 }
2477 2678
2478# check for spacing round square brackets; allowed: 2679# check for spacing round square brackets; allowed:
@@ -2484,8 +2685,12 @@ sub process {
2484 if ($prefix !~ /$Type\s+$/ && 2685 if ($prefix !~ /$Type\s+$/ &&
2485 ($where != 0 || $prefix !~ /^.\s+$/) && 2686 ($where != 0 || $prefix !~ /^.\s+$/) &&
2486 $prefix !~ /[{,]\s+$/) { 2687 $prefix !~ /[{,]\s+$/) {
2487 ERROR("BRACKET_SPACE", 2688 if (ERROR("BRACKET_SPACE",
2488 "space prohibited before open square bracket '['\n" . $herecurr); 2689 "space prohibited before open square bracket '['\n" . $herecurr) &&
2690 $fix) {
2691 $fixed[$linenr - 1] =~
2692 s/^(\+.*?)\s+\[/$1\[/;
2693 }
2489 } 2694 }
2490 } 2695 }
2491 2696
@@ -2502,7 +2707,6 @@ sub process {
2502 __attribute__|format|__extension__| 2707 __attribute__|format|__extension__|
2503 asm|__asm__)$/x) 2708 asm|__asm__)$/x)
2504 { 2709 {
2505
2506 # cpp #define statements have non-optional spaces, ie 2710 # cpp #define statements have non-optional spaces, ie
2507 # if there is a space between the name and the open 2711 # if there is a space between the name and the open
2508 # parenthesis it is simply not a parameter group. 2712 # parenthesis it is simply not a parameter group.
@@ -2516,19 +2720,20 @@ sub process {
2516 } elsif ($ctx =~ /$Type$/) { 2720 } elsif ($ctx =~ /$Type$/) {
2517 2721
2518 } else { 2722 } else {
2519 WARN("SPACING", 2723 if (WARN("SPACING",
2520 "space prohibited between function name and open parenthesis '('\n" . $herecurr); 2724 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
2725 $fix) {
2726 $fixed[$linenr - 1] =~
2727 s/\b$name\s+\(/$name\(/;
2728 }
2521 } 2729 }
2522 } 2730 }
2523 2731
2524# check for whitespace before a non-naked semicolon
2525 if ($line =~ /^\+.*\S\s+;/) {
2526 WARN("SPACING",
2527 "space prohibited before semicolon\n" . $herecurr);
2528 }
2529
2530# Check operator spacing. 2732# Check operator spacing.
2531 if (!($line=~/\#\s*include/)) { 2733 if (!($line=~/\#\s*include/)) {
2734 my $fixed_line = "";
2735 my $line_fixed = 0;
2736
2532 my $ops = qr{ 2737 my $ops = qr{
2533 <<=|>>=|<=|>=|==|!=| 2738 <<=|>>=|<=|>=|==|!=|
2534 \+=|-=|\*=|\/=|%=|\^=|\|=|&=| 2739 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
@@ -2537,11 +2742,30 @@ sub process {
2537 \?|: 2742 \?|:
2538 }x; 2743 }x;
2539 my @elements = split(/($ops|;)/, $opline); 2744 my @elements = split(/($ops|;)/, $opline);
2745
2746## print("element count: <" . $#elements . ">\n");
2747## foreach my $el (@elements) {
2748## print("el: <$el>\n");
2749## }
2750
2751 my @fix_elements = ();
2540 my $off = 0; 2752 my $off = 0;
2541 2753
2754 foreach my $el (@elements) {
2755 push(@fix_elements, substr($rawline, $off, length($el)));
2756 $off += length($el);
2757 }
2758
2759 $off = 0;
2760
2542 my $blank = copy_spacing($opline); 2761 my $blank = copy_spacing($opline);
2543 2762
2544 for (my $n = 0; $n < $#elements; $n += 2) { 2763 for (my $n = 0; $n < $#elements; $n += 2) {
2764
2765 my $good = $fix_elements[$n] . $fix_elements[$n + 1];
2766
2767## print("n: <$n> good: <$good>\n");
2768
2545 $off += length($elements[$n]); 2769 $off += length($elements[$n]);
2546 2770
2547 # Pick up the preceding and succeeding characters. 2771 # Pick up the preceding and succeeding characters.
@@ -2598,8 +2822,11 @@ sub process {
2598 } elsif ($op eq ';') { 2822 } elsif ($op eq ';') {
2599 if ($ctx !~ /.x[WEBC]/ && 2823 if ($ctx !~ /.x[WEBC]/ &&
2600 $cc !~ /^\\/ && $cc !~ /^;/) { 2824 $cc !~ /^\\/ && $cc !~ /^;/) {
2601 ERROR("SPACING", 2825 if (ERROR("SPACING",
2602 "space required after that '$op' $at\n" . $hereptr); 2826 "space required after that '$op' $at\n" . $hereptr)) {
2827 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
2828 $line_fixed = 1;
2829 }
2603 } 2830 }
2604 2831
2605 # // is a comment 2832 # // is a comment
@@ -2610,15 +2837,24 @@ sub process {
2610 # : when part of a bitfield 2837 # : when part of a bitfield
2611 } elsif ($op eq '->' || $opv eq ':B') { 2838 } elsif ($op eq '->' || $opv eq ':B') {
2612 if ($ctx =~ /Wx.|.xW/) { 2839 if ($ctx =~ /Wx.|.xW/) {
2613 ERROR("SPACING", 2840 if (ERROR("SPACING",
2614 "spaces prohibited around that '$op' $at\n" . $hereptr); 2841 "spaces prohibited around that '$op' $at\n" . $hereptr)) {
2842 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2843 $line_fixed = 1;
2844 if (defined $fix_elements[$n + 2]) {
2845 $fix_elements[$n + 2] =~ s/^\s+//;
2846 }
2847 }
2615 } 2848 }
2616 2849
2617 # , must have a space on the right. 2850 # , must have a space on the right.
2618 } elsif ($op eq ',') { 2851 } elsif ($op eq ',') {
2619 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { 2852 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
2620 ERROR("SPACING", 2853 if (ERROR("SPACING",
2621 "space required after that '$op' $at\n" . $hereptr); 2854 "space required after that '$op' $at\n" . $hereptr)) {
2855 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]) . " ";
2856 $line_fixed = 1;
2857 }
2622 } 2858 }
2623 2859
2624 # '*' as part of a type definition -- reported already. 2860 # '*' as part of a type definition -- reported already.
@@ -2632,34 +2868,58 @@ sub process {
2632 $opv eq '*U' || $opv eq '-U' || 2868 $opv eq '*U' || $opv eq '-U' ||
2633 $opv eq '&U' || $opv eq '&&U') { 2869 $opv eq '&U' || $opv eq '&&U') {
2634 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { 2870 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
2635 ERROR("SPACING", 2871 if (ERROR("SPACING",
2636 "space required before that '$op' $at\n" . $hereptr); 2872 "space required before that '$op' $at\n" . $hereptr)) {
2873 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
2874 $line_fixed = 1;
2875 }
2637 } 2876 }
2638 if ($op eq '*' && $cc =~/\s*$Modifier\b/) { 2877 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
2639 # A unary '*' may be const 2878 # A unary '*' may be const
2640 2879
2641 } elsif ($ctx =~ /.xW/) { 2880 } elsif ($ctx =~ /.xW/) {
2642 ERROR("SPACING", 2881 if (ERROR("SPACING",
2643 "space prohibited after that '$op' $at\n" . $hereptr); 2882 "space prohibited after that '$op' $at\n" . $hereptr)) {
2883 $fixed_line =~ s/\s+$//;
2884 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2885 $line_fixed = 1;
2886 if (defined $fix_elements[$n + 2]) {
2887 $fix_elements[$n + 2] =~ s/^\s+//;
2888 }
2889 }
2644 } 2890 }
2645 2891
2646 # unary ++ and unary -- are allowed no space on one side. 2892 # unary ++ and unary -- are allowed no space on one side.
2647 } elsif ($op eq '++' or $op eq '--') { 2893 } elsif ($op eq '++' or $op eq '--') {
2648 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { 2894 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
2649 ERROR("SPACING", 2895 if (ERROR("SPACING",
2650 "space required one side of that '$op' $at\n" . $hereptr); 2896 "space required one side of that '$op' $at\n" . $hereptr)) {
2897 $fixed_line =~ s/\s+$//;
2898 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]) . " ";
2899 $line_fixed = 1;
2900 }
2651 } 2901 }
2652 if ($ctx =~ /Wx[BE]/ || 2902 if ($ctx =~ /Wx[BE]/ ||
2653 ($ctx =~ /Wx./ && $cc =~ /^;/)) { 2903 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
2654 ERROR("SPACING", 2904 if (ERROR("SPACING",
2655 "space prohibited before that '$op' $at\n" . $hereptr); 2905 "space prohibited before that '$op' $at\n" . $hereptr)) {
2906 $fixed_line =~ s/\s+$//;
2907 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2908 $line_fixed = 1;
2909 }
2656 } 2910 }
2657 if ($ctx =~ /ExW/) { 2911 if ($ctx =~ /ExW/) {
2658 ERROR("SPACING", 2912 if (ERROR("SPACING",
2659 "space prohibited after that '$op' $at\n" . $hereptr); 2913 "space prohibited after that '$op' $at\n" . $hereptr)) {
2914 $fixed_line =~ s/\s+$//;
2915 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2916 $line_fixed = 1;
2917 if (defined $fix_elements[$n + 2]) {
2918 $fix_elements[$n + 2] =~ s/^\s+//;
2919 }
2920 }
2660 } 2921 }
2661 2922
2662
2663 # << and >> may either have or not have spaces both sides 2923 # << and >> may either have or not have spaces both sides
2664 } elsif ($op eq '<<' or $op eq '>>' or 2924 } elsif ($op eq '<<' or $op eq '>>' or
2665 $op eq '&' or $op eq '^' or $op eq '|' or 2925 $op eq '&' or $op eq '^' or $op eq '|' or
@@ -2668,17 +2928,23 @@ sub process {
2668 $op eq '%') 2928 $op eq '%')
2669 { 2929 {
2670 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { 2930 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
2671 ERROR("SPACING", 2931 if (ERROR("SPACING",
2672 "need consistent spacing around '$op' $at\n" . 2932 "need consistent spacing around '$op' $at\n" . $hereptr)) {
2673 $hereptr); 2933 $fixed_line =~ s/\s+$//;
2934 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
2935 $line_fixed = 1;
2936 }
2674 } 2937 }
2675 2938
2676 # A colon needs no spaces before when it is 2939 # A colon needs no spaces before when it is
2677 # terminating a case value or a label. 2940 # terminating a case value or a label.
2678 } elsif ($opv eq ':C' || $opv eq ':L') { 2941 } elsif ($opv eq ':C' || $opv eq ':L') {
2679 if ($ctx =~ /Wx./) { 2942 if ($ctx =~ /Wx./) {
2680 ERROR("SPACING", 2943 if (ERROR("SPACING",
2681 "space prohibited before that '$op' $at\n" . $hereptr); 2944 "space prohibited before that '$op' $at\n" . $hereptr)) {
2945 $good = trim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
2946 $line_fixed = 1;
2947 }
2682 } 2948 }
2683 2949
2684 # All the others need spaces both sides. 2950 # All the others need spaces both sides.
@@ -2701,11 +2967,39 @@ sub process {
2701 } 2967 }
2702 2968
2703 if ($ok == 0) { 2969 if ($ok == 0) {
2704 ERROR("SPACING", 2970 if (ERROR("SPACING",
2705 "spaces required around that '$op' $at\n" . $hereptr); 2971 "spaces required around that '$op' $at\n" . $hereptr)) {
2972 $good = trim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
2973 $good = $fix_elements[$n] . " " . trim($fix_elements[$n + 1]) . " ";
2974 $line_fixed = 1;
2975 }
2706 } 2976 }
2707 } 2977 }
2708 $off += length($elements[$n + 1]); 2978 $off += length($elements[$n + 1]);
2979
2980## print("n: <$n> GOOD: <$good>\n");
2981
2982 $fixed_line = $fixed_line . $good;
2983 }
2984
2985 if (($#elements % 2) == 0) {
2986 $fixed_line = $fixed_line . $fix_elements[$#elements];
2987 }
2988
2989 if ($fix && $line_fixed && $fixed_line ne $fixed[$linenr - 1]) {
2990 $fixed[$linenr - 1] = $fixed_line;
2991 }
2992
2993
2994 }
2995
2996# check for whitespace before a non-naked semicolon
2997 if ($line =~ /^\+.*\S\s+;/) {
2998 if (WARN("SPACING",
2999 "space prohibited before semicolon\n" . $herecurr) &&
3000 $fix) {
3001 1 while $fixed[$linenr - 1] =~
3002 s/^(\+.*\S)\s+;/$1;/;
2709 } 3003 }
2710 } 3004 }
2711 3005
@@ -2734,10 +3028,22 @@ sub process {
2734#need space before brace following if, while, etc 3028#need space before brace following if, while, etc
2735 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || 3029 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
2736 $line =~ /do{/) { 3030 $line =~ /do{/) {
2737 ERROR("SPACING", 3031 if (ERROR("SPACING",
2738 "space required before the open brace '{'\n" . $herecurr); 3032 "space required before the open brace '{'\n" . $herecurr) &&
3033 $fix) {
3034 $fixed[$linenr - 1] =~
3035 s/^(\+.*(?:do|\))){/$1 {/;
3036 }
2739 } 3037 }
2740 3038
3039## # check for blank lines before declarations
3040## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
3041## $prevrawline =~ /^.\s*$/) {
3042## WARN("SPACING",
3043## "No blank lines before declarations\n" . $hereprev);
3044## }
3045##
3046
2741# closing brace should have a space following it when it has anything 3047# closing brace should have a space following it when it has anything
2742# on the line 3048# on the line
2743 if ($line =~ /}(?!(?:,|;|\)))\S/) { 3049 if ($line =~ /}(?!(?:,|;|\)))\S/) {
@@ -2747,32 +3053,52 @@ sub process {
2747 3053
2748# check spacing on square brackets 3054# check spacing on square brackets
2749 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { 3055 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
2750 ERROR("SPACING", 3056 if (ERROR("SPACING",
2751 "space prohibited after that open square bracket '['\n" . $herecurr); 3057 "space prohibited after that open square bracket '['\n" . $herecurr) &&
3058 $fix) {
3059 $fixed[$linenr - 1] =~
3060 s/\[\s+/\[/;
3061 }
2752 } 3062 }
2753 if ($line =~ /\s\]/) { 3063 if ($line =~ /\s\]/) {
2754 ERROR("SPACING", 3064 if (ERROR("SPACING",
2755 "space prohibited before that close square bracket ']'\n" . $herecurr); 3065 "space prohibited before that close square bracket ']'\n" . $herecurr) &&
3066 $fix) {
3067 $fixed[$linenr - 1] =~
3068 s/\s+\]/\]/;
3069 }
2756 } 3070 }
2757 3071
2758# check spacing on parentheses 3072# check spacing on parentheses
2759 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && 3073 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
2760 $line !~ /for\s*\(\s+;/) { 3074 $line !~ /for\s*\(\s+;/) {
2761 ERROR("SPACING", 3075 if (ERROR("SPACING",
2762 "space prohibited after that open parenthesis '('\n" . $herecurr); 3076 "space prohibited after that open parenthesis '('\n" . $herecurr) &&
3077 $fix) {
3078 $fixed[$linenr - 1] =~
3079 s/\(\s+/\(/;
3080 }
2763 } 3081 }
2764 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && 3082 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
2765 $line !~ /for\s*\(.*;\s+\)/ && 3083 $line !~ /for\s*\(.*;\s+\)/ &&
2766 $line !~ /:\s+\)/) { 3084 $line !~ /:\s+\)/) {
2767 ERROR("SPACING", 3085 if (ERROR("SPACING",
2768 "space prohibited before that close parenthesis ')'\n" . $herecurr); 3086 "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
3087 $fix) {
3088 $fixed[$linenr - 1] =~
3089 s/\s+\)/\)/;
3090 }
2769 } 3091 }
2770 3092
2771#goto labels aren't indented, allow a single space however 3093#goto labels aren't indented, allow a single space however
2772 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and 3094 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
2773 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { 3095 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
2774 WARN("INDENTED_LABEL", 3096 if (WARN("INDENTED_LABEL",
2775 "labels should not be indented\n" . $herecurr); 3097 "labels should not be indented\n" . $herecurr) &&
3098 $fix) {
3099 $fixed[$linenr - 1] =~
3100 s/^(.)\s+/$1/;
3101 }
2776 } 3102 }
2777 3103
2778# Return is not a function. 3104# Return is not a function.
@@ -2809,8 +3135,13 @@ sub process {
2809 } 3135 }
2810 3136
2811# Need a space before open parenthesis after if, while etc 3137# Need a space before open parenthesis after if, while etc
2812 if ($line=~/\b(if|while|for|switch)\(/) { 3138 if ($line =~ /\b(if|while|for|switch)\(/) {
2813 ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr); 3139 if (ERROR("SPACING",
3140 "space required before the open parenthesis '('\n" . $herecurr) &&
3141 $fix) {
3142 $fixed[$linenr - 1] =~
3143 s/\b(if|while|for|switch)\(/$1 \(/;
3144 }
2814 } 3145 }
2815 3146
2816# Check for illegal assignment in if conditional -- and check for trailing 3147# Check for illegal assignment in if conditional -- and check for trailing
@@ -2934,16 +3265,29 @@ sub process {
2934 } 3265 }
2935 } 3266 }
2936 3267
2937#CamelCase 3268#Specific variable tests
2938 while ($line =~ m{($Constant|$Lval)}g) { 3269 while ($line =~ m{($Constant|$Lval)}g) {
2939 my $var = $1; 3270 my $var = $1;
2940 if ($var !~ /$Constant/ && 3271
2941 $var =~ /[A-Z]\w*[a-z]|[a-z]\w*[A-Z]/ && 3272#gcc binary extension
2942 $var !~ /"^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && 3273 if ($var =~ /^$Binary$/) {
2943 !defined $camelcase{$var}) { 3274 WARN("GCC_BINARY_CONSTANT",
2944 $camelcase{$var} = 1; 3275 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr);
2945 WARN("CAMELCASE", 3276 }
2946 "Avoid CamelCase: <$var>\n" . $herecurr); 3277
3278#CamelCase
3279 if ($var !~ /^$Constant$/ &&
3280 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
3281#Ignore Page<foo> variants
3282 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
3283#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
3284 $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
3285 seed_camelcase_includes() if ($check);
3286 if (!defined $camelcase{$var}) {
3287 $camelcase{$var} = 1;
3288 CHK("CAMELCASE",
3289 "Avoid CamelCase: <$var>\n" . $herecurr);
3290 }
2947 } 3291 }
2948 } 3292 }
2949 3293
@@ -3021,7 +3365,7 @@ sub process {
3021 if ($dstat ne '' && 3365 if ($dstat ne '' &&
3022 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), 3366 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
3023 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo(); 3367 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
3024 $dstat !~ /^[!~-]?(?:$Ident|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo 3368 $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
3025 $dstat !~ /^'X'$/ && # character constants 3369 $dstat !~ /^'X'$/ && # character constants
3026 $dstat !~ /$exceptions/ && 3370 $dstat !~ /$exceptions/ &&
3027 $dstat !~ /^\.$Ident\s*=/ && # .foo = 3371 $dstat !~ /^\.$Ident\s*=/ && # .foo =
@@ -3230,11 +3574,11 @@ sub process {
3230 } 3574 }
3231 3575
3232# check for unnecessary blank lines around braces 3576# check for unnecessary blank lines around braces
3233 if (($line =~ /^.\s*}\s*$/ && $prevline =~ /^.\s*$/)) { 3577 if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
3234 CHK("BRACES", 3578 CHK("BRACES",
3235 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev); 3579 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev);
3236 } 3580 }
3237 if (($line =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) { 3581 if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
3238 CHK("BRACES", 3582 CHK("BRACES",
3239 "Blank lines aren't necessary after an open brace '{'\n" . $hereprev); 3583 "Blank lines aren't necessary after an open brace '{'\n" . $hereprev);
3240 } 3584 }
@@ -3279,6 +3623,18 @@ sub process {
3279 } 3623 }
3280 } 3624 }
3281 3625
3626# check for comparisons of jiffies
3627 if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
3628 WARN("JIFFIES_COMPARISON",
3629 "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
3630 }
3631
3632# check for comparisons of get_jiffies_64()
3633 if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
3634 WARN("JIFFIES_COMPARISON",
3635 "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
3636 }
3637
3282# warn about #ifdefs in C files 3638# warn about #ifdefs in C files
3283# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { 3639# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
3284# print "#ifdef in C files should be avoided\n"; 3640# print "#ifdef in C files should be avoided\n";
@@ -3288,8 +3644,13 @@ sub process {
3288 3644
3289# warn about spacing in #ifdefs 3645# warn about spacing in #ifdefs
3290 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { 3646 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
3291 ERROR("SPACING", 3647 if (ERROR("SPACING",
3292 "exactly one space required after that #$1\n" . $herecurr); 3648 "exactly one space required after that #$1\n" . $herecurr) &&
3649 $fix) {
3650 $fixed[$linenr - 1] =~
3651 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
3652 }
3653
3293 } 3654 }
3294 3655
3295# check for spinlock_t definitions without a comment. 3656# check for spinlock_t definitions without a comment.
@@ -3495,6 +3856,14 @@ sub process {
3495 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 3856 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
3496 } 3857 }
3497 3858
3859# alloc style
3860# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
3861 if ($^V && $^V ge 5.10.0 &&
3862 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
3863 CHK("ALLOC_SIZEOF_STRUCT",
3864 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
3865 }
3866
3498# check for krealloc arg reuse 3867# check for krealloc arg reuse
3499 if ($^V && $^V ge 5.10.0 && 3868 if ($^V && $^V ge 5.10.0 &&
3500 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { 3869 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) {
@@ -3540,6 +3909,33 @@ sub process {
3540 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr); 3909 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
3541 } 3910 }
3542 3911
3912# check for comparisons against true and false
3913 if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
3914 my $lead = $1;
3915 my $arg = $2;
3916 my $test = $3;
3917 my $otype = $4;
3918 my $trail = $5;
3919 my $op = "!";
3920
3921 ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
3922
3923 my $type = lc($otype);
3924 if ($type =~ /^(?:true|false)$/) {
3925 if (("$test" eq "==" && "$type" eq "true") ||
3926 ("$test" eq "!=" && "$type" eq "false")) {
3927 $op = "";
3928 }
3929
3930 CHK("BOOL_COMPARISON",
3931 "Using comparison to $otype is error prone\n" . $herecurr);
3932
3933## maybe suggesting a correct construct would better
3934## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
3935
3936 }
3937 }
3938
3543# check for semaphores initialized locked 3939# check for semaphores initialized locked
3544 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { 3940 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
3545 WARN("CONSIDER_COMPLETION", 3941 WARN("CONSIDER_COMPLETION",
@@ -3717,6 +4113,40 @@ sub process {
3717 print "\n\n"; 4113 print "\n\n";
3718 } 4114 }
3719 4115
4116 if ($clean == 0 && $fix && "@rawlines" ne "@fixed") {
4117 my $newfile = $filename . ".EXPERIMENTAL-checkpatch-fixes";
4118 my $linecount = 0;
4119 my $f;
4120
4121 open($f, '>', $newfile)
4122 or die "$P: Can't open $newfile for write\n";
4123 foreach my $fixed_line (@fixed) {
4124 $linecount++;
4125 if ($file) {
4126 if ($linecount > 3) {
4127 $fixed_line =~ s/^\+//;
4128 print $f $fixed_line. "\n";
4129 }
4130 } else {
4131 print $f $fixed_line . "\n";
4132 }
4133 }
4134 close($f);
4135
4136 if (!$quiet) {
4137 print << "EOM";
4138Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
4139
4140Do _NOT_ trust the results written to this file.
4141Do _NOT_ submit these changes without inspecting them for correctness.
4142
4143This EXPERIMENTAL file is simply a convenience to help rewrite patches.
4144No warranties, expressed or implied...
4145
4146EOM
4147 }
4148 }
4149
3720 if ($clean == 1 && $quiet == 0) { 4150 if ($clean == 1 && $quiet == 0) {
3721 print "$vname has no obvious style problems and is ready for submission.\n" 4151 print "$vname has no obvious style problems and is ready for submission.\n"
3722 } 4152 }
diff --git a/scripts/coccicheck b/scripts/coccicheck
index 06fcb3333247..bbf901afb606 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -1,17 +1,31 @@
1#!/bin/bash 1#!/bin/bash
2 2
3#
4# This script requires at least spatch
5# version 1.0.0-rc11.
6#
7
3SPATCH="`which ${SPATCH:=spatch}`" 8SPATCH="`which ${SPATCH:=spatch}`"
4 9
10trap kill_running SIGTERM SIGINT
11declare -a SPATCH_PID
12
5# The verbosity may be set by the environmental parameter V= 13# The verbosity may be set by the environmental parameter V=
6# as for example with 'make V=1 coccicheck' 14# as for example with 'make V=1 coccicheck'
7 15
8if [ -n "$V" -a "$V" != "0" ]; then 16if [ -n "$V" -a "$V" != "0" ]; then
9 VERBOSE=1 17 VERBOSE="$V"
10else 18else
11 VERBOSE=0 19 VERBOSE=0
12fi 20fi
13 21
14FLAGS="$SPFLAGS -very_quiet" 22if [ -z "$J" ]; then
23 NPROC=$(getconf _NPROCESSORS_ONLN)
24else
25 NPROC="$J"
26fi
27
28FLAGS="$SPFLAGS --very-quiet"
15 29
16# spatch only allows include directories with the syntax "-I include" 30# spatch only allows include directories with the syntax "-I include"
17# while gcc also allows "-Iinclude" and "-include include" 31# while gcc also allows "-Iinclude" and "-include include"
@@ -27,14 +41,14 @@ if [ "$C" = "1" -o "$C" = "2" ]; then
27else 41else
28 ONLINE=0 42 ONLINE=0
29 if [ "$KBUILD_EXTMOD" = "" ] ; then 43 if [ "$KBUILD_EXTMOD" = "" ] ; then
30 OPTIONS="-dir $srctree $COCCIINCLUDE" 44 OPTIONS="--dir $srctree $COCCIINCLUDE"
31 else 45 else
32 OPTIONS="-dir $KBUILD_EXTMOD $COCCIINCLUDE" 46 OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
33 fi 47 fi
34fi 48fi
35 49
36if [ "$KBUILD_EXTMOD" != "" ] ; then 50if [ "$KBUILD_EXTMOD" != "" ] ; then
37 OPTIONS="-patch $srctree $OPTIONS" 51 OPTIONS="--patch $srctree $OPTIONS"
38fi 52fi
39 53
40if [ ! -x "$SPATCH" ]; then 54if [ ! -x "$SPATCH" ]; then
@@ -44,13 +58,21 @@ fi
44 58
45if [ "$MODE" = "" ] ; then 59if [ "$MODE" = "" ] ; then
46 if [ "$ONLINE" = "0" ] ; then 60 if [ "$ONLINE" = "0" ] ; then
47 echo 'You have not explicitly specified the mode to use. Using default "chain" mode.' 61 echo 'You have not explicitly specified the mode to use. Using default "report" mode.'
48 echo 'All available modes will be tried (in that order): patch, report, context, org' 62 echo 'Available modes are the following: patch, report, context, org'
49 echo 'You can specify the mode with "make coccicheck MODE=<mode>"' 63 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
64 echo 'Note however that some modes are not implemented by some semantic patches.'
65 fi
66 MODE="report"
67fi
68
69if [ "$MODE" = "chain" ] ; then
70 if [ "$ONLINE" = "0" ] ; then
71 echo 'You have selected the "chain" mode.'
72 echo 'All available modes will be tried (in that order): patch, report, context, org'
50 fi 73 fi
51 MODE="chain"
52elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then 74elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
53 FLAGS="$FLAGS -no_show_diff" 75 FLAGS="$FLAGS --no-show-diff"
54fi 76fi
55 77
56if [ "$ONLINE" = "0" ] ; then 78if [ "$ONLINE" = "0" ] ; then
@@ -61,19 +83,35 @@ if [ "$ONLINE" = "0" ] ; then
61fi 83fi
62 84
63run_cmd() { 85run_cmd() {
86 local i
64 if [ $VERBOSE -ne 0 ] ; then 87 if [ $VERBOSE -ne 0 ] ; then
65 echo "Running: $@" 88 echo "Running ($NPROC in parallel): $@"
66 fi 89 fi
67 eval $@ 90 for i in $(seq 0 $(( NPROC - 1)) ); do
91 eval "$@ --max $NPROC --index $i &"
92 SPATCH_PID[$i]=$!
93 if [ $VERBOSE -eq 2 ] ; then
94 echo "${SPATCH_PID[$i]} running"
95 fi
96 done
97 wait
68} 98}
69 99
100kill_running() {
101 for i in $(seq $(( NPROC - 1 )) ); do
102 if [ $VERBOSE -eq 2 ] ; then
103 echo "Killing ${SPATCH_PID[$i]}"
104 fi
105 kill ${SPATCH_PID[$i]} 2>/dev/null
106 done
107}
70 108
71coccinelle () { 109coccinelle () {
72 COCCI="$1" 110 COCCI="$1"
73 111
74 OPT=`grep "Option" $COCCI | cut -d':' -f2` 112 OPT=`grep "Option" $COCCI | cut -d':' -f2`
75 113
76# The option '-parse_cocci' can be used to syntactically check the SmPL files. 114# The option '--parse-cocci' can be used to syntactically check the SmPL files.
77# 115#
78# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null 116# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
79 117
@@ -114,20 +152,20 @@ coccinelle () {
114 152
115 if [ "$MODE" = "chain" ] ; then 153 if [ "$MODE" = "chain" ] ; then
116 run_cmd $SPATCH -D patch \ 154 run_cmd $SPATCH -D patch \
117 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ 155 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || \
118 run_cmd $SPATCH -D report \ 156 run_cmd $SPATCH -D report \
119 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ 157 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || \
120 run_cmd $SPATCH -D context \ 158 run_cmd $SPATCH -D context \
121 $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ 159 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || \
122 run_cmd $SPATCH -D org \ 160 run_cmd $SPATCH -D org \
123 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 161 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit 1
124 elif [ "$MODE" = "rep+ctxt" ] ; then 162 elif [ "$MODE" = "rep+ctxt" ] ; then
125 run_cmd $SPATCH -D report \ 163 run_cmd $SPATCH -D report \
126 $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ 164 $FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
127 run_cmd $SPATCH -D context \ 165 run_cmd $SPATCH -D context \
128 $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 166 $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
129 else 167 else
130 run_cmd $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 168 run_cmd $SPATCH -D $MODE $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
131 fi 169 fi
132 170
133} 171}
diff --git a/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci b/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci
index 7d4771d449c3..bd5d08b882ee 100644
--- a/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci
+++ b/scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci
@@ -5,7 +5,7 @@
5// Confidence: High 5// Confidence: High
6// Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2. 6// Copyright: 2009,2010 Nicolas Palix, DIKU. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Options: -no_includes -include_headers 8// Options: --no-includes --include-headers
9// 9//
10// Keywords: kmalloc, kzalloc, kcalloc 10// Keywords: kmalloc, kzalloc, kcalloc
11// Version min: < 2.6.12 kmalloc 11// Version min: < 2.6.12 kmalloc
diff --git a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
index 046b9b16f8f9..52c55e4fa67d 100644
--- a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
+++ b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci
@@ -9,7 +9,7 @@
9// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2. 9// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2.
10// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/rules/kzalloc.html 11// URL: http://coccinelle.lip6.fr/rules/kzalloc.html
12// Options: -no_includes -include_headers 12// Options: --no-includes --include-headers
13// 13//
14// Keywords: kmalloc, kzalloc 14// Keywords: kmalloc, kzalloc
15// Version min: < 2.6.12 kmalloc 15// Version min: < 2.6.12 kmalloc
diff --git a/scripts/coccinelle/api/d_find_alias.cocci b/scripts/coccinelle/api/d_find_alias.cocci
index a9694a8d3e5a..9594c9f7eb8d 100644
--- a/scripts/coccinelle/api/d_find_alias.cocci
+++ b/scripts/coccinelle/api/d_find_alias.cocci
@@ -4,7 +4,7 @@
4// 4//
5// Confidence: Moderate 5// Confidence: Moderate
6// URL: http://coccinelle.lip6.fr/ 6// URL: http://coccinelle.lip6.fr/
7// Options: -include_headers 7// Options: --include-headers
8 8
9virtual context 9virtual context
10virtual org 10virtual org
diff --git a/scripts/coccinelle/api/devm_request_and_ioremap.cocci b/scripts/coccinelle/api/devm_request_and_ioremap.cocci
index 46beb81406ab..562ec88b6352 100644
--- a/scripts/coccinelle/api/devm_request_and_ioremap.cocci
+++ b/scripts/coccinelle/api/devm_request_and_ioremap.cocci
@@ -10,7 +10,7 @@
10// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/ 11// URL: http://coccinelle.lip6.fr/
12// Comments: 12// Comments:
13// Options: -no_includes -include_headers 13// Options: --no-includes --include-headers
14 14
15virtual patch 15virtual patch
16virtual org 16virtual org
diff --git a/scripts/coccinelle/api/kstrdup.cocci b/scripts/coccinelle/api/kstrdup.cocci
index 07a74b2c6196..09cba54ed0cf 100644
--- a/scripts/coccinelle/api/kstrdup.cocci
+++ b/scripts/coccinelle/api/kstrdup.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual patch 11virtual patch
12virtual context 12virtual context
diff --git a/scripts/coccinelle/api/memdup.cocci b/scripts/coccinelle/api/memdup.cocci
index 4dceab6d54de..3d1aa71b7579 100644
--- a/scripts/coccinelle/api/memdup.cocci
+++ b/scripts/coccinelle/api/memdup.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual patch 11virtual patch
12virtual context 12virtual context
diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci
index 2b131a8a1306..c606231b0e46 100644
--- a/scripts/coccinelle/api/memdup_user.cocci
+++ b/scripts/coccinelle/api/memdup_user.cocci
@@ -7,7 +7,7 @@
7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments: 9// Comments:
10// Options: -no_includes -include_headers 10// Options: --no-includes --include-headers
11 11
12virtual patch 12virtual patch
13virtual context 13virtual context
diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci
index 15f076fdecbe..2274638d005b 100644
--- a/scripts/coccinelle/api/ptr_ret.cocci
+++ b/scripts/coccinelle/api/ptr_ret.cocci
@@ -5,7 +5,7 @@
5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. 5// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Options: -no_includes -include_headers 8// Options: --no-includes --include-headers
9// 9//
10// Keywords: ERR_PTR, PTR_ERR, PTR_RET 10// Keywords: ERR_PTR, PTR_ERR, PTR_RET
11// Version min: 2.6.39 11// Version min: 2.6.39
diff --git a/scripts/coccinelle/api/simple_open.cocci b/scripts/coccinelle/api/simple_open.cocci
index 05962f7be155..b67e174f3d95 100644
--- a/scripts/coccinelle/api/simple_open.cocci
+++ b/scripts/coccinelle/api/simple_open.cocci
@@ -4,7 +4,7 @@
4/// 4///
5// Confidence: High 5// Confidence: High
6// Comments: 6// Comments:
7// Options: -no_includes -include_headers 7// Options: --no-includes --include-headers
8 8
9virtual patch 9virtual patch
10virtual report 10virtual report
diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci
index 0a1e36146d76..3d9349012bb3 100644
--- a/scripts/coccinelle/free/devm_free.cocci
+++ b/scripts/coccinelle/free/devm_free.cocci
@@ -18,7 +18,7 @@
18// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2. 18// Copyright: (C) 2011 Gilles Muller, INRIA/LiP6. GPLv2.
19// URL: http://coccinelle.lip6.fr/ 19// URL: http://coccinelle.lip6.fr/
20// Comments: 20// Comments:
21// Options: -no_includes -include_headers 21// Options: --no-includes --include-headers
22 22
23virtual org 23virtual org
24virtual report 24virtual report
diff --git a/scripts/coccinelle/free/kfree.cocci b/scripts/coccinelle/free/kfree.cocci
index d9ae6d89c2f5..577b78056990 100644
--- a/scripts/coccinelle/free/kfree.cocci
+++ b/scripts/coccinelle/free/kfree.cocci
@@ -10,7 +10,7 @@
10// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/ 11// URL: http://coccinelle.lip6.fr/
12// Comments: 12// Comments:
13// Options: -no_includes -include_headers 13// Options: --no-includes --include-headers
14 14
15virtual org 15virtual org
16virtual report 16virtual report
diff --git a/scripts/coccinelle/free/kfreeaddr.cocci b/scripts/coccinelle/free/kfreeaddr.cocci
new file mode 100644
index 000000000000..ce8aacc314cb
--- /dev/null
+++ b/scripts/coccinelle/free/kfreeaddr.cocci
@@ -0,0 +1,32 @@
1/// Free of a structure field
2///
3// Confidence: High
4// Copyright: (C) 2013 Julia Lawall, INRIA/LIP6. GPLv2.
5// URL: http://coccinelle.lip6.fr/
6// Comments:
7// Options: --no-includes --include-headers
8
9virtual org
10virtual report
11virtual context
12
13@r depends on context || report || org @
14expression e;
15identifier f;
16position p;
17@@
18
19* kfree@p(&e->f)
20
21@script:python depends on org@
22p << r.p;
23@@
24
25cocci.print_main("kfree",p)
26
27@script:python depends on report@
28p << r.p;
29@@
30
31msg = "ERROR: kfree of structure field"
32coccilib.report.print_report(p[0],msg)
diff --git a/scripts/coccinelle/free/pci_free_consistent.cocci b/scripts/coccinelle/free/pci_free_consistent.cocci
new file mode 100644
index 000000000000..43600ccb62a8
--- /dev/null
+++ b/scripts/coccinelle/free/pci_free_consistent.cocci
@@ -0,0 +1,52 @@
1/// Find missing pci_free_consistent for every pci_alloc_consistent.
2///
3// Confidence: Moderate
4// Copyright: (C) 2013 Petr Strnad. GPLv2.
5// URL: http://coccinelle.lip6.fr/
6// Keywords: pci_free_consistent, pci_alloc_consistent
7// Options: --no-includes --include-headers
8
9virtual report
10virtual org
11
12@search@
13local idexpression id;
14expression x,y,z,e;
15position p1,p2;
16type T;
17@@
18
19id = pci_alloc_consistent@p1(x,y,&z)
20... when != e = id
21if (id == NULL || ...) { ... return ...; }
22... when != pci_free_consistent(x,y,id,z)
23 when != if (id) { ... pci_free_consistent(x,y,id,z) ... }
24 when != if (y) { ... pci_free_consistent(x,y,id,z) ... }
25 when != e = (T)id
26 when exists
27(
28return 0;
29|
30return 1;
31|
32return id;
33|
34return@p2 ...;
35)
36
37@script:python depends on report@
38p1 << search.p1;
39p2 << search.p2;
40@@
41
42msg = "ERROR: missing pci_free_consistent; pci_alloc_consistent on line %s and return without freeing on line %s" % (p1[0].line,p2[0].line)
43coccilib.report.print_report(p2[0],msg)
44
45@script:python depends on org@
46p1 << search.p1;
47p2 << search.p2;
48@@
49
50msg = "ERROR: missing pci_free_consistent; pci_alloc_consistent on line %s and return without freeing on line %s" % (p1[0].line,p2[0].line)
51cocci.print_main(msg,p1)
52cocci.print_secs("",p2)
diff --git a/scripts/coccinelle/iterators/fen.cocci b/scripts/coccinelle/iterators/fen.cocci
index 0a40af828c43..48c152f224e1 100644
--- a/scripts/coccinelle/iterators/fen.cocci
+++ b/scripts/coccinelle/iterators/fen.cocci
@@ -7,7 +7,7 @@
7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 7// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments: 9// Comments:
10// Options: -no_includes -include_headers 10// Options: --no-includes --include-headers
11 11
12virtual patch 12virtual patch
13virtual context 13virtual context
diff --git a/scripts/coccinelle/iterators/itnull.cocci b/scripts/coccinelle/iterators/itnull.cocci
index 259899f6838e..f58732b56a40 100644
--- a/scripts/coccinelle/iterators/itnull.cocci
+++ b/scripts/coccinelle/iterators/itnull.cocci
@@ -11,7 +11,7 @@
11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/ 12// URL: http://coccinelle.lip6.fr/
13// Comments: 13// Comments:
14// Options: -no_includes -include_headers 14// Options: --no-includes --include-headers
15 15
16virtual patch 16virtual patch
17virtual context 17virtual context
diff --git a/scripts/coccinelle/iterators/list_entry_update.cocci b/scripts/coccinelle/iterators/list_entry_update.cocci
index b2967475679b..873f444e7137 100644
--- a/scripts/coccinelle/iterators/list_entry_update.cocci
+++ b/scripts/coccinelle/iterators/list_entry_update.cocci
@@ -9,7 +9,7 @@
9// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 9// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
10// URL: http://coccinelle.lip6.fr/ 10// URL: http://coccinelle.lip6.fr/
11// Comments: 11// Comments:
12// Options: -no_includes -include_headers 12// Options: --no-includes --include-headers
13 13
14virtual context 14virtual context
15virtual org 15virtual org
diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci
index 06284c57a951..f085f5968c52 100644
--- a/scripts/coccinelle/iterators/use_after_iter.cocci
+++ b/scripts/coccinelle/iterators/use_after_iter.cocci
@@ -11,7 +11,7 @@
11// Copyright: (C) 2012 Gilles Muller, INRIA/LIP6. GPLv2. 11// Copyright: (C) 2012 Gilles Muller, INRIA/LIP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/ 12// URL: http://coccinelle.lip6.fr/
13// Comments: 13// Comments:
14// Options: -no_includes -include_headers 14// Options: --no-includes --include-headers
15 15
16virtual context 16virtual context
17virtual org 17virtual org
diff --git a/scripts/coccinelle/locks/call_kern.cocci b/scripts/coccinelle/locks/call_kern.cocci
index 8f10b49603c3..669b24436248 100644
--- a/scripts/coccinelle/locks/call_kern.cocci
+++ b/scripts/coccinelle/locks/call_kern.cocci
@@ -9,7 +9,7 @@
9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
10// URL: http://coccinelle.lip6.fr/ 10// URL: http://coccinelle.lip6.fr/
11// Comments: 11// Comments:
12// Options: -no_includes -include_headers 12// Options: --no-includes --include-headers
13 13
14virtual patch 14virtual patch
15virtual context 15virtual context
diff --git a/scripts/coccinelle/locks/double_lock.cocci b/scripts/coccinelle/locks/double_lock.cocci
index 63b24e682fad..002752f97dca 100644
--- a/scripts/coccinelle/locks/double_lock.cocci
+++ b/scripts/coccinelle/locks/double_lock.cocci
@@ -8,7 +8,7 @@
8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/ 9// URL: http://coccinelle.lip6.fr/
10// Comments: 10// Comments:
11// Options: -no_includes -include_headers 11// Options: --no-includes --include-headers
12 12
13virtual org 13virtual org
14virtual report 14virtual report
diff --git a/scripts/coccinelle/locks/flags.cocci b/scripts/coccinelle/locks/flags.cocci
index 1c4ffe6fd846..debd70e46267 100644
--- a/scripts/coccinelle/locks/flags.cocci
+++ b/scripts/coccinelle/locks/flags.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual context 11virtual context
12virtual org 12virtual org
diff --git a/scripts/coccinelle/locks/mini_lock.cocci b/scripts/coccinelle/locks/mini_lock.cocci
index 3267d7410bd5..47f649b0ea87 100644
--- a/scripts/coccinelle/locks/mini_lock.cocci
+++ b/scripts/coccinelle/locks/mini_lock.cocci
@@ -11,7 +11,7 @@
11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
12// URL: http://coccinelle.lip6.fr/ 12// URL: http://coccinelle.lip6.fr/
13// Comments: 13// Comments:
14// Options: -no_includes -include_headers 14// Options: --no-includes --include-headers
15 15
16virtual context 16virtual context
17virtual org 17virtual org
diff --git a/scripts/coccinelle/misc/boolinit.cocci b/scripts/coccinelle/misc/boolinit.cocci
index 97ce41ce8135..b9abed49cd95 100644
--- a/scripts/coccinelle/misc/boolinit.cocci
+++ b/scripts/coccinelle/misc/boolinit.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2. 6// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
7// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 7// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Options: -include_headers 9// Options: --include-headers
10 10
11virtual patch 11virtual patch
12virtual context 12virtual context
diff --git a/scripts/coccinelle/misc/cstptr.cocci b/scripts/coccinelle/misc/cstptr.cocci
index d42564484528..f0368b3d4563 100644
--- a/scripts/coccinelle/misc/cstptr.cocci
+++ b/scripts/coccinelle/misc/cstptr.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual org 11virtual org
12virtual report 12virtual report
diff --git a/scripts/coccinelle/misc/doubleinit.cocci b/scripts/coccinelle/misc/doubleinit.cocci
index cf74a00cf597..c0c3371d25e0 100644
--- a/scripts/coccinelle/misc/doubleinit.cocci
+++ b/scripts/coccinelle/misc/doubleinit.cocci
@@ -8,7 +8,7 @@
8// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 8// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/ 9// URL: http://coccinelle.lip6.fr/
10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise 10// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
11// Options: -no_includes -include_headers 11// Options: --no-includes --include-headers
12 12
13virtual org 13virtual org
14virtual report 14virtual report
diff --git a/scripts/coccinelle/misc/ifaddr.cocci b/scripts/coccinelle/misc/ifaddr.cocci
index 3e4089a77000..8aebd1875e75 100644
--- a/scripts/coccinelle/misc/ifaddr.cocci
+++ b/scripts/coccinelle/misc/ifaddr.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual org 11virtual org
12virtual report 12virtual report
diff --git a/scripts/coccinelle/misc/ifcol.cocci b/scripts/coccinelle/misc/ifcol.cocci
index b7ed91dbeb95..d0d00ef1f12a 100644
--- a/scripts/coccinelle/misc/ifcol.cocci
+++ b/scripts/coccinelle/misc/ifcol.cocci
@@ -13,7 +13,7 @@
13// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 13// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
14// URL: http://coccinelle.lip6.fr/ 14// URL: http://coccinelle.lip6.fr/
15// Comments: 15// Comments:
16// Options: -no_includes -include_headers 16// Options: --no-includes --include-headers
17 17
18virtual org 18virtual org
19virtual report 19virtual report
diff --git a/scripts/coccinelle/misc/noderef.cocci b/scripts/coccinelle/misc/noderef.cocci
index c1707214e602..80a831c91161 100644
--- a/scripts/coccinelle/misc/noderef.cocci
+++ b/scripts/coccinelle/misc/noderef.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual org 11virtual org
12virtual report 12virtual report
diff --git a/scripts/coccinelle/misc/orplus.cocci b/scripts/coccinelle/misc/orplus.cocci
index 4a28cef1484e..81fabf379390 100644
--- a/scripts/coccinelle/misc/orplus.cocci
+++ b/scripts/coccinelle/misc/orplus.cocci
@@ -7,7 +7,7 @@
7// Copyright: (C) 2013 Gilles Muller, INRIA/LIP6. GPLv2. 7// Copyright: (C) 2013 Gilles Muller, INRIA/LIP6. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments: 9// Comments:
10// Options: -no_includes -include_headers 10// Options: --no-includes --include-headers
11 11
12virtual org 12virtual org
13virtual report 13virtual report
diff --git a/scripts/coccinelle/misc/warn.cocci b/scripts/coccinelle/misc/warn.cocci
index fda8c3558e4f..d2e5b6cedb84 100644
--- a/scripts/coccinelle/misc/warn.cocci
+++ b/scripts/coccinelle/misc/warn.cocci
@@ -5,7 +5,7 @@
5// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2. 5// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
6// URL: http://coccinelle.lip6.fr/ 6// URL: http://coccinelle.lip6.fr/
7// Comments: 7// Comments:
8// Options: -no_includes -include_headers 8// Options: --no-includes --include-headers
9 9
10virtual patch 10virtual patch
11virtual context 11virtual context
diff --git a/scripts/coccinelle/null/eno.cocci b/scripts/coccinelle/null/eno.cocci
index ed961a1f7d11..9bd29aa83399 100644
--- a/scripts/coccinelle/null/eno.cocci
+++ b/scripts/coccinelle/null/eno.cocci
@@ -6,7 +6,7 @@
6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2. 6// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
7// URL: http://coccinelle.lip6.fr/ 7// URL: http://coccinelle.lip6.fr/
8// Comments: 8// Comments:
9// Options: -no_includes -include_headers 9// Options: --no-includes --include-headers
10 10
11virtual patch 11virtual patch
12virtual context 12virtual context
diff --git a/scripts/coccinelle/null/kmerr.cocci b/scripts/coccinelle/null/kmerr.cocci
index 949bf656c64c..5354a7903ccb 100644
--- a/scripts/coccinelle/null/kmerr.cocci
+++ b/scripts/coccinelle/null/kmerr.cocci
@@ -10,7 +10,7 @@
10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/ 11// URL: http://coccinelle.lip6.fr/
12// Comments: 12// Comments:
13// Options: -no_includes -include_headers 13// Options: --no-includes --include-headers
14 14
15virtual context 15virtual context
16virtual org 16virtual org
diff --git a/scripts/coccinelle/tests/doublebitand.cocci b/scripts/coccinelle/tests/doublebitand.cocci
index 9ba73d05a77e..72f1572aaec3 100644
--- a/scripts/coccinelle/tests/doublebitand.cocci
+++ b/scripts/coccinelle/tests/doublebitand.cocci
@@ -10,7 +10,7 @@
10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 10// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
11// URL: http://coccinelle.lip6.fr/ 11// URL: http://coccinelle.lip6.fr/
12// Comments: 12// Comments:
13// Options: -no_includes -include_headers 13// Options: --no-includes --include-headers
14 14
15virtual context 15virtual context
16virtual org 16virtual org
diff --git a/scripts/coccinelle/tests/doubletest.cocci b/scripts/coccinelle/tests/doubletest.cocci
index 13a2c0e8a4bf..78d74c22ca12 100644
--- a/scripts/coccinelle/tests/doubletest.cocci
+++ b/scripts/coccinelle/tests/doubletest.cocci
@@ -8,7 +8,7 @@
8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
9// URL: http://coccinelle.lip6.fr/ 9// URL: http://coccinelle.lip6.fr/
10// Comments: 10// Comments:
11// Options: -no_includes -include_headers 11// Options: --no-includes --include-headers
12 12
13virtual context 13virtual context
14virtual org 14virtual org
diff --git a/scripts/coccinelle/tests/odd_ptr_err.cocci b/scripts/coccinelle/tests/odd_ptr_err.cocci
index e8dd8a6b28a2..cfe0a35cf2dd 100644
--- a/scripts/coccinelle/tests/odd_ptr_err.cocci
+++ b/scripts/coccinelle/tests/odd_ptr_err.cocci
@@ -7,7 +7,7 @@
7// Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2. 7// Copyright: (C) 2012 Gilles Muller, INRIA. GPLv2.
8// URL: http://coccinelle.lip6.fr/ 8// URL: http://coccinelle.lip6.fr/
9// Comments: 9// Comments:
10// Options: -no_includes -include_headers 10// Options: --no-includes --include-headers
11 11
12virtual patch 12virtual patch
13virtual context 13virtual context
diff --git a/scripts/config b/scripts/config
index a65ecbbdd32a..567120a87c39 100755
--- a/scripts/config
+++ b/scripts/config
@@ -1,6 +1,8 @@
1#!/bin/bash 1#!/bin/bash
2# Manipulate options in a .config file from the command line 2# Manipulate options in a .config file from the command line
3 3
4myname=${0##*/}
5
4# If no prefix forced, use the default CONFIG_ 6# If no prefix forced, use the default CONFIG_
5CONFIG_="${CONFIG_-CONFIG_}" 7CONFIG_="${CONFIG_-CONFIG_}"
6 8
@@ -8,7 +10,7 @@ usage() {
8 cat >&2 <<EOL 10 cat >&2 <<EOL
9Manipulate options in a .config file from the command line. 11Manipulate options in a .config file from the command line.
10Usage: 12Usage:
11config options command ... 13$myname options command ...
12commands: 14commands:
13 --enable|-e option Enable option 15 --enable|-e option Enable option
14 --disable|-d option Disable option 16 --disable|-d option Disable option
@@ -33,14 +35,14 @@ options:
33 --file config-file .config file to change (default .config) 35 --file config-file .config file to change (default .config)
34 --keep-case|-k Keep next symbols' case (dont' upper-case it) 36 --keep-case|-k Keep next symbols' case (dont' upper-case it)
35 37
36config doesn't check the validity of the .config file. This is done at next 38$myname doesn't check the validity of the .config file. This is done at next
37make time. 39make time.
38 40
39By default, config will upper-case the given symbol. Use --keep-case to keep 41By default, $myname will upper-case the given symbol. Use --keep-case to keep
40the case of all following symbols unchanged. 42the case of all following symbols unchanged.
41 43
42config uses 'CONFIG_' as the default symbol prefix. Set the environment 44$myname uses 'CONFIG_' as the default symbol prefix. Set the environment
43variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" config ... 45variable CONFIG_ to the prefix to use. Eg.: CONFIG_="FOO_" $myname ...
44EOL 46EOL
45 exit 1 47 exit 1
46} 48}
diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
index 643764f53ea7..5de5660cb708 100644
--- a/scripts/headers_install.sh
+++ b/scripts/headers_install.sh
@@ -2,7 +2,7 @@
2 2
3if [ $# -lt 1 ] 3if [ $# -lt 1 ]
4then 4then
5 echo "Usage: headers_install.sh OUTDIR [FILES...] 5 echo "Usage: headers_install.sh OUTDIR SRCDIR [FILES...]
6 echo 6 echo
7 echo "Prepares kernel header files for use by user space, by removing" 7 echo "Prepares kernel header files for use by user space, by removing"
8 echo "all compiler.h definitions and #includes, removing any" 8 echo "all compiler.h definitions and #includes, removing any"
@@ -10,6 +10,7 @@ then
10 echo "asm/inline/volatile keywords." 10 echo "asm/inline/volatile keywords."
11 echo 11 echo
12 echo "OUTDIR: directory to write each userspace header FILE to." 12 echo "OUTDIR: directory to write each userspace header FILE to."
13 echo "SRCDIR: source directory where files are picked."
13 echo "FILES: list of header files to operate on." 14 echo "FILES: list of header files to operate on."
14 15
15 exit 1 16 exit 1
@@ -19,6 +20,8 @@ fi
19 20
20OUTDIR="$1" 21OUTDIR="$1"
21shift 22shift
23SRCDIR="$1"
24shift
22 25
23# Iterate through files listed on command line 26# Iterate through files listed on command line
24 27
@@ -34,7 +37,7 @@ do
34 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \ 37 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
35 -e 's/(^|[ \t(])(inline|asm|volatile)([ \t(]|$)/\1__\2__\3/g' \ 38 -e 's/(^|[ \t(])(inline|asm|volatile)([ \t(]|$)/\1__\2__\3/g' \
36 -e 's@#(ifndef|define|endif[ \t]*/[*])[ \t]*_UAPI@#\1 @' \ 39 -e 's@#(ifndef|define|endif[ \t]*/[*])[ \t]*_UAPI@#\1 @' \
37 "$i" > "$OUTDIR/$FILE.sed" || exit 1 40 "$SRCDIR/$i" > "$OUTDIR/$FILE.sed" || exit 1
38 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ "$OUTDIR/$FILE.sed" \ 41 scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ "$OUTDIR/$FILE.sed" \
39 > "$OUTDIR/$FILE" 42 > "$OUTDIR/$FILE"
40 [ $? -gt 1 ] && exit 1 43 [ $? -gt 1 ] && exit 1
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index bde5b95c8c19..d19944f9c3ac 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -527,11 +527,12 @@ int main(int ac, char **av)
527 seed_env = getenv("KCONFIG_SEED"); 527 seed_env = getenv("KCONFIG_SEED");
528 if( seed_env && *seed_env ) { 528 if( seed_env && *seed_env ) {
529 char *endp; 529 char *endp;
530 int tmp = (int)strtol(seed_env, &endp, 10); 530 int tmp = (int)strtol(seed_env, &endp, 0);
531 if (*endp == '\0') { 531 if (*endp == '\0') {
532 seed = tmp; 532 seed = tmp;
533 } 533 }
534 } 534 }
535 fprintf( stderr, "KCONFIG_SEED=0x%X\n", seed );
535 srand(seed); 536 srand(seed);
536 break; 537 break;
537 } 538 }
@@ -653,7 +654,8 @@ int main(int ac, char **av)
653 conf_set_all_new_symbols(def_default); 654 conf_set_all_new_symbols(def_default);
654 break; 655 break;
655 case randconfig: 656 case randconfig:
656 conf_set_all_new_symbols(def_random); 657 /* Really nothing to do in this loop */
658 while (conf_set_all_new_symbols(def_random)) ;
657 break; 659 break;
658 case defconfig: 660 case defconfig:
659 conf_set_all_new_symbols(def_default); 661 conf_set_all_new_symbols(def_default);
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 43eda40c3838..c55c227af463 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -1040,7 +1040,7 @@ void conf_set_changed_callback(void (*fn)(void))
1040 conf_changed_callback = fn; 1040 conf_changed_callback = fn;
1041} 1041}
1042 1042
1043static void randomize_choice_values(struct symbol *csym) 1043static bool randomize_choice_values(struct symbol *csym)
1044{ 1044{
1045 struct property *prop; 1045 struct property *prop;
1046 struct symbol *sym; 1046 struct symbol *sym;
@@ -1053,7 +1053,7 @@ static void randomize_choice_values(struct symbol *csym)
1053 * In both cases stop. 1053 * In both cases stop.
1054 */ 1054 */
1055 if (csym->curr.tri != yes) 1055 if (csym->curr.tri != yes)
1056 return; 1056 return false;
1057 1057
1058 prop = sym_get_choice_prop(csym); 1058 prop = sym_get_choice_prop(csym);
1059 1059
@@ -1077,13 +1077,18 @@ static void randomize_choice_values(struct symbol *csym)
1077 else { 1077 else {
1078 sym->def[S_DEF_USER].tri = no; 1078 sym->def[S_DEF_USER].tri = no;
1079 } 1079 }
1080 sym->flags |= SYMBOL_DEF_USER;
1081 /* clear VALID to get value calculated */
1082 sym->flags &= ~SYMBOL_VALID;
1080 } 1083 }
1081 csym->flags |= SYMBOL_DEF_USER; 1084 csym->flags |= SYMBOL_DEF_USER;
1082 /* clear VALID to get value calculated */ 1085 /* clear VALID to get value calculated */
1083 csym->flags &= ~(SYMBOL_VALID); 1086 csym->flags &= ~(SYMBOL_VALID);
1087
1088 return true;
1084} 1089}
1085 1090
1086static void set_all_choice_values(struct symbol *csym) 1091void set_all_choice_values(struct symbol *csym)
1087{ 1092{
1088 struct property *prop; 1093 struct property *prop;
1089 struct symbol *sym; 1094 struct symbol *sym;
@@ -1100,10 +1105,10 @@ static void set_all_choice_values(struct symbol *csym)
1100 } 1105 }
1101 csym->flags |= SYMBOL_DEF_USER; 1106 csym->flags |= SYMBOL_DEF_USER;
1102 /* clear VALID to get value calculated */ 1107 /* clear VALID to get value calculated */
1103 csym->flags &= ~(SYMBOL_VALID); 1108 csym->flags &= ~(SYMBOL_VALID | SYMBOL_NEED_SET_CHOICE_VALUES);
1104} 1109}
1105 1110
1106void conf_set_all_new_symbols(enum conf_def_mode mode) 1111bool conf_set_all_new_symbols(enum conf_def_mode mode)
1107{ 1112{
1108 struct symbol *sym, *csym; 1113 struct symbol *sym, *csym;
1109 int i, cnt, pby, pty, ptm; /* pby: probability of boolean = y 1114 int i, cnt, pby, pty, ptm; /* pby: probability of boolean = y
@@ -1151,6 +1156,7 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
1151 exit( 1 ); 1156 exit( 1 );
1152 } 1157 }
1153 } 1158 }
1159 bool has_changed = false;
1154 1160
1155 for_all_symbols(i, sym) { 1161 for_all_symbols(i, sym) {
1156 if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID)) 1162 if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
@@ -1158,6 +1164,7 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
1158 switch (sym_get_type(sym)) { 1164 switch (sym_get_type(sym)) {
1159 case S_BOOLEAN: 1165 case S_BOOLEAN:
1160 case S_TRISTATE: 1166 case S_TRISTATE:
1167 has_changed = true;
1161 switch (mode) { 1168 switch (mode) {
1162 case def_yes: 1169 case def_yes:
1163 sym->def[S_DEF_USER].tri = yes; 1170 sym->def[S_DEF_USER].tri = yes;
@@ -1202,14 +1209,26 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
1202 * selected in a choice block and we set it to yes, 1209 * selected in a choice block and we set it to yes,
1203 * and the rest to no. 1210 * and the rest to no.
1204 */ 1211 */
1212 if (mode != def_random) {
1213 for_all_symbols(i, csym) {
1214 if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
1215 sym_is_choice_value(csym))
1216 csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
1217 }
1218 }
1219
1205 for_all_symbols(i, csym) { 1220 for_all_symbols(i, csym) {
1206 if (sym_has_value(csym) || !sym_is_choice(csym)) 1221 if (sym_has_value(csym) || !sym_is_choice(csym))
1207 continue; 1222 continue;
1208 1223
1209 sym_calc_value(csym); 1224 sym_calc_value(csym);
1210 if (mode == def_random) 1225 if (mode == def_random)
1211 randomize_choice_values(csym); 1226 has_changed = randomize_choice_values(csym);
1212 else 1227 else {
1213 set_all_choice_values(csym); 1228 set_all_choice_values(csym);
1229 has_changed = true;
1230 }
1214 } 1231 }
1232
1233 return has_changed;
1215} 1234}
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index cdd48600e02a..df198a5f4822 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -106,6 +106,9 @@ struct symbol {
106#define SYMBOL_DEF3 0x40000 /* symbol.def[S_DEF_3] is valid */ 106#define SYMBOL_DEF3 0x40000 /* symbol.def[S_DEF_3] is valid */
107#define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */ 107#define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */
108 108
109/* choice values need to be set before calculating this symbol value */
110#define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000
111
109#define SYMBOL_MAXLENGTH 256 112#define SYMBOL_MAXLENGTH 256
110#define SYMBOL_HASHSIZE 9973 113#define SYMBOL_HASHSIZE 9973
111 114
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index f8aee5fc6d5e..09f4edfdc911 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -86,7 +86,8 @@ const char *conf_get_autoconfig_name(void);
86char *conf_get_default_confname(void); 86char *conf_get_default_confname(void);
87void sym_set_change_count(int count); 87void sym_set_change_count(int count);
88void sym_add_change_count(int count); 88void sym_add_change_count(int count);
89void conf_set_all_new_symbols(enum conf_def_mode mode); 89bool conf_set_all_new_symbols(enum conf_def_mode mode);
90void set_all_choice_values(struct symbol *csym);
90 91
91struct conf_printer { 92struct conf_printer {
92 void (*print_symbol)(FILE *, struct symbol *, const char *, void *); 93 void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index ef1a7381f956..ecdb9659b67d 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -14,6 +14,7 @@ P(conf_set_message_callback, void,(void (*fn)(const char *fmt, va_list ap)));
14/* menu.c */ 14/* menu.c */
15P(rootmenu,struct menu,); 15P(rootmenu,struct menu,);
16 16
17P(menu_is_empty, bool, (struct menu *menu));
17P(menu_is_visible, bool, (struct menu *menu)); 18P(menu_is_visible, bool, (struct menu *menu));
18P(menu_has_prompt, bool, (struct menu *menu)); 19P(menu_has_prompt, bool, (struct menu *menu));
19P(menu_get_prompt,const char *,(struct menu *menu)); 20P(menu_get_prompt,const char *,(struct menu *menu));
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index a2eb80fbc896..3b15c08ec1fa 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -132,16 +132,16 @@ int dialog_checklist(const char *title, const char *prompt, int height,
132 } 132 }
133 133
134do_resize: 134do_resize:
135 if (getmaxy(stdscr) < (height + 6)) 135 if (getmaxy(stdscr) < (height + CHECKLIST_HEIGTH_MIN))
136 return -ERRDISPLAYTOOSMALL; 136 return -ERRDISPLAYTOOSMALL;
137 if (getmaxx(stdscr) < (width + 6)) 137 if (getmaxx(stdscr) < (width + CHECKLIST_WIDTH_MIN))
138 return -ERRDISPLAYTOOSMALL; 138 return -ERRDISPLAYTOOSMALL;
139 139
140 max_choice = MIN(list_height, item_count()); 140 max_choice = MIN(list_height, item_count());
141 141
142 /* center dialog box on screen */ 142 /* center dialog box on screen */
143 x = (COLS - width) / 2; 143 x = (getmaxx(stdscr) - width) / 2;
144 y = (LINES - height) / 2; 144 y = (getmaxy(stdscr) - height) / 2;
145 145
146 draw_shadow(stdscr, y, x, height, width); 146 draw_shadow(stdscr, y, x, height, width);
147 147
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index 1099337079b6..b4343d384926 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -200,6 +200,20 @@ int item_is_tag(char tag);
200int on_key_esc(WINDOW *win); 200int on_key_esc(WINDOW *win);
201int on_key_resize(void); 201int on_key_resize(void);
202 202
203/* minimum (re)size values */
204#define CHECKLIST_HEIGTH_MIN 6 /* For dialog_checklist() */
205#define CHECKLIST_WIDTH_MIN 6
206#define INPUTBOX_HEIGTH_MIN 2 /* For dialog_inputbox() */
207#define INPUTBOX_WIDTH_MIN 2
208#define MENUBOX_HEIGTH_MIN 15 /* For dialog_menu() */
209#define MENUBOX_WIDTH_MIN 65
210#define TEXTBOX_HEIGTH_MIN 8 /* For dialog_textbox() */
211#define TEXTBOX_WIDTH_MIN 8
212#define YESNO_HEIGTH_MIN 4 /* For dialog_yesno() */
213#define YESNO_WIDTH_MIN 4
214#define WINDOW_HEIGTH_MIN 19 /* For init_dialog() */
215#define WINDOW_WIDTH_MIN 80
216
203int init_dialog(const char *backtitle); 217int init_dialog(const char *backtitle);
204void set_dialog_backtitle(const char *backtitle); 218void set_dialog_backtitle(const char *backtitle);
205void set_dialog_subtitles(struct subtitle_list *subtitles); 219void set_dialog_subtitles(struct subtitle_list *subtitles);
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 21404a04d7c3..447a582198c9 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -56,14 +56,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
56 strcpy(instr, init); 56 strcpy(instr, init);
57 57
58do_resize: 58do_resize:
59 if (getmaxy(stdscr) <= (height - 2)) 59 if (getmaxy(stdscr) <= (height - INPUTBOX_HEIGTH_MIN))
60 return -ERRDISPLAYTOOSMALL; 60 return -ERRDISPLAYTOOSMALL;
61 if (getmaxx(stdscr) <= (width - 2)) 61 if (getmaxx(stdscr) <= (width - INPUTBOX_WIDTH_MIN))
62 return -ERRDISPLAYTOOSMALL; 62 return -ERRDISPLAYTOOSMALL;
63 63
64 /* center dialog box on screen */ 64 /* center dialog box on screen */
65 x = (COLS - width) / 2; 65 x = (getmaxx(stdscr) - width) / 2;
66 y = (LINES - height) / 2; 66 y = (getmaxy(stdscr) - height) / 2;
67 67
68 draw_shadow(stdscr, y, x, height, width); 68 draw_shadow(stdscr, y, x, height, width);
69 69
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 38cd69c5660e..c93de0b2faca 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -193,7 +193,7 @@ int dialog_menu(const char *title, const char *prompt,
193do_resize: 193do_resize:
194 height = getmaxy(stdscr); 194 height = getmaxy(stdscr);
195 width = getmaxx(stdscr); 195 width = getmaxx(stdscr);
196 if (height < 15 || width < 65) 196 if (height < MENUBOX_HEIGTH_MIN || width < MENUBOX_WIDTH_MIN)
197 return -ERRDISPLAYTOOSMALL; 197 return -ERRDISPLAYTOOSMALL;
198 198
199 height -= 4; 199 height -= 4;
@@ -203,8 +203,8 @@ do_resize:
203 max_choice = MIN(menu_height, item_count()); 203 max_choice = MIN(menu_height, item_count());
204 204
205 /* center dialog box on screen */ 205 /* center dialog box on screen */
206 x = (COLS - width) / 2; 206 x = (getmaxx(stdscr) - width) / 2;
207 y = (LINES - height) / 2; 207 y = (getmaxy(stdscr) - height) / 2;
208 208
209 draw_shadow(stdscr, y, x, height, width); 209 draw_shadow(stdscr, y, x, height, width);
210 210
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index a48bb93e0907..1773319b95e7 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -80,7 +80,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
80 80
81do_resize: 81do_resize:
82 getmaxyx(stdscr, height, width); 82 getmaxyx(stdscr, height, width);
83 if (height < 8 || width < 8) 83 if (height < TEXTBOX_HEIGTH_MIN || width < TEXTBOX_WIDTH_MIN)
84 return -ERRDISPLAYTOOSMALL; 84 return -ERRDISPLAYTOOSMALL;
85 if (initial_height != 0) 85 if (initial_height != 0)
86 height = initial_height; 86 height = initial_height;
@@ -98,8 +98,8 @@ do_resize:
98 width = 0; 98 width = 0;
99 99
100 /* center dialog box on screen */ 100 /* center dialog box on screen */
101 x = (COLS - width) / 2; 101 x = (getmaxx(stdscr) - width) / 2;
102 y = (LINES - height) / 2; 102 y = (getmaxy(stdscr) - height) / 2;
103 103
104 draw_shadow(stdscr, y, x, height, width); 104 draw_shadow(stdscr, y, x, height, width);
105 105
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index a0e97c299410..58a8289dd650 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -254,7 +254,12 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)
254 254
255void dialog_clear(void) 255void dialog_clear(void)
256{ 256{
257 attr_clear(stdscr, LINES, COLS, dlg.screen.atr); 257 int lines, columns;
258
259 lines = getmaxy(stdscr);
260 columns = getmaxx(stdscr);
261
262 attr_clear(stdscr, lines, columns, dlg.screen.atr);
258 /* Display background title if it exists ... - SLH */ 263 /* Display background title if it exists ... - SLH */
259 if (dlg.backtitle != NULL) { 264 if (dlg.backtitle != NULL) {
260 int i, len = 0, skip = 0; 265 int i, len = 0, skip = 0;
@@ -269,10 +274,10 @@ void dialog_clear(void)
269 } 274 }
270 275
271 wmove(stdscr, 1, 1); 276 wmove(stdscr, 1, 1);
272 if (len > COLS - 2) { 277 if (len > columns - 2) {
273 const char *ellipsis = "[...] "; 278 const char *ellipsis = "[...] ";
274 waddstr(stdscr, ellipsis); 279 waddstr(stdscr, ellipsis);
275 skip = len - (COLS - 2 - strlen(ellipsis)); 280 skip = len - (columns - 2 - strlen(ellipsis));
276 } 281 }
277 282
278 for (pos = dlg.subtitles; pos != NULL; pos = pos->next) { 283 for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
@@ -298,7 +303,7 @@ void dialog_clear(void)
298 skip--; 303 skip--;
299 } 304 }
300 305
301 for (i = len + 1; i < COLS - 1; i++) 306 for (i = len + 1; i < columns - 1; i++)
302 waddch(stdscr, ACS_HLINE); 307 waddch(stdscr, ACS_HLINE);
303 } 308 }
304 wnoutrefresh(stdscr); 309 wnoutrefresh(stdscr);
@@ -317,7 +322,7 @@ int init_dialog(const char *backtitle)
317 getyx(stdscr, saved_y, saved_x); 322 getyx(stdscr, saved_y, saved_x);
318 323
319 getmaxyx(stdscr, height, width); 324 getmaxyx(stdscr, height, width);
320 if (height < 19 || width < 80) { 325 if (height < WINDOW_HEIGTH_MIN || width < WINDOW_WIDTH_MIN) {
321 endwin(); 326 endwin();
322 return -ERRDISPLAYTOOSMALL; 327 return -ERRDISPLAYTOOSMALL;
323 } 328 }
@@ -371,27 +376,19 @@ void print_title(WINDOW *dialog, const char *title, int width)
371/* 376/*
372 * Print a string of text in a window, automatically wrap around to the 377 * Print a string of text in a window, automatically wrap around to the
373 * next line if the string is too long to fit on one line. Newline 378 * next line if the string is too long to fit on one line. Newline
374 * characters '\n' are replaced by spaces. We start on a new line 379 * characters '\n' are propperly processed. We start on a new line
375 * if there is no room for at least 4 nonblanks following a double-space. 380 * if there is no room for at least 4 nonblanks following a double-space.
376 */ 381 */
377void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x) 382void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
378{ 383{
379 int newl, cur_x, cur_y; 384 int newl, cur_x, cur_y;
380 int i, prompt_len, room, wlen; 385 int prompt_len, room, wlen;
381 char tempstr[MAX_LEN + 1], *word, *sp, *sp2; 386 char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0;
382 387
383 strcpy(tempstr, prompt); 388 strcpy(tempstr, prompt);
384 389
385 prompt_len = strlen(tempstr); 390 prompt_len = strlen(tempstr);
386 391
387 /*
388 * Remove newlines
389 */
390 for (i = 0; i < prompt_len; i++) {
391 if (tempstr[i] == '\n')
392 tempstr[i] = ' ';
393 }
394
395 if (prompt_len <= width - x * 2) { /* If prompt is short */ 392 if (prompt_len <= width - x * 2) { /* If prompt is short */
396 wmove(win, y, (width - prompt_len) / 2); 393 wmove(win, y, (width - prompt_len) / 2);
397 waddstr(win, tempstr); 394 waddstr(win, tempstr);
@@ -401,7 +398,10 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
401 newl = 1; 398 newl = 1;
402 word = tempstr; 399 word = tempstr;
403 while (word && *word) { 400 while (word && *word) {
404 sp = strchr(word, ' '); 401 sp = strpbrk(word, "\n ");
402 if (sp && *sp == '\n')
403 newline_separator = sp;
404
405 if (sp) 405 if (sp)
406 *sp++ = 0; 406 *sp++ = 0;
407 407
@@ -413,7 +413,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
413 if (wlen > room || 413 if (wlen > room ||
414 (newl && wlen < 4 && sp 414 (newl && wlen < 4 && sp
415 && wlen + 1 + strlen(sp) > room 415 && wlen + 1 + strlen(sp) > room
416 && (!(sp2 = strchr(sp, ' ')) 416 && (!(sp2 = strpbrk(sp, "\n "))
417 || wlen + 1 + (sp2 - sp) > room))) { 417 || wlen + 1 + (sp2 - sp) > room))) {
418 cur_y++; 418 cur_y++;
419 cur_x = x; 419 cur_x = x;
@@ -421,7 +421,15 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
421 wmove(win, cur_y, cur_x); 421 wmove(win, cur_y, cur_x);
422 waddstr(win, word); 422 waddstr(win, word);
423 getyx(win, cur_y, cur_x); 423 getyx(win, cur_y, cur_x);
424 cur_x++; 424
425 /* Move to the next line if the word separator was a newline */
426 if (newline_separator) {
427 cur_y++;
428 cur_x = x;
429 newline_separator = 0;
430 } else
431 cur_x++;
432
425 if (sp && *sp == ' ') { 433 if (sp && *sp == ' ') {
426 cur_x++; /* double space */ 434 cur_x++; /* double space */
427 while (*++sp == ' ') ; 435 while (*++sp == ' ') ;
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index 4e6e8090c20b..676fb2f824a3 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -45,14 +45,14 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
45 WINDOW *dialog; 45 WINDOW *dialog;
46 46
47do_resize: 47do_resize:
48 if (getmaxy(stdscr) < (height + 4)) 48 if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN))
49 return -ERRDISPLAYTOOSMALL; 49 return -ERRDISPLAYTOOSMALL;
50 if (getmaxx(stdscr) < (width + 4)) 50 if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
51 return -ERRDISPLAYTOOSMALL; 51 return -ERRDISPLAYTOOSMALL;
52 52
53 /* center dialog box on screen */ 53 /* center dialog box on screen */
54 x = (COLS - width) / 2; 54 x = (getmaxx(stdscr) - width) / 2;
55 y = (LINES - height) / 2; 55 y = (getmaxy(stdscr) - height) / 2;
56 56
57 draw_shadow(stdscr, y, x, height, width); 57 draw_shadow(stdscr, y, x, height, width);
58 58
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index a69cbd78fb38..6c9c45f9fbba 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -48,7 +48,7 @@ static const char mconf_readme[] = N_(
48"----------\n" 48"----------\n"
49"o Use the Up/Down arrow keys (cursor keys) to highlight the item\n" 49"o Use the Up/Down arrow keys (cursor keys) to highlight the item\n"
50" you wish to change or submenu wish to select and press <Enter>.\n" 50" you wish to change or submenu wish to select and press <Enter>.\n"
51" Submenus are designated by \"--->\".\n" 51" Submenus are designated by \"--->\", empty ones by \"----\".\n"
52"\n" 52"\n"
53" Shortcut: Press the option's highlighted letter (hotkey).\n" 53" Shortcut: Press the option's highlighted letter (hotkey).\n"
54" Pressing a hotkey more than once will sequence\n" 54" Pressing a hotkey more than once will sequence\n"
@@ -176,7 +176,7 @@ static const char mconf_readme[] = N_(
176"\n"), 176"\n"),
177menu_instructions[] = N_( 177menu_instructions[] = N_(
178 "Arrow keys navigate the menu. " 178 "Arrow keys navigate the menu. "
179 "<Enter> selects submenus --->. " 179 "<Enter> selects submenus ---> (or empty submenus ----). "
180 "Highlighted letters are hotkeys. " 180 "Highlighted letters are hotkeys. "
181 "Pressing <Y> includes, <N> excludes, <M> modularizes features. " 181 "Pressing <Y> includes, <N> excludes, <M> modularizes features. "
182 "Press <Esc><Esc> to exit, <?> for Help, </> for Search. " 182 "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
@@ -401,7 +401,7 @@ static void search_conf(void)
401 struct subtitle_part stpart; 401 struct subtitle_part stpart;
402 402
403 title = str_new(); 403 title = str_new();
404 str_printf( &title, _("Enter %s (sub)string to search for " 404 str_printf( &title, _("Enter %s (sub)string or regexp to search for "
405 "(with or without \"%s\")"), CONFIG_, CONFIG_); 405 "(with or without \"%s\")"), CONFIG_, CONFIG_);
406 406
407again: 407again:
@@ -498,8 +498,9 @@ static void build_conf(struct menu *menu)
498 menu->data ? "-->" : "++>", 498 menu->data ? "-->" : "++>",
499 indent + 1, ' ', prompt); 499 indent + 1, ' ', prompt);
500 } else 500 } else
501 item_make(" %*c%s --->", indent + 1, ' ', prompt); 501 item_make(" %*c%s %s",
502 502 indent + 1, ' ', prompt,
503 menu_is_empty(menu) ? "----" : "--->");
503 item_set_tag('m'); 504 item_set_tag('m');
504 item_set_data(menu); 505 item_set_data(menu);
505 if (single_menu_mode && menu->data) 506 if (single_menu_mode && menu->data)
@@ -630,7 +631,7 @@ static void build_conf(struct menu *menu)
630 (sym_has_value(sym) || !sym_is_changable(sym)) ? 631 (sym_has_value(sym) || !sym_is_changable(sym)) ?
631 "" : _(" (NEW)")); 632 "" : _(" (NEW)"));
632 if (menu->prompt->type == P_MENU) { 633 if (menu->prompt->type == P_MENU) {
633 item_add_str(" --->"); 634 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
634 return; 635 return;
635 } 636 }
636 } 637 }
@@ -826,7 +827,9 @@ static void conf_choice(struct menu *menu)
826 dialog_clear(); 827 dialog_clear();
827 res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"), 828 res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
828 _(radiolist_instructions), 829 _(radiolist_instructions),
829 15, 70, 6); 830 MENUBOX_HEIGTH_MIN,
831 MENUBOX_WIDTH_MIN,
832 CHECKLIST_HEIGTH_MIN);
830 selected = item_activate_selected(); 833 selected = item_activate_selected();
831 switch (res) { 834 switch (res) {
832 case 0: 835 case 0:
@@ -957,8 +960,8 @@ static int handle_exit(void)
957 dialog_clear(); 960 dialog_clear();
958 if (conf_get_changed()) 961 if (conf_get_changed())
959 res = dialog_yesno(NULL, 962 res = dialog_yesno(NULL,
960 _("Do you wish to save your new configuration ?\n" 963 _("Do you wish to save your new configuration?\n"
961 "<ESC><ESC> to continue."), 964 "(Press <ESC><ESC> to continue kernel configuration.)"),
962 6, 60); 965 6, 60);
963 else 966 else
964 res = -1; 967 res = -1;
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index fd3f0180e08f..7e233a6ca64e 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -443,6 +443,22 @@ bool menu_has_prompt(struct menu *menu)
443 return true; 443 return true;
444} 444}
445 445
446/*
447 * Determine if a menu is empty.
448 * A menu is considered empty if it contains no or only
449 * invisible entries.
450 */
451bool menu_is_empty(struct menu *menu)
452{
453 struct menu *child;
454
455 for (child = menu->list; child; child = child->next) {
456 if (menu_is_visible(child))
457 return(false);
458 }
459 return(true);
460}
461
446bool menu_is_visible(struct menu *menu) 462bool menu_is_visible(struct menu *menu)
447{ 463{
448 struct menu *child; 464 struct menu *child;
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index dbf31edd22b2..7975d8d258c3 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -45,8 +45,8 @@ static const char nconf_global_help[] = N_(
45"<n> to remove it. You may press the <Space> key to cycle through the\n" 45"<n> to remove it. You may press the <Space> key to cycle through the\n"
46"available options.\n" 46"available options.\n"
47"\n" 47"\n"
48"A trailing \"--->\" designates a submenu.\n" 48"A trailing \"--->\" designates a submenu, a trailing \"----\" an\n"
49"\n" 49"empty submenu.\n"
50"\n" 50"\n"
51"Menu navigation keys\n" 51"Menu navigation keys\n"
52"----------------------------------------------------------------------\n" 52"----------------------------------------------------------------------\n"
@@ -131,7 +131,7 @@ static const char nconf_global_help[] = N_(
131"\n"), 131"\n"),
132menu_no_f_instructions[] = N_( 132menu_no_f_instructions[] = N_(
133"Legend: [*] built-in [ ] excluded <M> module < > module capable.\n" 133"Legend: [*] built-in [ ] excluded <M> module < > module capable.\n"
134"Submenus are designated by a trailing \"--->\".\n" 134"Submenus are designated by a trailing \"--->\", empty ones by \"----\".\n"
135"\n" 135"\n"
136"Use the following keys to navigate the menus:\n" 136"Use the following keys to navigate the menus:\n"
137"Move up or down with <Up> and <Down>.\n" 137"Move up or down with <Up> and <Down>.\n"
@@ -148,7 +148,7 @@ menu_no_f_instructions[] = N_(
148"For help related to the current menu entry press <?> or <h>.\n"), 148"For help related to the current menu entry press <?> or <h>.\n"),
149menu_instructions[] = N_( 149menu_instructions[] = N_(
150"Legend: [*] built-in [ ] excluded <M> module < > module capable.\n" 150"Legend: [*] built-in [ ] excluded <M> module < > module capable.\n"
151"Submenus are designated by a trailing \"--->\".\n" 151"Submenus are designated by a trailing \"--->\", empty ones by \"----\".\n"
152"\n" 152"\n"
153"Use the following keys to navigate the menus:\n" 153"Use the following keys to navigate the menus:\n"
154"Move up or down with <Up> or <Down>.\n" 154"Move up or down with <Up> or <Down>.\n"
@@ -365,15 +365,16 @@ static void print_function_line(void)
365 int i; 365 int i;
366 int offset = 1; 366 int offset = 1;
367 const int skip = 1; 367 const int skip = 1;
368 int lines = getmaxy(stdscr);
368 369
369 for (i = 0; i < function_keys_num; i++) { 370 for (i = 0; i < function_keys_num; i++) {
370 (void) wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]); 371 (void) wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]);
371 mvwprintw(main_window, LINES-3, offset, 372 mvwprintw(main_window, lines-3, offset,
372 "%s", 373 "%s",
373 function_keys[i].key_str); 374 function_keys[i].key_str);
374 (void) wattrset(main_window, attributes[FUNCTION_TEXT]); 375 (void) wattrset(main_window, attributes[FUNCTION_TEXT]);
375 offset += strlen(function_keys[i].key_str); 376 offset += strlen(function_keys[i].key_str);
376 mvwprintw(main_window, LINES-3, 377 mvwprintw(main_window, lines-3,
377 offset, "%s", 378 offset, "%s",
378 function_keys[i].func); 379 function_keys[i].func);
379 offset += strlen(function_keys[i].func) + skip; 380 offset += strlen(function_keys[i].func) + skip;
@@ -694,7 +695,7 @@ static void search_conf(void)
694 int dres; 695 int dres;
695 696
696 title = str_new(); 697 title = str_new();
697 str_printf( &title, _("Enter %s (sub)string to search for " 698 str_printf( &title, _("Enter %s (sub)string or regexp to search for "
698 "(with or without \"%s\")"), CONFIG_, CONFIG_); 699 "(with or without \"%s\")"), CONFIG_, CONFIG_);
699 700
700again: 701again:
@@ -759,9 +760,9 @@ static void build_conf(struct menu *menu)
759 indent + 1, ' ', prompt); 760 indent + 1, ' ', prompt);
760 } else 761 } else
761 item_make(menu, 'm', 762 item_make(menu, 'm',
762 " %*c%s --->", 763 " %*c%s %s",
763 indent + 1, 764 indent + 1, ' ', prompt,
764 ' ', prompt); 765 menu_is_empty(menu) ? "----" : "--->");
765 766
766 if (single_menu_mode && menu->data) 767 if (single_menu_mode && menu->data)
767 goto conf_childs; 768 goto conf_childs;
@@ -903,7 +904,7 @@ static void build_conf(struct menu *menu)
903 (sym_has_value(sym) || !sym_is_changable(sym)) ? 904 (sym_has_value(sym) || !sym_is_changable(sym)) ?
904 "" : _(" (NEW)")); 905 "" : _(" (NEW)"));
905 if (menu->prompt && menu->prompt->type == P_MENU) { 906 if (menu->prompt && menu->prompt->type == P_MENU) {
906 item_add_str(" --->"); 907 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
907 return; 908 return;
908 } 909 }
909 } 910 }
@@ -954,7 +955,7 @@ static void show_menu(const char *prompt, const char *instructions,
954 955
955 clear(); 956 clear();
956 (void) wattrset(main_window, attributes[NORMAL]); 957 (void) wattrset(main_window, attributes[NORMAL]);
957 print_in_middle(stdscr, 1, 0, COLS, 958 print_in_middle(stdscr, 1, 0, getmaxx(stdscr),
958 menu_backtitle, 959 menu_backtitle,
959 attributes[MAIN_HEADING]); 960 attributes[MAIN_HEADING]);
960 961
@@ -1455,14 +1456,18 @@ static void conf_save(void)
1455 1456
1456void setup_windows(void) 1457void setup_windows(void)
1457{ 1458{
1459 int lines, columns;
1460
1461 getmaxyx(stdscr, lines, columns);
1462
1458 if (main_window != NULL) 1463 if (main_window != NULL)
1459 delwin(main_window); 1464 delwin(main_window);
1460 1465
1461 /* set up the menu and menu window */ 1466 /* set up the menu and menu window */
1462 main_window = newwin(LINES-2, COLS-2, 2, 1); 1467 main_window = newwin(lines-2, columns-2, 2, 1);
1463 keypad(main_window, TRUE); 1468 keypad(main_window, TRUE);
1464 mwin_max_lines = LINES-7; 1469 mwin_max_lines = lines-7;
1465 mwin_max_cols = COLS-6; 1470 mwin_max_cols = columns-6;
1466 1471
1467 /* panels order is from bottom to top */ 1472 /* panels order is from bottom to top */
1468 new_panel(main_window); 1473 new_panel(main_window);
@@ -1470,6 +1475,7 @@ void setup_windows(void)
1470 1475
1471int main(int ac, char **av) 1476int main(int ac, char **av)
1472{ 1477{
1478 int lines, columns;
1473 char *mode; 1479 char *mode;
1474 1480
1475 setlocale(LC_ALL, ""); 1481 setlocale(LC_ALL, "");
@@ -1495,7 +1501,8 @@ int main(int ac, char **av)
1495 keypad(stdscr, TRUE); 1501 keypad(stdscr, TRUE);
1496 curs_set(0); 1502 curs_set(0);
1497 1503
1498 if (COLS < 75 || LINES < 20) { 1504 getmaxyx(stdscr, lines, columns);
1505 if (columns < 75 || lines < 20) {
1499 endwin(); 1506 endwin();
1500 printf("Your terminal should have at " 1507 printf("Your terminal should have at "
1501 "least 20 lines and 75 columns\n"); 1508 "least 20 lines and 75 columns\n");
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 9f8c44ecc703..8275f0e55106 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -276,8 +276,8 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
276 276
277 total_width = max(msg_width, btns_width); 277 total_width = max(msg_width, btns_width);
278 /* place dialog in middle of screen */ 278 /* place dialog in middle of screen */
279 y = (LINES-(msg_lines+4))/2; 279 y = (getmaxy(stdscr)-(msg_lines+4))/2;
280 x = (COLS-(total_width+4))/2; 280 x = (getmaxx(stdscr)-(total_width+4))/2;
281 281
282 282
283 /* create the windows */ 283 /* create the windows */
@@ -387,8 +387,8 @@ int dialog_inputbox(WINDOW *main_window,
387 prompt_width = max(prompt_width, strlen(title)); 387 prompt_width = max(prompt_width, strlen(title));
388 388
389 /* place dialog in middle of screen */ 389 /* place dialog in middle of screen */
390 y = (LINES-(prompt_lines+4))/2; 390 y = (getmaxy(stdscr)-(prompt_lines+4))/2;
391 x = (COLS-(prompt_width+4))/2; 391 x = (getmaxx(stdscr)-(prompt_width+4))/2;
392 392
393 strncpy(result, init, *result_len); 393 strncpy(result, init, *result_len);
394 394
@@ -545,7 +545,7 @@ void show_scroll_win(WINDOW *main_window,
545{ 545{
546 int res; 546 int res;
547 int total_lines = get_line_no(text); 547 int total_lines = get_line_no(text);
548 int x, y; 548 int x, y, lines, columns;
549 int start_x = 0, start_y = 0; 549 int start_x = 0, start_y = 0;
550 int text_lines = 0, text_cols = 0; 550 int text_lines = 0, text_cols = 0;
551 int total_cols = 0; 551 int total_cols = 0;
@@ -556,6 +556,8 @@ void show_scroll_win(WINDOW *main_window,
556 WINDOW *pad; 556 WINDOW *pad;
557 PANEL *panel; 557 PANEL *panel;
558 558
559 getmaxyx(stdscr, lines, columns);
560
559 /* find the widest line of msg: */ 561 /* find the widest line of msg: */
560 total_lines = get_line_no(text); 562 total_lines = get_line_no(text);
561 for (i = 0; i < total_lines; i++) { 563 for (i = 0; i < total_lines; i++) {
@@ -569,14 +571,14 @@ void show_scroll_win(WINDOW *main_window,
569 (void) wattrset(pad, attributes[SCROLLWIN_TEXT]); 571 (void) wattrset(pad, attributes[SCROLLWIN_TEXT]);
570 fill_window(pad, text); 572 fill_window(pad, text);
571 573
572 win_lines = min(total_lines+4, LINES-2); 574 win_lines = min(total_lines+4, lines-2);
573 win_cols = min(total_cols+2, COLS-2); 575 win_cols = min(total_cols+2, columns-2);
574 text_lines = max(win_lines-4, 0); 576 text_lines = max(win_lines-4, 0);
575 text_cols = max(win_cols-2, 0); 577 text_cols = max(win_cols-2, 0);
576 578
577 /* place window in middle of screen */ 579 /* place window in middle of screen */
578 y = (LINES-win_lines)/2; 580 y = (lines-win_lines)/2;
579 x = (COLS-win_cols)/2; 581 x = (columns-win_cols)/2;
580 582
581 win = newwin(win_lines, win_cols, y, x); 583 win = newwin(win_lines, win_cols, y, x);
582 keypad(win, TRUE); 584 keypad(win, TRUE);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index ecc5aa5f865d..d550300ec00c 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -136,7 +136,7 @@ static struct property *sym_get_range_prop(struct symbol *sym)
136 return NULL; 136 return NULL;
137} 137}
138 138
139static int sym_get_range_val(struct symbol *sym, int base) 139static long sym_get_range_val(struct symbol *sym, int base)
140{ 140{
141 sym_calc_value(sym); 141 sym_calc_value(sym);
142 switch (sym->type) { 142 switch (sym->type) {
@@ -155,7 +155,7 @@ static int sym_get_range_val(struct symbol *sym, int base)
155static void sym_validate_range(struct symbol *sym) 155static void sym_validate_range(struct symbol *sym)
156{ 156{
157 struct property *prop; 157 struct property *prop;
158 int base, val, val2; 158 long base, val, val2;
159 char str[64]; 159 char str[64];
160 160
161 switch (sym->type) { 161 switch (sym->type) {
@@ -179,9 +179,9 @@ static void sym_validate_range(struct symbol *sym)
179 return; 179 return;
180 } 180 }
181 if (sym->type == S_INT) 181 if (sym->type == S_INT)
182 sprintf(str, "%d", val2); 182 sprintf(str, "%ld", val2);
183 else 183 else
184 sprintf(str, "0x%x", val2); 184 sprintf(str, "0x%lx", val2);
185 sym->curr.val = strdup(str); 185 sym->curr.val = strdup(str);
186} 186}
187 187
@@ -300,6 +300,14 @@ void sym_calc_value(struct symbol *sym)
300 300
301 if (sym->flags & SYMBOL_VALID) 301 if (sym->flags & SYMBOL_VALID)
302 return; 302 return;
303
304 if (sym_is_choice_value(sym) &&
305 sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES) {
306 sym->flags &= ~SYMBOL_NEED_SET_CHOICE_VALUES;
307 prop = sym_get_choice_prop(sym);
308 sym_calc_value(prop_get_symbol(prop));
309 }
310
303 sym->flags |= SYMBOL_VALID; 311 sym->flags |= SYMBOL_VALID;
304 312
305 oldval = sym->curr; 313 oldval = sym->curr;
@@ -425,6 +433,9 @@ void sym_calc_value(struct symbol *sym)
425 433
426 if (sym->flags & SYMBOL_AUTO) 434 if (sym->flags & SYMBOL_AUTO)
427 sym->flags &= ~SYMBOL_WRITE; 435 sym->flags &= ~SYMBOL_WRITE;
436
437 if (sym->flags & SYMBOL_NEED_SET_CHOICE_VALUES)
438 set_all_choice_values(sym);
428} 439}
429 440
430void sym_clear_all_valid(void) 441void sym_clear_all_valid(void)
@@ -583,7 +594,7 @@ bool sym_string_valid(struct symbol *sym, const char *str)
583bool sym_string_within_range(struct symbol *sym, const char *str) 594bool sym_string_within_range(struct symbol *sym, const char *str)
584{ 595{
585 struct property *prop; 596 struct property *prop;
586 int val; 597 long val;
587 598
588 switch (sym->type) { 599 switch (sym->type) {
589 case S_STRING: 600 case S_STRING:
@@ -943,38 +954,98 @@ const char *sym_escape_string_value(const char *in)
943 return res; 954 return res;
944} 955}
945 956
957struct sym_match {
958 struct symbol *sym;
959 off_t so, eo;
960};
961
962/* Compare matched symbols as thus:
963 * - first, symbols that match exactly
964 * - then, alphabetical sort
965 */
966static int sym_rel_comp( const void *sym1, const void *sym2 )
967{
968 struct sym_match *s1 = *(struct sym_match **)sym1;
969 struct sym_match *s2 = *(struct sym_match **)sym2;
970 int l1, l2;
971
972 /* Exact match:
973 * - if matched length on symbol s1 is the length of that symbol,
974 * then this symbol should come first;
975 * - if matched length on symbol s2 is the length of that symbol,
976 * then this symbol should come first.
977 * Note: since the search can be a regexp, both symbols may match
978 * exactly; if this is the case, we can't decide which comes first,
979 * and we fallback to sorting alphabetically.
980 */
981 l1 = s1->eo - s1->so;
982 l2 = s2->eo - s2->so;
983 if (l1 == strlen(s1->sym->name) && l2 != strlen(s2->sym->name))
984 return -1;
985 if (l1 != strlen(s1->sym->name) && l2 == strlen(s2->sym->name))
986 return 1;
987
988 /* As a fallback, sort symbols alphabetically */
989 return strcmp(s1->sym->name, s2->sym->name);
990}
991
946struct symbol **sym_re_search(const char *pattern) 992struct symbol **sym_re_search(const char *pattern)
947{ 993{
948 struct symbol *sym, **sym_arr = NULL; 994 struct symbol *sym, **sym_arr = NULL;
995 struct sym_match **sym_match_arr = NULL;
949 int i, cnt, size; 996 int i, cnt, size;
950 regex_t re; 997 regex_t re;
998 regmatch_t match[1];
951 999
952 cnt = size = 0; 1000 cnt = size = 0;
953 /* Skip if empty */ 1001 /* Skip if empty */
954 if (strlen(pattern) == 0) 1002 if (strlen(pattern) == 0)
955 return NULL; 1003 return NULL;
956 if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE)) 1004 if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE))
957 return NULL; 1005 return NULL;
958 1006
959 for_all_symbols(i, sym) { 1007 for_all_symbols(i, sym) {
1008 struct sym_match *tmp_sym_match;
960 if (sym->flags & SYMBOL_CONST || !sym->name) 1009 if (sym->flags & SYMBOL_CONST || !sym->name)
961 continue; 1010 continue;
962 if (regexec(&re, sym->name, 0, NULL, 0)) 1011 if (regexec(&re, sym->name, 1, match, 0))
963 continue; 1012 continue;
964 if (cnt + 1 >= size) { 1013 if (cnt + 1 >= size) {
965 void *tmp = sym_arr; 1014 void *tmp;
966 size += 16; 1015 size += 16;
967 sym_arr = realloc(sym_arr, size * sizeof(struct symbol *)); 1016 tmp = realloc(sym_match_arr, size * sizeof(struct sym_match *));
968 if (!sym_arr) { 1017 if (!tmp) {
969 free(tmp); 1018 goto sym_re_search_free;
970 return NULL;
971 } 1019 }
1020 sym_match_arr = tmp;
972 } 1021 }
973 sym_calc_value(sym); 1022 sym_calc_value(sym);
974 sym_arr[cnt++] = sym; 1023 tmp_sym_match = (struct sym_match*)malloc(sizeof(struct sym_match));
1024 if (!tmp_sym_match)
1025 goto sym_re_search_free;
1026 tmp_sym_match->sym = sym;
1027 /* As regexec return 0, we know we have a match, so
1028 * we can use match[0].rm_[se]o without further checks
1029 */
1030 tmp_sym_match->so = match[0].rm_so;
1031 tmp_sym_match->eo = match[0].rm_eo;
1032 sym_match_arr[cnt++] = tmp_sym_match;
975 } 1033 }
976 if (sym_arr) 1034 if (sym_match_arr) {
1035 qsort(sym_match_arr, cnt, sizeof(struct sym_match*), sym_rel_comp);
1036 sym_arr = malloc((cnt+1) * sizeof(struct symbol));
1037 if (!sym_arr)
1038 goto sym_re_search_free;
1039 for (i = 0; i < cnt; i++)
1040 sym_arr[i] = sym_match_arr[i]->sym;
977 sym_arr[cnt] = NULL; 1041 sym_arr[cnt] = NULL;
1042 }
1043sym_re_search_free:
1044 if (sym_match_arr) {
1045 for (i = 0; i < cnt; i++)
1046 free(sym_match_arr[i]);
1047 free(sym_match_arr);
1048 }
978 regfree(&re); 1049 regfree(&re);
979 1050
980 return sym_arr; 1051 return sym_arr;
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index 75d59fcd48b8..c11212ff3510 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -15,8 +15,8 @@ endef
15quiet_cmd_offsets = GEN $@ 15quiet_cmd_offsets = GEN $@
16define cmd_offsets 16define cmd_offsets
17 (set -e; \ 17 (set -e; \
18 echo "#ifndef __DEVICEVTABLE_OFFSETS_H__"; \ 18 echo "#ifndef __DEVICETABLE_OFFSETS_H__"; \
19 echo "#define __DEVICEVTABLE_OFFSETS_H__"; \ 19 echo "#define __DEVICETABLE_OFFSETS_H__"; \
20 echo "/*"; \ 20 echo "/*"; \
21 echo " * DO NOT MODIFY."; \ 21 echo " * DO NOT MODIFY."; \
22 echo " *"; \ 22 echo " *"; \
@@ -29,15 +29,10 @@ define cmd_offsets
29 echo "#endif" ) > $@ 29 echo "#endif" ) > $@
30endef 30endef
31 31
32# We use internal kbuild rules to avoid the "is up to date" message from make 32$(obj)/$(devicetable-offsets-file): $(obj)/devicetable-offsets.s
33scripts/mod/devicetable-offsets.s: scripts/mod/devicetable-offsets.c FORCE 33 $(call if_changed,offsets)
34 $(Q)mkdir -p $(dir $@)
35 $(call if_changed_dep,cc_s_c)
36 34
37$(obj)/$(devicetable-offsets-file): scripts/mod/devicetable-offsets.s 35targets += $(devicetable-offsets-file) devicetable-offsets.s
38 $(call cmd,offsets)
39
40targets += $(devicetable-offsets-file)
41 36
42# dependencies on generated files need to be listed explicitly 37# dependencies on generated files need to be listed explicitly
43 38
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index e66d4d258e1a..bb5d115ca671 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -177,5 +177,11 @@ int main(void)
177 DEVID(mei_cl_device_id); 177 DEVID(mei_cl_device_id);
178 DEVID_FIELD(mei_cl_device_id, name); 178 DEVID_FIELD(mei_cl_device_id, name);
179 179
180 DEVID(rio_device_id);
181 DEVID_FIELD(rio_device_id, did);
182 DEVID_FIELD(rio_device_id, vid);
183 DEVID_FIELD(rio_device_id, asm_did);
184 DEVID_FIELD(rio_device_id, asm_vid);
185
180 return 0; 186 return 0;
181} 187}
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 45f9a3377dcd..23708636b05c 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -79,10 +79,12 @@ struct devtable **__start___devtable, **__stop___devtable;
79extern struct devtable *__start___devtable[], *__stop___devtable[]; 79extern struct devtable *__start___devtable[], *__stop___devtable[];
80#endif /* __MACH__ */ 80#endif /* __MACH__ */
81 81
82#if __GNUC__ == 3 && __GNUC_MINOR__ < 3 82#if !defined(__used)
83# define __used __attribute__((__unused__)) 83# if __GNUC__ == 3 && __GNUC_MINOR__ < 3
84#else 84# define __used __attribute__((__unused__))
85# define __used __attribute__((__used__)) 85# else
86# define __used __attribute__((__used__))
87# endif
86#endif 88#endif
87 89
88/* Define a variable f that holds the value of field f of struct devid 90/* Define a variable f that holds the value of field f of struct devid
@@ -1145,6 +1147,26 @@ static int do_mei_entry(const char *filename, void *symval,
1145} 1147}
1146ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry); 1148ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
1147 1149
1150/* Looks like: rapidio:vNdNavNadN */
1151static int do_rio_entry(const char *filename,
1152 void *symval, char *alias)
1153{
1154 DEF_FIELD(symval, rio_device_id, did);
1155 DEF_FIELD(symval, rio_device_id, vid);
1156 DEF_FIELD(symval, rio_device_id, asm_did);
1157 DEF_FIELD(symval, rio_device_id, asm_vid);
1158
1159 strcpy(alias, "rapidio:");
1160 ADD(alias, "v", vid != RIO_ANY_ID, vid);
1161 ADD(alias, "d", did != RIO_ANY_ID, did);
1162 ADD(alias, "av", asm_vid != RIO_ANY_ID, asm_vid);
1163 ADD(alias, "ad", asm_did != RIO_ANY_ID, asm_did);
1164
1165 add_wildcard(alias);
1166 return 1;
1167}
1168ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
1169
1148/* Does namelen bytes of name exactly match the symbol? */ 1170/* Does namelen bytes of name exactly match the symbol? */
1149static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1171static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1150{ 1172{
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index a4be8e112bb6..62164348ecf7 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -861,37 +861,34 @@ static void check_section(const char *modname, struct elf_info *elf,
861 861
862 862
863#define ALL_INIT_DATA_SECTIONS \ 863#define ALL_INIT_DATA_SECTIONS \
864 ".init.setup$", ".init.rodata$", \ 864 ".init.setup$", ".init.rodata$", ".meminit.rodata$", \
865 ".cpuinit.rodata$", ".meminit.rodata$", \ 865 ".init.data$", ".meminit.data$"
866 ".init.data$", ".cpuinit.data$", ".meminit.data$"
867#define ALL_EXIT_DATA_SECTIONS \ 866#define ALL_EXIT_DATA_SECTIONS \
868 ".exit.data$", ".cpuexit.data$", ".memexit.data$" 867 ".exit.data$", ".memexit.data$"
869 868
870#define ALL_INIT_TEXT_SECTIONS \ 869#define ALL_INIT_TEXT_SECTIONS \
871 ".init.text$", ".cpuinit.text$", ".meminit.text$" 870 ".init.text$", ".meminit.text$"
872#define ALL_EXIT_TEXT_SECTIONS \ 871#define ALL_EXIT_TEXT_SECTIONS \
873 ".exit.text$", ".cpuexit.text$", ".memexit.text$" 872 ".exit.text$", ".memexit.text$"
874 873
875#define ALL_PCI_INIT_SECTIONS \ 874#define ALL_PCI_INIT_SECTIONS \
876 ".pci_fixup_early$", ".pci_fixup_header$", ".pci_fixup_final$", \ 875 ".pci_fixup_early$", ".pci_fixup_header$", ".pci_fixup_final$", \
877 ".pci_fixup_enable$", ".pci_fixup_resume$", \ 876 ".pci_fixup_enable$", ".pci_fixup_resume$", \
878 ".pci_fixup_resume_early$", ".pci_fixup_suspend$" 877 ".pci_fixup_resume_early$", ".pci_fixup_suspend$"
879 878
880#define ALL_XXXINIT_SECTIONS CPU_INIT_SECTIONS, MEM_INIT_SECTIONS 879#define ALL_XXXINIT_SECTIONS MEM_INIT_SECTIONS
881#define ALL_XXXEXIT_SECTIONS CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS 880#define ALL_XXXEXIT_SECTIONS MEM_EXIT_SECTIONS
882 881
883#define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS 882#define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
884#define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS 883#define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS
885 884
886#define DATA_SECTIONS ".data$", ".data.rel$" 885#define DATA_SECTIONS ".data$", ".data.rel$"
887#define TEXT_SECTIONS ".text$" 886#define TEXT_SECTIONS ".text$", ".text.unlikely$"
888 887
889#define INIT_SECTIONS ".init.*" 888#define INIT_SECTIONS ".init.*"
890#define CPU_INIT_SECTIONS ".cpuinit.*"
891#define MEM_INIT_SECTIONS ".meminit.*" 889#define MEM_INIT_SECTIONS ".meminit.*"
892 890
893#define EXIT_SECTIONS ".exit.*" 891#define EXIT_SECTIONS ".exit.*"
894#define CPU_EXIT_SECTIONS ".cpuexit.*"
895#define MEM_EXIT_SECTIONS ".memexit.*" 892#define MEM_EXIT_SECTIONS ".memexit.*"
896 893
897/* init data sections */ 894/* init data sections */
@@ -979,48 +976,20 @@ const struct sectioncheck sectioncheck[] = {
979 .mismatch = DATA_TO_ANY_EXIT, 976 .mismatch = DATA_TO_ANY_EXIT,
980 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 977 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
981}, 978},
982/* Do not reference init code/data from cpuinit/meminit code/data */ 979/* Do not reference init code/data from meminit code/data */
983{ 980{
984 .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, 981 .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
985 .tosec = { INIT_SECTIONS, NULL }, 982 .tosec = { INIT_SECTIONS, NULL },
986 .mismatch = XXXINIT_TO_SOME_INIT, 983 .mismatch = XXXINIT_TO_SOME_INIT,
987 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 984 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
988}, 985},
989/* Do not reference cpuinit code/data from meminit code/data */ 986/* Do not reference exit code/data from memexit code/data */
990{
991 .fromsec = { MEM_INIT_SECTIONS, NULL },
992 .tosec = { CPU_INIT_SECTIONS, NULL },
993 .mismatch = XXXINIT_TO_SOME_INIT,
994 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
995},
996/* Do not reference meminit code/data from cpuinit code/data */
997{
998 .fromsec = { CPU_INIT_SECTIONS, NULL },
999 .tosec = { MEM_INIT_SECTIONS, NULL },
1000 .mismatch = XXXINIT_TO_SOME_INIT,
1001 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1002},
1003/* Do not reference exit code/data from cpuexit/memexit code/data */
1004{ 987{
1005 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL }, 988 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
1006 .tosec = { EXIT_SECTIONS, NULL }, 989 .tosec = { EXIT_SECTIONS, NULL },
1007 .mismatch = XXXEXIT_TO_SOME_EXIT, 990 .mismatch = XXXEXIT_TO_SOME_EXIT,
1008 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 991 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1009}, 992},
1010/* Do not reference cpuexit code/data from memexit code/data */
1011{
1012 .fromsec = { MEM_EXIT_SECTIONS, NULL },
1013 .tosec = { CPU_EXIT_SECTIONS, NULL },
1014 .mismatch = XXXEXIT_TO_SOME_EXIT,
1015 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1016},
1017/* Do not reference memexit code/data from cpuexit code/data */
1018{
1019 .fromsec = { CPU_EXIT_SECTIONS, NULL },
1020 .tosec = { MEM_EXIT_SECTIONS, NULL },
1021 .mismatch = XXXEXIT_TO_SOME_EXIT,
1022 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1023},
1024/* Do not use exit code/data from init code */ 993/* Do not use exit code/data from init code */
1025{ 994{
1026 .fromsec = { ALL_INIT_SECTIONS, NULL }, 995 .fromsec = { ALL_INIT_SECTIONS, NULL },
@@ -1089,8 +1058,6 @@ static const struct sectioncheck *section_mismatch(
1089 * Pattern 2: 1058 * Pattern 2:
1090 * Many drivers utilise a *driver container with references to 1059 * Many drivers utilise a *driver container with references to
1091 * add, remove, probe functions etc. 1060 * add, remove, probe functions etc.
1092 * These functions may often be marked __cpuinit and we do not want to
1093 * warn here.
1094 * the pattern is identified by: 1061 * the pattern is identified by:
1095 * tosec = init or exit section 1062 * tosec = init or exit section
1096 * fromsec = data section 1063 * fromsec = data section
@@ -1249,7 +1216,6 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1249/* 1216/*
1250 * Convert a section name to the function/data attribute 1217 * Convert a section name to the function/data attribute
1251 * .init.text => __init 1218 * .init.text => __init
1252 * .cpuinit.data => __cpudata
1253 * .memexitconst => __memconst 1219 * .memexitconst => __memconst
1254 * etc. 1220 * etc.
1255 * 1221 *
diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index fbbfd08853d3..fdd3fbf4d4a4 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -74,6 +74,7 @@ echo ""
74fi 74fi
75 75
76echo "%install" 76echo "%install"
77echo 'KBUILD_IMAGE=$(make image_name)'
77echo "%ifarch ia64" 78echo "%ifarch ia64"
78echo 'mkdir -p $RPM_BUILD_ROOT/boot/efi $RPM_BUILD_ROOT/lib/modules' 79echo 'mkdir -p $RPM_BUILD_ROOT/boot/efi $RPM_BUILD_ROOT/lib/modules'
79echo 'mkdir -p $RPM_BUILD_ROOT/lib/firmware' 80echo 'mkdir -p $RPM_BUILD_ROOT/lib/firmware'
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 84b88f109b80..d105a44b68f6 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -71,9 +71,6 @@ scm_version()
71 printf -- '-svn%s' "`git svn find-rev $head`" 71 printf -- '-svn%s' "`git svn find-rev $head`"
72 fi 72 fi
73 73
74 # Update index only on r/w media
75 [ -w . ] && git update-index --refresh --unmerged > /dev/null
76
77 # Check for uncommitted changes 74 # Check for uncommitted changes
78 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then 75 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
79 printf '%s' -dirty 76 printf '%s' -dirty
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index 1f10e89d15b4..f9ce1160419b 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -31,6 +31,10 @@
31#include <tools/be_byteshift.h> 31#include <tools/be_byteshift.h>
32#include <tools/le_byteshift.h> 32#include <tools/le_byteshift.h>
33 33
34#ifndef EM_AARCH64
35#define EM_AARCH64 183
36#endif
37
34static int fd_map; /* File descriptor for file being modified. */ 38static int fd_map; /* File descriptor for file being modified. */
35static int mmap_failed; /* Boolean flag. */ 39static int mmap_failed; /* Boolean flag. */
36static void *ehdr_curr; /* current ElfXX_Ehdr * for resource cleanup */ 40static void *ehdr_curr; /* current ElfXX_Ehdr * for resource cleanup */
@@ -249,6 +253,7 @@ do_file(char const *const fname)
249 custom_sort = sort_relative_table; 253 custom_sort = sort_relative_table;
250 break; 254 break;
251 case EM_ARM: 255 case EM_ARM:
256 case EM_AARCH64:
252 case EM_MIPS: 257 case EM_MIPS:
253 break; 258 break;
254 } /* end switch */ 259 } /* end switch */