aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/.gitignore2
-rw-r--r--scripts/Kbuild.include70
-rw-r--r--scripts/Makefile4
-rw-r--r--scripts/Makefile.asm-generic41
-rw-r--r--scripts/Makefile.build130
-rw-r--r--scripts/Makefile.gcc-plugins14
-rw-r--r--scripts/Makefile.headersinst8
-rw-r--r--scripts/Makefile.kasan53
-rw-r--r--scripts/Makefile.lib56
-rw-r--r--scripts/basic/fixdep.c31
-rwxr-xr-xscripts/bloat-o-meter1
-rwxr-xr-xscripts/checkpatch.pl49
-rwxr-xr-xscripts/checkstack.pl6
-rwxr-xr-xscripts/checksyscalls.sh1
-rw-r--r--scripts/coccinelle/api/alloc/alloc_cast.cocci8
-rw-r--r--scripts/coccinelle/api/alloc/zalloc-simple.cocci11
-rw-r--r--scripts/coccinelle/iterators/use_after_iter.cocci3
-rw-r--r--scripts/coccinelle/misc/boolinit.cocci44
-rwxr-xr-xscripts/decode_stacktrace.sh2
-rwxr-xr-xscripts/decodecode7
-rw-r--r--scripts/dtc/Makefile4
-rw-r--r--scripts/dtc/checks.c73
-rw-r--r--scripts/dtc/dtc-lexer.l4
-rw-r--r--scripts/dtc/dtc-parser.y52
-rw-r--r--scripts/dtc/dtc.c11
-rw-r--r--scripts/dtc/dtc.h11
-rw-r--r--scripts/dtc/flattree.c4
-rw-r--r--scripts/dtc/fstree.c5
-rw-r--r--scripts/dtc/libfdt/Makefile.libfdt4
-rw-r--r--scripts/dtc/libfdt/fdt_addresses.c16
-rw-r--r--scripts/dtc/libfdt/libfdt.h24
-rw-r--r--scripts/dtc/livetree.c33
-rw-r--r--scripts/dtc/srcpos.c153
-rw-r--r--scripts/dtc/srcpos.h14
-rw-r--r--scripts/dtc/treesource.c115
-rw-r--r--scripts/dtc/util.c60
-rw-r--r--scripts/dtc/util.h2
-rw-r--r--scripts/dtc/version_gen.h2
-rwxr-xr-xscripts/gcc-goto.sh2
-rw-r--r--scripts/gcc-plugins/Kconfig4
-rw-r--r--scripts/gcc-plugins/arm_ssp_per_task_plugin.c122
-rw-r--r--scripts/gcc-plugins/stackleak_plugin.c8
-rw-r--r--scripts/gdb/linux/proc.py2
-rwxr-xr-xscripts/gen_compile_commands.py151
-rwxr-xr-xscripts/gen_ksymdeps.sh25
-rw-r--r--scripts/kallsyms.c4
-rw-r--r--scripts/kconfig/.gitignore1
-rw-r--r--scripts/kconfig/Makefile65
-rw-r--r--scripts/kconfig/conf.c2
-rw-r--r--scripts/kconfig/confdata.c136
-rw-r--r--scripts/kconfig/expr.c18
-rw-r--r--scripts/kconfig/expr.h6
-rw-r--r--scripts/kconfig/gconf.c30
-rw-r--r--scripts/kconfig/images.c34
-rw-r--r--scripts/kconfig/images.h33
-rw-r--r--scripts/kconfig/kconf_id.c52
-rw-r--r--scripts/kconfig/lkc.h25
-rw-r--r--scripts/kconfig/lxdialog/checklist.c15
-rw-r--r--scripts/kconfig/lxdialog/dialog.h15
-rw-r--r--scripts/kconfig/lxdialog/inputbox.c15
-rw-r--r--scripts/kconfig/lxdialog/menubox.c15
-rw-r--r--scripts/kconfig/lxdialog/textbox.c15
-rw-r--r--scripts/kconfig/lxdialog/util.c15
-rw-r--r--scripts/kconfig/lxdialog/yesno.c15
-rw-r--r--scripts/kconfig/mconf.c2
-rw-r--r--scripts/kconfig/menu.c43
-rwxr-xr-xscripts/kconfig/merge_config.sh48
-rw-r--r--scripts/kconfig/nconf.c5
-rw-r--r--scripts/kconfig/nconf.gui.c5
-rw-r--r--scripts/kconfig/nconf.h5
-rw-r--r--scripts/kconfig/preprocess.c5
-rw-r--r--scripts/kconfig/qconf.cc4
-rw-r--r--scripts/kconfig/qconf.h2
-rwxr-xr-xscripts/kconfig/streamline_config.pl2
-rw-r--r--scripts/kconfig/symbol.c7
-rw-r--r--scripts/kconfig/tests/auto_submenu/Kconfig2
-rw-r--r--scripts/kconfig/tests/auto_submenu/__init__.py1
-rw-r--r--scripts/kconfig/tests/choice/Kconfig2
-rw-r--r--scripts/kconfig/tests/choice/__init__.py1
-rw-r--r--scripts/kconfig/tests/choice_value_with_m_dep/Kconfig2
-rw-r--r--scripts/kconfig/tests/choice_value_with_m_dep/__init__.py1
-rw-r--r--scripts/kconfig/tests/err_recursive_inc/__init__.py1
-rw-r--r--scripts/kconfig/tests/inter_choice/Kconfig2
-rw-r--r--scripts/kconfig/tests/inter_choice/__init__.py1
-rw-r--r--scripts/kconfig/tests/new_choice_with_dep/Kconfig2
-rw-r--r--scripts/kconfig/tests/new_choice_with_dep/__init__.py1
-rw-r--r--scripts/kconfig/tests/no_write_if_dep_unmet/Kconfig2
-rw-r--r--scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py1
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/Kconfig2
-rw-r--r--scripts/kconfig/tests/rand_nested_choice/__init__.py1
-rw-r--r--scripts/kconfig/util.c3
-rw-r--r--scripts/kconfig/zconf.l235
-rw-r--r--scripts/kconfig/zconf.y291
-rwxr-xr-xscripts/kernel-doc13
-rw-r--r--scripts/mod/Makefile2
-rw-r--r--scripts/mod/file2alias.c149
-rw-r--r--scripts/mod/modpost.c116
-rw-r--r--scripts/package/Makefile1
-rw-r--r--scripts/recordmcount.c2
-rwxr-xr-xscripts/recordmcount.pl13
-rw-r--r--scripts/selinux/genheaders/genheaders.c29
-rwxr-xr-xscripts/setlocalversion12
-rw-r--r--scripts/spdxcheck-test.sh12
-rwxr-xr-xscripts/spdxcheck.py6
-rwxr-xr-xscripts/tags.sh13
-rw-r--r--scripts/unifdef.c4
106 files changed, 1717 insertions, 1287 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 12d302d70128..17f8cef88fa8 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -6,9 +6,7 @@ conmakehash
6kallsyms 6kallsyms
7pnmtologo 7pnmtologo
8unifdef 8unifdef
9ihex2fw
10recordmcount 9recordmcount
11check-lc_ctype
12sortextable 10sortextable
13asn1_compiler 11asn1_compiler
14extract-cert 12extract-cert
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index bb015551c2d9..30816037036e 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -24,10 +24,6 @@ depfile = $(subst $(comma),_,$(dot-target).d)
24basetarget = $(basename $(notdir $@)) 24basetarget = $(basename $(notdir $@))
25 25
26### 26###
27# filename of first prerequisite with directory and extension stripped
28baseprereq = $(basename $(notdir $<))
29
30###
31# Escape single quote for use in echo statements 27# Escape single quote for use in echo statements
32escsq = $(subst $(squote),'\$(squote)',$1) 28escsq = $(subst $(squote),'\$(squote)',$1)
33 29
@@ -41,11 +37,11 @@ kecho := $($(quiet)kecho)
41### 37###
42# filechk is used to check if the content of a generated file is updated. 38# filechk is used to check if the content of a generated file is updated.
43# Sample usage: 39# Sample usage:
44# define filechk_sample 40#
45# echo $KERNELRELEASE 41# filechk_sample = echo $(KERNELRELEASE)
46# endef 42# version.h: FORCE
47# version.h : Makefile
48# $(call filechk,sample) 43# $(call filechk,sample)
44#
49# The rule defined shall write to stdout the content of the new file. 45# The rule defined shall write to stdout the content of the new file.
50# The existing file will be compared with the new one. 46# The existing file will be compared with the new one.
51# - If no file exist it is created 47# - If no file exist it is created
@@ -56,7 +52,7 @@ kecho := $($(quiet)kecho)
56define filechk 52define filechk
57 $(Q)set -e; \ 53 $(Q)set -e; \
58 mkdir -p $(dir $@); \ 54 mkdir -p $(dir $@); \
59 $(filechk_$(1)) > $@.tmp; \ 55 { $(filechk_$(1)); } > $@.tmp; \
60 if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 56 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
61 rm -f $@.tmp; \ 57 rm -f $@.tmp; \
62 else \ 58 else \
@@ -115,9 +111,7 @@ __cc-option = $(call try-run,\
115 111
116# Do not attempt to build with gcc plugins during cc-option tests. 112# Do not attempt to build with gcc plugins during cc-option tests.
117# (And this uses delayed resolution so the flags will be up to date.) 113# (And this uses delayed resolution so the flags will be up to date.)
118# In addition, do not include the asm macros which are built later. 114CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
119CC_OPTION_FILTERED = $(GCC_PLUGINS_CFLAGS) $(ASM_MACRO_FLAGS)
120CC_OPTION_CFLAGS = $(filter-out $(CC_OPTION_FILTERED),$(KBUILD_CFLAGS))
121 115
122# cc-option 116# cc-option
123# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 117# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
@@ -215,7 +209,7 @@ echo-cmd = $(if $($(quiet)cmd_$(1)),\
215 echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 209 echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
216 210
217# printing commands 211# printing commands
218cmd = @$(echo-cmd) $(cmd_$(1)) 212cmd = @set -e; $(echo-cmd) $(cmd_$(1))
219 213
220# Add $(obj)/ for paths that are not absolute 214# Add $(obj)/ for paths that are not absolute
221objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) 215objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
@@ -251,56 +245,21 @@ any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
251 245
252# Execute command if command has changed or prerequisite(s) are updated. 246# Execute command if command has changed or prerequisite(s) are updated.
253if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 247if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
254 @set -e; \ 248 $(cmd); \
255 $(echo-cmd) $(cmd_$(1)); \
256 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 249 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
257 250
258# Execute the command and also postprocess generated .d dependencies file. 251# Execute the command and also postprocess generated .d dependencies file.
259if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ 252if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)),$(cmd_and_fixdep),@:)
260 @set -e; \
261 $(cmd_and_fixdep), @:)
262
263ifndef CONFIG_TRIM_UNUSED_KSYMS
264 253
265cmd_and_fixdep = \ 254cmd_and_fixdep = \
266 $(echo-cmd) $(cmd_$(1)); \ 255 $(cmd); \
267 scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ 256 scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
268 rm -f $(depfile); \ 257 rm -f $(depfile)
269 mv -f $(dot-target).tmp $(dot-target).cmd;
270
271else
272
273# Filter out exported kernel symbol names from the preprocessor output.
274# See also __KSYM_DEPS__ in include/linux/export.h.
275# We disable the depfile generation here, so as not to overwrite the existing
276# depfile while fixdep is parsing it.
277flags_nodeps = $(filter-out -Wp$(comma)-M%, $($(1)))
278ksym_dep_filter = \
279 case "$(1)" in \
280 cc_*_c|cpp_i_c) \
281 $(CPP) $(call flags_nodeps,c_flags) -D__KSYM_DEPS__ $< ;; \
282 as_*_S|cpp_s_S) \
283 $(CPP) $(call flags_nodeps,a_flags) -D__KSYM_DEPS__ $< ;; \
284 boot*|build*|cpp_its_S|*cpp_lds_S|dtc|host*|vdso*) : ;; \
285 *) echo "Don't know how to preprocess $(1)" >&2; false ;; \
286 esac | tr ";" "\n" | sed -n 's/^.*=== __KSYM_\(.*\) ===.*$$/_\1/p'
287
288cmd_and_fixdep = \
289 $(echo-cmd) $(cmd_$(1)); \
290 $(ksym_dep_filter) | \
291 scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)' \
292 > $(dot-target).tmp; \
293 rm -f $(depfile); \
294 mv -f $(dot-target).tmp $(dot-target).cmd;
295
296endif
297 258
298# Usage: $(call if_changed_rule,foo) 259# Usage: $(call if_changed_rule,foo)
299# Will check if $(cmd_foo) or any of the prerequisites changed, 260# Will check if $(cmd_foo) or any of the prerequisites changed,
300# and if so will execute $(rule_foo). 261# and if so will execute $(rule_foo).
301if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ 262if_changed_rule = $(if $(strip $(any-prereq) $(arg-check)),$(rule_$(1)),@:)
302 @set -e; \
303 $(rule_$(1)), @:)
304 263
305### 264###
306# why - tell why a target got built 265# why - tell why a target got built
@@ -393,3 +352,6 @@ endef
393 352
394# delete partially updated (i.e. corrupted) files on error 353# delete partially updated (i.e. corrupted) files on error
395.DELETE_ON_ERROR: 354.DELETE_ON_ERROR:
355
356# do not delete intermediate files automatically
357.SECONDARY:
diff --git a/scripts/Makefile b/scripts/Makefile
index ece52ff20171..feb1f71381d7 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -36,10 +36,10 @@ PHONY += build_unifdef
36build_unifdef: $(obj)/unifdef 36build_unifdef: $(obj)/unifdef
37 @: 37 @:
38 38
39subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins
39subdir-$(CONFIG_MODVERSIONS) += genksyms 40subdir-$(CONFIG_MODVERSIONS) += genksyms
40subdir-y += mod
41subdir-$(CONFIG_SECURITY_SELINUX) += selinux 41subdir-$(CONFIG_SECURITY_SELINUX) += selinux
42subdir-$(CONFIG_GDB_SCRIPTS) += gdb 42subdir-$(CONFIG_GDB_SCRIPTS) += gdb
43 43
44# Let clean descend into subdirs 44# Let clean descend into subdirs
45subdir- += basic dtc kconfig package gcc-plugins 45subdir- += basic dtc kconfig mod package
diff --git a/scripts/Makefile.asm-generic b/scripts/Makefile.asm-generic
index 32ad8e93fbe1..a62d2823f6cf 100644
--- a/scripts/Makefile.asm-generic
+++ b/scripts/Makefile.asm-generic
@@ -2,41 +2,46 @@
2# include/asm-generic contains a lot of files that are used 2# include/asm-generic contains a lot of files that are used
3# verbatim by several architectures. 3# verbatim by several architectures.
4# 4#
5# This Makefile reads the file arch/$(SRCARCH)/include/$(src)/Kbuild 5# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
6# and for each file listed in this file with generic-y creates 6# and for each file listed in this file with generic-y creates
7# a small wrapper file in $(obj) (arch/$(SRCARCH)/include/generated/$(src)) 7# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
8 8
9PHONY := all 9PHONY := all
10all: 10all:
11 11
12kbuild-file := $(srctree)/arch/$(SRCARCH)/include/$(src)/Kbuild 12src := $(subst /generated,,$(obj))
13-include $(kbuild-file) 13-include $(src)/Kbuild
14 14
15include scripts/Kbuild.include 15include scripts/Kbuild.include
16 16
17# Create output directory if not already present 17# If arch does not implement mandatory headers, fallback to asm-generic ones.
18_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) 18mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
19generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
19 20
20# Stale wrappers when the corresponding files are removed from generic-y 21generic-y := $(addprefix $(obj)/, $(generic-y))
21# need removing. 22generated-y := $(addprefix $(obj)/, $(generated-y))
22generated-y := $(generic-y) $(generated-y) 23
23all-files := $(patsubst %, $(obj)/%, $(generated-y)) 24# Remove stale wrappers when the corresponding files are removed from generic-y
24old-headers := $(wildcard $(obj)/*.h) 25old-headers := $(wildcard $(obj)/*.h)
25unwanted := $(filter-out $(all-files),$(old-headers)) 26unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
26 27
27quiet_cmd_wrap = WRAP $@ 28quiet_cmd_wrap = WRAP $@
28cmd_wrap = echo "\#include <asm-generic/$*.h>" >$@ 29 cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
29 30
30quiet_cmd_remove = REMOVE $(unwanted) 31quiet_cmd_remove = REMOVE $(unwanted)
31cmd_remove = rm -f $(unwanted) 32 cmd_remove = rm -f $(unwanted)
32 33
33all: $(patsubst %, $(obj)/%, $(generic-y)) FORCE 34all: $(generic-y)
34 $(if $(unwanted),$(call cmd,remove),) 35 $(if $(unwanted),$(call cmd,remove))
35 @: 36 @:
36 37
37$(obj)/%.h: 38$(obj)/%.h:
38 $(call cmd,wrap) 39 $(call cmd,wrap)
39 40
40PHONY += FORCE 41# Create output directory. Skip it if at least one old header exists
42# since we know the output directory already exists.
43ifeq ($(old-headers),)
44$(shell mkdir -p $(obj))
45endif
46
41.PHONY: $(PHONY) 47.PHONY: $(PHONY)
42FORCE: ;
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a8e7ba9f73e8..fd03d60f6c5a 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -75,14 +75,14 @@ __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
75# Linus' kernel sanity checking tool 75# Linus' kernel sanity checking tool
76ifeq ($(KBUILD_CHECKSRC),1) 76ifeq ($(KBUILD_CHECKSRC),1)
77 quiet_cmd_checksrc = CHECK $< 77 quiet_cmd_checksrc = CHECK $<
78 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; 78 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
79else ifeq ($(KBUILD_CHECKSRC),2) 79else ifeq ($(KBUILD_CHECKSRC),2)
80 quiet_cmd_force_checksrc = CHECK $< 80 quiet_cmd_force_checksrc = CHECK $<
81 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; 81 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
82endif 82endif
83 83
84ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) 84ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
85 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< ; 85 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
86endif 86endif
87 87
88# Do section mismatch analysis for each module/built-in.a 88# Do section mismatch analysis for each module/built-in.a
@@ -94,23 +94,14 @@ endif
94# --------------------------------------------------------------------------- 94# ---------------------------------------------------------------------------
95 95
96# Default is built-in, unless we know otherwise 96# Default is built-in, unless we know otherwise
97$(foreach x, i ll lst o s symtypes, $(patsubst %.o,%.$(x),$(real-obj-m))): \
98 part-of-module := y
99
97modkern_cflags = \ 100modkern_cflags = \
98 $(if $(part-of-module), \ 101 $(if $(part-of-module), \
99 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ 102 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
100 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) 103 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
101quiet_modtag := $(empty) $(empty) 104quiet_modtag = $(if $(part-of-module),[M], )
102
103$(real-obj-m) : part-of-module := y
104$(real-obj-m:.o=.i) : part-of-module := y
105$(real-obj-m:.o=.s) : part-of-module := y
106$(real-obj-m:.o=.lst): part-of-module := y
107
108$(real-obj-m) : quiet_modtag := [M]
109$(real-obj-m:.o=.i) : quiet_modtag := [M]
110$(real-obj-m:.o=.s) : quiet_modtag := [M]
111$(real-obj-m:.o=.lst): quiet_modtag := [M]
112
113$(obj-m) : quiet_modtag := [M]
114 105
115quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ 106quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
116cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< 107cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
@@ -134,7 +125,6 @@ cmd_gensymtypes_c = \
134 125
135quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 126quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
136cmd_cc_symtypes_c = \ 127cmd_cc_symtypes_c = \
137 set -e; \
138 $(call cmd_gensymtypes_c,true,$@) >/dev/null; \ 128 $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
139 test -s $@ || rm -f $@ 129 test -s $@ || rm -f $@
140 130
@@ -154,36 +144,31 @@ $(obj)/%.ll: $(src)/%.c FORCE
154# (See cmd_cc_o_c + relevant part of rule_cc_o_c) 144# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
155 145
156quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ 146quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
147 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
157 148
158ifndef CONFIG_MODVERSIONS 149ifdef CONFIG_MODVERSIONS
159cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
160
161else
162# When module versioning is enabled the following steps are executed: 150# When module versioning is enabled the following steps are executed:
163# o compile a .tmp_<file>.o from <file>.c 151# o compile a <file>.o from <file>.c
164# o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does 152# o if <file>.o doesn't contain a __ksymtab version, i.e. does
165# not export symbols, we just rename .tmp_<file>.o to <file>.o and 153# not export symbols, it's done.
166# are done.
167# o otherwise, we calculate symbol versions using the good old 154# o otherwise, we calculate symbol versions using the good old
168# genksyms on the preprocessed source and postprocess them in a way 155# genksyms on the preprocessed source and postprocess them in a way
169# that they are usable as a linker script 156# that they are usable as a linker script
170# o generate <file>.o from .tmp_<file>.o using the linker to 157# o generate .tmp_<file>.o from <file>.o using the linker to
171# replace the unresolved symbols __crc_exported_symbol with 158# replace the unresolved symbols __crc_exported_symbol with
172# the actual value of the checksum generated by genksyms 159# the actual value of the checksum generated by genksyms
173 160# o remove .tmp_<file>.o to <file>.o
174cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
175 161
176cmd_modversions_c = \ 162cmd_modversions_c = \
177 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 163 if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
178 $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 164 $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
179 > $(@D)/.tmp_$(@F:.o=.ver); \ 165 > $(@D)/.tmp_$(@F:.o=.ver); \
180 \ 166 \
181 $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 167 $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
182 -T $(@D)/.tmp_$(@F:.o=.ver); \ 168 -T $(@D)/.tmp_$(@F:.o=.ver); \
183 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
184 else \
185 mv -f $(@D)/.tmp_$(@F) $@; \ 169 mv -f $(@D)/.tmp_$(@F) $@; \
186 fi; 170 rm -f $(@D)/.tmp_$(@F:.o=.ver); \
171 fi
187endif 172endif
188 173
189ifdef CONFIG_FTRACE_MCOUNT_RECORD 174ifdef CONFIG_FTRACE_MCOUNT_RECORD
@@ -204,7 +189,7 @@ sub_cmd_record_mcount = \
204recordmcount_source := $(srctree)/scripts/recordmcount.c \ 189recordmcount_source := $(srctree)/scripts/recordmcount.c \
205 $(srctree)/scripts/recordmcount.h 190 $(srctree)/scripts/recordmcount.h
206else 191else
207sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ 192sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
208 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ 193 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
209 "$(if $(CONFIG_64BIT),64,32)" \ 194 "$(if $(CONFIG_64BIT),64,32)" \
210 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \ 195 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
@@ -216,7 +201,7 @@ cmd_record_mcount = \
216 if [ "$(findstring $(CC_FLAGS_FTRACE),$(_c_flags))" = \ 201 if [ "$(findstring $(CC_FLAGS_FTRACE),$(_c_flags))" = \
217 "$(CC_FLAGS_FTRACE)" ]; then \ 202 "$(CC_FLAGS_FTRACE)" ]; then \
218 $(sub_cmd_record_mcount) \ 203 $(sub_cmd_record_mcount) \
219 fi; 204 fi
220endif # CC_USING_RECORD_MCOUNT 205endif # CC_USING_RECORD_MCOUNT
221endif # CONFIG_FTRACE_MCOUNT_RECORD 206endif # CONFIG_FTRACE_MCOUNT_RECORD
222 207
@@ -236,24 +221,15 @@ ifdef CONFIG_GCOV_KERNEL
236objtool_args += --no-unreachable 221objtool_args += --no-unreachable
237endif 222endif
238ifdef CONFIG_RETPOLINE 223ifdef CONFIG_RETPOLINE
239ifneq ($(RETPOLINE_CFLAGS),)
240 objtool_args += --retpoline 224 objtool_args += --retpoline
241endif 225endif
242endif
243
244
245ifdef CONFIG_MODVERSIONS
246objtool_o = $(@D)/.tmp_$(@F)
247else
248objtool_o = $(@)
249endif
250 226
251# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory 227# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
252# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file 228# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
253# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file 229# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
254cmd_objtool = $(if $(patsubst y%,, \ 230cmd_objtool = $(if $(patsubst y%,, \
255 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ 231 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
256 $(__objtool_obj) $(objtool_args) "$(objtool_o)";) 232 $(__objtool_obj) $(objtool_args) $@)
257objtool_obj = $(if $(patsubst y%,, \ 233objtool_obj = $(if $(patsubst y%,, \
258 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ 234 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
259 $(__objtool_obj)) 235 $(__objtool_obj))
@@ -266,19 +242,26 @@ objtool_dep = $(objtool_obj) \
266 $(wildcard include/config/orc/unwinder.h \ 242 $(wildcard include/config/orc/unwinder.h \
267 include/config/stack/validation.h) 243 include/config/stack/validation.h)
268 244
245ifdef CONFIG_TRIM_UNUSED_KSYMS
246cmd_gen_ksymdeps = \
247 $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
248endif
249
269define rule_cc_o_c 250define rule_cc_o_c
270 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 251 $(call cmd,checksrc)
271 $(call cmd_and_fixdep,cc_o_c) \ 252 $(call cmd_and_fixdep,cc_o_c)
272 $(cmd_checkdoc) \ 253 $(call cmd,gen_ksymdeps)
273 $(call echo-cmd,objtool) $(cmd_objtool) \ 254 $(call cmd,checkdoc)
274 $(cmd_modversions_c) \ 255 $(call cmd,objtool)
275 $(call echo-cmd,record_mcount) $(cmd_record_mcount) 256 $(call cmd,modversions_c)
257 $(call cmd,record_mcount)
276endef 258endef
277 259
278define rule_as_o_S 260define rule_as_o_S
279 $(call cmd_and_fixdep,as_o_S) \ 261 $(call cmd_and_fixdep,as_o_S)
280 $(call echo-cmd,objtool) $(cmd_objtool) \ 262 $(call cmd,gen_ksymdeps)
281 $(cmd_modversions_S) 263 $(call cmd,objtool)
264 $(call cmd,modversions_S)
282endef 265endef
283 266
284# List module undefined symbols (or empty line if not enabled) 267# List module undefined symbols (or empty line if not enabled)
@@ -342,7 +325,6 @@ cmd_gensymtypes_S = \
342 325
343quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ 326quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
344cmd_cc_symtypes_S = \ 327cmd_cc_symtypes_S = \
345 set -e; \
346 $(call cmd_gensymtypes_S,true,$@) >/dev/null; \ 328 $(call cmd_gensymtypes_S,true,$@) >/dev/null; \
347 test -s $@ || rm -f $@ 329 test -s $@ || rm -f $@
348 330
@@ -357,35 +339,27 @@ $(obj)/%.s: $(src)/%.S FORCE
357 $(call if_changed_dep,cpp_s_S) 339 $(call if_changed_dep,cpp_s_S)
358 340
359quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 341quiet_cmd_as_o_S = AS $(quiet_modtag) $@
342 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
360 343
361ifndef CONFIG_MODVERSIONS 344ifdef CONFIG_MODVERSIONS
362cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
363
364else
365 345
366ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h) 346ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
367 347
368ifeq ($(ASM_PROTOTYPES),) 348ifneq ($(ASM_PROTOTYPES),)
369cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
370
371else
372 349
373# versioning matches the C process described above, with difference that 350# versioning matches the C process described above, with difference that
374# we parse asm-prototypes.h C header to get function definitions. 351# we parse asm-prototypes.h C header to get function definitions.
375 352
376cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
377
378cmd_modversions_S = \ 353cmd_modversions_S = \
379 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 354 if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
380 $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 355 $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
381 > $(@D)/.tmp_$(@F:.o=.ver); \ 356 > $(@D)/.tmp_$(@F:.o=.ver); \
382 \ 357 \
383 $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 358 $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
384 -T $(@D)/.tmp_$(@F:.o=.ver); \ 359 -T $(@D)/.tmp_$(@F:.o=.ver); \
385 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
386 else \
387 mv -f $(@D)/.tmp_$(@F) $@; \ 360 mv -f $(@D)/.tmp_$(@F) $@; \
388 fi; 361 rm -f $(@D)/.tmp_$(@F:.o=.ver); \
362 fi
389endif 363endif
390endif 364endif
391 365
@@ -529,25 +503,19 @@ FORCE:
529# optimization, we don't need to read them if the target does not 503# optimization, we don't need to read them if the target does not
530# exist, we will rebuild anyway in that case. 504# exist, we will rebuild anyway in that case.
531 505
532cmd_files := $(wildcard $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd)) 506existing-targets := $(wildcard $(sort $(targets)))
533 507
534ifneq ($(cmd_files),) 508-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
535 include $(cmd_files)
536endif
537 509
538ifneq ($(KBUILD_SRC),) 510ifneq ($(KBUILD_SRC),)
539# Create directories for object files if they do not exist 511# Create directories for object files if they do not exist
540obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets)))) 512obj-dirs := $(sort $(obj) $(patsubst %/,%, $(dir $(targets))))
541# If cmd_files exist, their directories apparently exist. Skip mkdir. 513# If targets exist, their directories apparently exist. Skip mkdir.
542exist-dirs := $(sort $(patsubst %/,%, $(dir $(cmd_files)))) 514existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets))))
543obj-dirs := $(strip $(filter-out $(exist-dirs), $(obj-dirs))) 515obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs)))
544ifneq ($(obj-dirs),) 516ifneq ($(obj-dirs),)
545$(shell mkdir -p $(obj-dirs)) 517$(shell mkdir -p $(obj-dirs))
546endif 518endif
547endif 519endif
548 520
549# Some files contained in $(targets) are intermediate artifacts.
550# We never want them to be removed automatically.
551.SECONDARY: $(targets)
552
553.PHONY: $(PHONY) 521.PHONY: $(PHONY)
diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins
index 46c5c6809806..35042d96cf5d 100644
--- a/scripts/Makefile.gcc-plugins
+++ b/scripts/Makefile.gcc-plugins
@@ -36,6 +36,12 @@ ifdef CONFIG_GCC_PLUGIN_STACKLEAK
36endif 36endif
37export DISABLE_STACKLEAK_PLUGIN 37export DISABLE_STACKLEAK_PLUGIN
38 38
39gcc-plugin-$(CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK) += arm_ssp_per_task_plugin.so
40ifdef CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK
41 DISABLE_ARM_SSP_PER_TASK_PLUGIN += -fplugin-arg-arm_ssp_per_task_plugin-disable
42endif
43export DISABLE_ARM_SSP_PER_TASK_PLUGIN
44
39# All the plugin CFLAGS are collected here in case a build target needs to 45# All the plugin CFLAGS are collected here in case a build target needs to
40# filter them out of the KBUILD_CFLAGS. 46# filter them out of the KBUILD_CFLAGS.
41GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) 47GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
@@ -49,11 +55,3 @@ KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
49# All enabled GCC plugins are collected here for building below. 55# All enabled GCC plugins are collected here for building below.
50GCC_PLUGIN := $(gcc-plugin-y) 56GCC_PLUGIN := $(gcc-plugin-y)
51export GCC_PLUGIN 57export GCC_PLUGIN
52
53# Actually do the build, if requested.
54PHONY += gcc-plugins
55gcc-plugins: scripts_basic
56ifdef CONFIG_GCC_PLUGINS
57 $(Q)$(MAKE) $(build)=scripts/gcc-plugins
58endif
59 @:
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
index d5e131471131..3d1ebaabd1b6 100644
--- a/scripts/Makefile.headersinst
+++ b/scripts/Makefile.headersinst
@@ -44,7 +44,6 @@ kbuild-file := $(srctree)/$(obj)/Kbuild
44installdir := $(INSTALL_HDR_PATH)/$(dst) 44installdir := $(INSTALL_HDR_PATH)/$(dst)
45gendir := $(objtree)/$(subst include/,include/generated/,$(obj)) 45gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
46header-files := $(notdir $(wildcard $(srcdir)/*.h)) 46header-files := $(notdir $(wildcard $(srcdir)/*.h))
47header-files += $(notdir $(wildcard $(srcdir)/*.agh))
48header-files := $(filter-out $(no-export-headers), $(header-files)) 47header-files := $(filter-out $(no-export-headers), $(header-files))
49genhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 48genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
50genhdr-files := $(filter-out $(header-files), $(genhdr-files)) 49genhdr-files := $(filter-out $(header-files), $(genhdr-files))
@@ -57,13 +56,6 @@ check-file := $(installdir)/.check
57all-files := $(header-files) $(genhdr-files) 56all-files := $(header-files) $(genhdr-files)
58output-files := $(addprefix $(installdir)/, $(all-files)) 57output-files := $(addprefix $(installdir)/, $(all-files))
59 58
60ifneq ($(mandatory-y),)
61missing := $(filter-out $(all-files),$(mandatory-y))
62ifneq ($(missing),)
63$(error Some mandatory headers ($(missing)) are missing in $(obj))
64endif
65endif
66
67# Work out what needs to be removed 59# Work out what needs to be removed
68oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 60oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
69unwanted := $(filter-out $(all-files),$(oldheaders)) 61unwanted := $(filter-out $(all-files),$(oldheaders))
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 69552a39951d..25c259df8ffa 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -1,5 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2ifdef CONFIG_KASAN 2ifdef CONFIG_KASAN_GENERIC
3
3ifdef CONFIG_KASAN_INLINE 4ifdef CONFIG_KASAN_INLINE
4 call_threshold := 10000 5 call_threshold := 10000
5else 6else
@@ -12,36 +13,44 @@ CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
12 13
13cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) 14cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
14 15
15ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) 16# -fasan-shadow-offset fails without -fsanitize
16 ifneq ($(CONFIG_COMPILE_TEST),y) 17CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
17 $(warning Cannot use CONFIG_KASAN: \
18 -fsanitize=kernel-address is not supported by compiler)
19 endif
20else
21 # -fasan-shadow-offset fails without -fsanitize
22 CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
23 -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ 18 -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
24 $(call cc-option, -fsanitize=kernel-address \ 19 $(call cc-option, -fsanitize=kernel-address \
25 -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) 20 -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
26 21
27 ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) 22ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
28 CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) 23 CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
29 else 24else
30 # Now add all the compiler specific options that are valid standalone 25 # Now add all the compiler specific options that are valid standalone
31 CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ 26 CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
32 $(call cc-param,asan-globals=1) \ 27 $(call cc-param,asan-globals=1) \
33 $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ 28 $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
34 $(call cc-param,asan-stack=1) \ 29 $(call cc-param,asan-stack=1) \
35 $(call cc-param,asan-use-after-scope=1) \ 30 $(call cc-param,asan-use-after-scope=1) \
36 $(call cc-param,asan-instrument-allocas=1) 31 $(call cc-param,asan-instrument-allocas=1)
37 endif
38
39endif 32endif
40 33
41ifdef CONFIG_KASAN_EXTRA 34ifdef CONFIG_KASAN_EXTRA
42CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) 35CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
43endif 36endif
44 37
45CFLAGS_KASAN_NOSANITIZE := -fno-builtin 38endif # CONFIG_KASAN_GENERIC
46 39
40ifdef CONFIG_KASAN_SW_TAGS
41
42ifdef CONFIG_KASAN_INLINE
43 instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)
44else
45 instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1
46endif
47
48CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
49 -mllvm -hwasan-instrument-stack=0 \
50 $(instrumentation_flags)
51
52endif # CONFIG_KASAN_SW_TAGS
53
54ifdef CONFIG_KASAN
55CFLAGS_KASAN_NOSANITIZE := -fno-builtin
47endif 56endif
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 8fe4468f9bda..12b88d09c3a4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -61,6 +61,11 @@ real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))
61extra-y += $(dtb-y) 61extra-y += $(dtb-y)
62extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 62extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
63 63
64ifneq ($(CHECK_DTBS),)
65extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
66extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
67endif
68
64# Add subdir path 69# Add subdir path
65 70
66extra-y := $(addprefix $(obj)/,$(extra-y)) 71extra-y := $(addprefix $(obj)/,$(extra-y))
@@ -237,8 +242,7 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
237# --------------------------------------------------------------------------- 242# ---------------------------------------------------------------------------
238 243
239quiet_cmd_gzip = GZIP $@ 244quiet_cmd_gzip = GZIP $@
240cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ 245 cmd_gzip = cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@
241 (rm -f $@ ; false)
242 246
243# DTC 247# DTC
244# --------------------------------------------------------------------------- 248# ---------------------------------------------------------------------------
@@ -251,7 +255,7 @@ DTC_FLAGS += -Wno-unit_address_vs_reg \
251 -Wno-avoid_unnecessary_addr_size \ 255 -Wno-avoid_unnecessary_addr_size \
252 -Wno-alias_paths \ 256 -Wno-alias_paths \
253 -Wno-graph_child_address \ 257 -Wno-graph_child_address \
254 -Wno-graph_port \ 258 -Wno-simple_bus_reg \
255 -Wno-unique_unit_address \ 259 -Wno-unique_unit_address \
256 -Wno-pci_device_reg 260 -Wno-pci_device_reg
257endif 261endif
@@ -284,13 +288,28 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
284quiet_cmd_dtc = DTC $@ 288quiet_cmd_dtc = DTC $@
285cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \ 289cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
286 $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 290 $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
287 $(DTC) -O dtb -o $@ -b 0 \ 291 $(DTC) -O $(2) -o $@ -b 0 \
288 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \ 292 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
289 -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 293 -d $(depfile).dtc.tmp $(dtc-tmp) ; \
290 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) 294 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
291 295
292$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE 296$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
293 $(call if_changed_dep,dtc) 297 $(call if_changed_dep,dtc,dtb)
298
299DT_CHECKER ?= dt-validate
300DT_BINDING_DIR := Documentation/devicetree/bindings
301DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.yaml
302
303quiet_cmd_dtb_check = CHECK $@
304 cmd_dtb_check = $(DT_CHECKER) -p $(DT_TMP_SCHEMA) $@ ;
305
306define rule_dtc_dt_yaml
307 $(call cmd_and_fixdep,dtc,yaml)
308 $(call cmd,dtb_check)
309endef
310
311$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
312 $(call if_changed_rule,dtc_dt_yaml)
294 313
295dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 314dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
296 315
@@ -316,26 +335,22 @@ printf "%08x\n" $$dec_size | \
316 335
317quiet_cmd_bzip2 = BZIP2 $@ 336quiet_cmd_bzip2 = BZIP2 $@
318cmd_bzip2 = (cat $(filter-out FORCE,$^) | \ 337cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
319 bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 338 bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@
320 (rm -f $@ ; false)
321 339
322# Lzma 340# Lzma
323# --------------------------------------------------------------------------- 341# ---------------------------------------------------------------------------
324 342
325quiet_cmd_lzma = LZMA $@ 343quiet_cmd_lzma = LZMA $@
326cmd_lzma = (cat $(filter-out FORCE,$^) | \ 344cmd_lzma = (cat $(filter-out FORCE,$^) | \
327 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 345 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@
328 (rm -f $@ ; false)
329 346
330quiet_cmd_lzo = LZO $@ 347quiet_cmd_lzo = LZO $@
331cmd_lzo = (cat $(filter-out FORCE,$^) | \ 348cmd_lzo = (cat $(filter-out FORCE,$^) | \
332 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 349 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@
333 (rm -f $@ ; false)
334 350
335quiet_cmd_lz4 = LZ4 $@ 351quiet_cmd_lz4 = LZ4 $@
336cmd_lz4 = (cat $(filter-out FORCE,$^) | \ 352cmd_lz4 = (cat $(filter-out FORCE,$^) | \
337 lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 353 lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@
338 (rm -f $@ ; false)
339 354
340# U-Boot mkimage 355# U-Boot mkimage
341# --------------------------------------------------------------------------- 356# ---------------------------------------------------------------------------
@@ -351,15 +366,13 @@ UIMAGE_TYPE ?= kernel
351UIMAGE_LOADADDR ?= arch_must_set_this 366UIMAGE_LOADADDR ?= arch_must_set_this
352UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) 367UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
353UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)' 368UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
354UIMAGE_IN ?= $<
355UIMAGE_OUT ?= $@
356 369
357quiet_cmd_uimage = UIMAGE $(UIMAGE_OUT) 370quiet_cmd_uimage = UIMAGE $@
358 cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ 371 cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
359 -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ 372 -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
360 -T $(UIMAGE_TYPE) \ 373 -T $(UIMAGE_TYPE) \
361 -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ 374 -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
362 -n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT) 375 -n $(UIMAGE_NAME) -d $< $@
363 376
364# XZ 377# XZ
365# --------------------------------------------------------------------------- 378# ---------------------------------------------------------------------------
@@ -381,13 +394,11 @@ quiet_cmd_uimage = UIMAGE $(UIMAGE_OUT)
381quiet_cmd_xzkern = XZKERN $@ 394quiet_cmd_xzkern = XZKERN $@
382cmd_xzkern = (cat $(filter-out FORCE,$^) | \ 395cmd_xzkern = (cat $(filter-out FORCE,$^) | \
383 sh $(srctree)/scripts/xz_wrap.sh && \ 396 sh $(srctree)/scripts/xz_wrap.sh && \
384 $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 397 $(call size_append, $(filter-out FORCE,$^))) > $@
385 (rm -f $@ ; false)
386 398
387quiet_cmd_xzmisc = XZMISC $@ 399quiet_cmd_xzmisc = XZMISC $@
388cmd_xzmisc = (cat $(filter-out FORCE,$^) | \ 400cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
389 xz --check=crc32 --lzma2=dict=1MiB) > $@ || \ 401 xz --check=crc32 --lzma2=dict=1MiB) > $@
390 (rm -f $@ ; false)
391 402
392# ASM offsets 403# ASM offsets
393# --------------------------------------------------------------------------- 404# ---------------------------------------------------------------------------
@@ -406,7 +417,6 @@ endef
406# Use filechk to avoid rebuilds when a header changes, but the resulting file 417# Use filechk to avoid rebuilds when a header changes, but the resulting file
407# does not 418# does not
408define filechk_offsets 419define filechk_offsets
409 (set -e; \
410 echo "#ifndef $2"; \ 420 echo "#ifndef $2"; \
411 echo "#define $2"; \ 421 echo "#define $2"; \
412 echo "/*"; \ 422 echo "/*"; \
@@ -417,5 +427,5 @@ define filechk_offsets
417 echo ""; \ 427 echo ""; \
418 sed -ne $(sed-offsets) < $<; \ 428 sed -ne $(sed-offsets) < $<; \
419 echo ""; \ 429 echo ""; \
420 echo "#endif" ) 430 echo "#endif"
421endef 431endef
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index 850966f3d602..facbd603adf6 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -105,8 +105,7 @@
105 105
106static void usage(void) 106static void usage(void)
107{ 107{
108 fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n"); 108 fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
109 fprintf(stderr, " -e insert extra dependencies given on stdin\n");
110 exit(1); 109 exit(1);
111} 110}
112 111
@@ -131,21 +130,6 @@ static void print_dep(const char *m, int slen, const char *dir)
131 printf(".h) \\\n"); 130 printf(".h) \\\n");
132} 131}
133 132
134static void do_extra_deps(void)
135{
136 char buf[80];
137
138 while (fgets(buf, sizeof(buf), stdin)) {
139 int len = strlen(buf);
140
141 if (len < 2 || buf[len - 1] != '\n') {
142 fprintf(stderr, "fixdep: bad data on stdin\n");
143 exit(1);
144 }
145 print_dep(buf, len - 1, "include/ksym");
146 }
147}
148
149struct item { 133struct item {
150 struct item *next; 134 struct item *next;
151 unsigned int len; 135 unsigned int len;
@@ -293,7 +277,7 @@ static int is_ignored_file(const char *s, int len)
293 * assignments are parsed not only by make, but also by the rather simple 277 * assignments are parsed not only by make, but also by the rather simple
294 * parser in scripts/mod/sumversion.c. 278 * parser in scripts/mod/sumversion.c.
295 */ 279 */
296static void parse_dep_file(char *m, const char *target, int insert_extra_deps) 280static void parse_dep_file(char *m, const char *target)
297{ 281{
298 char *p; 282 char *p;
299 int is_last, is_target; 283 int is_last, is_target;
@@ -369,9 +353,6 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
369 exit(1); 353 exit(1);
370 } 354 }
371 355
372 if (insert_extra_deps)
373 do_extra_deps();
374
375 printf("\n%s: $(deps_%s)\n\n", target, target); 356 printf("\n%s: $(deps_%s)\n\n", target, target);
376 printf("$(deps_%s):\n", target); 357 printf("$(deps_%s):\n", target);
377} 358}
@@ -379,13 +360,9 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
379int main(int argc, char *argv[]) 360int main(int argc, char *argv[])
380{ 361{
381 const char *depfile, *target, *cmdline; 362 const char *depfile, *target, *cmdline;
382 int insert_extra_deps = 0;
383 void *buf; 363 void *buf;
384 364
385 if (argc == 5 && !strcmp(argv[1], "-e")) { 365 if (argc != 4)
386 insert_extra_deps = 1;
387 argv++;
388 } else if (argc != 4)
389 usage(); 366 usage();
390 367
391 depfile = argv[1]; 368 depfile = argv[1];
@@ -395,7 +372,7 @@ int main(int argc, char *argv[])
395 printf("cmd_%s := %s\n\n", target, cmdline); 372 printf("cmd_%s := %s\n\n", target, cmdline);
396 373
397 buf = read_file(depfile); 374 buf = read_file(depfile);
398 parse_dep_file(buf, target, insert_extra_deps); 375 parse_dep_file(buf, target);
399 free(buf); 376 free(buf);
400 377
401 return 0; 378 return 0;
diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index a923f05edb36..8c965f6a9881 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -32,6 +32,7 @@ def getsizes(file, format):
32 if name.startswith("__mod_"): continue 32 if name.startswith("__mod_"): continue
33 if name.startswith("__se_sys"): continue 33 if name.startswith("__se_sys"): continue
34 if name.startswith("__se_compat_sys"): continue 34 if name.startswith("__se_compat_sys"): continue
35 if name.startswith("__addressable_"): continue
35 if name == "linux_banner": continue 36 if name == "linux_banner": continue
36 # statics and some other optimizations adds random .NUMBER 37 # statics and some other optimizations adds random .NUMBER
37 name = re_NUMBER.sub('', name) 38 name = re_NUMBER.sub('', name)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index c883ec55654f..b737ca9d7204 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -468,6 +468,7 @@ our $logFunctions = qr{(?x:
468 468
469our $signature_tags = qr{(?xi: 469our $signature_tags = qr{(?xi:
470 Signed-off-by:| 470 Signed-off-by:|
471 Co-developed-by:|
471 Acked-by:| 472 Acked-by:|
472 Tested-by:| 473 Tested-by:|
473 Reviewed-by:| 474 Reviewed-by:|
@@ -573,6 +574,27 @@ foreach my $entry (@mode_permission_funcs) {
573} 574}
574$mode_perms_search = "(?:${mode_perms_search})"; 575$mode_perms_search = "(?:${mode_perms_search})";
575 576
577our %deprecated_apis = (
578 "synchronize_rcu_bh" => "synchronize_rcu",
579 "synchronize_rcu_bh_expedited" => "synchronize_rcu_expedited",
580 "call_rcu_bh" => "call_rcu",
581 "rcu_barrier_bh" => "rcu_barrier",
582 "synchronize_sched" => "synchronize_rcu",
583 "synchronize_sched_expedited" => "synchronize_rcu_expedited",
584 "call_rcu_sched" => "call_rcu",
585 "rcu_barrier_sched" => "rcu_barrier",
586 "get_state_synchronize_sched" => "get_state_synchronize_rcu",
587 "cond_synchronize_sched" => "cond_synchronize_rcu",
588);
589
590#Create a search pattern for all these strings to speed up a loop below
591our $deprecated_apis_search = "";
592foreach my $entry (keys %deprecated_apis) {
593 $deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");
594 $deprecated_apis_search .= $entry;
595}
596$deprecated_apis_search = "(?:${deprecated_apis_search})";
597
576our $mode_perms_world_writable = qr{ 598our $mode_perms_world_writable = qr{
577 S_IWUGO | 599 S_IWUGO |
578 S_IWOTH | 600 S_IWOTH |
@@ -3869,14 +3891,23 @@ sub process {
3869 WARN("STATIC_CONST_CHAR_ARRAY", 3891 WARN("STATIC_CONST_CHAR_ARRAY",
3870 "static const char * array should probably be static const char * const\n" . 3892 "static const char * array should probably be static const char * const\n" .
3871 $herecurr); 3893 $herecurr);
3872 } 3894 }
3895
3896# check for initialized const char arrays that should be static const
3897 if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
3898 if (WARN("STATIC_CONST_CHAR_ARRAY",
3899 "const array should probably be static const\n" . $herecurr) &&
3900 $fix) {
3901 $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
3902 }
3903 }
3873 3904
3874# check for static char foo[] = "bar" declarations. 3905# check for static char foo[] = "bar" declarations.
3875 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { 3906 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
3876 WARN("STATIC_CONST_CHAR_ARRAY", 3907 WARN("STATIC_CONST_CHAR_ARRAY",
3877 "static char array declaration should probably be static const char\n" . 3908 "static char array declaration should probably be static const char\n" .
3878 $herecurr); 3909 $herecurr);
3879 } 3910 }
3880 3911
3881# check for const <foo> const where <foo> is not a pointer or array type 3912# check for const <foo> const where <foo> is not a pointer or array type
3882 if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { 3913 if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
@@ -6368,6 +6399,20 @@ sub process {
6368 "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr); 6399 "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
6369 } 6400 }
6370 6401
6402# check for spin_is_locked(), suggest lockdep instead
6403 if ($line =~ /\bspin_is_locked\(/) {
6404 WARN("USE_LOCKDEP",
6405 "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr);
6406 }
6407
6408# check for deprecated apis
6409 if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
6410 my $deprecated_api = $1;
6411 my $new_api = $deprecated_apis{$deprecated_api};
6412 WARN("DEPRECATED_API",
6413 "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr);
6414 }
6415
6371# check for various structs that are normally const (ops, kgdb, device_tree) 6416# check for various structs that are normally const (ops, kgdb, device_tree)
6372# and avoid what seem like struct definitions 'struct foo {' 6417# and avoid what seem like struct definitions 'struct foo {'
6373 if ($line !~ /\bconst\b/ && 6418 if ($line !~ /\bconst\b/ &&
diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl
index 8081b6cf67d2..122aef5e4e14 100755
--- a/scripts/checkstack.pl
+++ b/scripts/checkstack.pl
@@ -47,8 +47,10 @@ my (@stack, $re, $dre, $x, $xs, $funcre);
47 $xs = "[0-9a-f ]"; # hex character or space 47 $xs = "[0-9a-f ]"; # hex character or space
48 $funcre = qr/^$x* <(.*)>:$/; 48 $funcre = qr/^$x* <(.*)>:$/;
49 if ($arch eq 'aarch64') { 49 if ($arch eq 'aarch64') {
50 #ffffffc0006325cc: a9bb7bfd stp x29, x30, [sp,#-80]! 50 #ffffffc0006325cc: a9bb7bfd stp x29, x30, [sp, #-80]!
51 $re = qr/^.*stp.*sp,\#-([0-9]{1,8})\]\!/o; 51 #a110: d11643ff sub sp, sp, #0x590
52 $re = qr/^.*stp.*sp, \#-([0-9]{1,8})\]\!/o;
53 $dre = qr/^.*sub.*sp, sp, #(0x$x{1,8})/o;
52 } elsif ($arch eq 'arm') { 54 } elsif ($arch eq 'arm') {
53 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64 55 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
54 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; 56 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
diff --git a/scripts/checksyscalls.sh b/scripts/checksyscalls.sh
index ee3dfb5be6cd..cf931003395f 100755
--- a/scripts/checksyscalls.sh
+++ b/scripts/checksyscalls.sh
@@ -150,6 +150,7 @@ cat << EOF
150#define __IGNORE_uselib 150#define __IGNORE_uselib
151#define __IGNORE__sysctl 151#define __IGNORE__sysctl
152#define __IGNORE_arch_prctl 152#define __IGNORE_arch_prctl
153#define __IGNORE_nfsservctl
153 154
154/* ... including the "new" 32-bit uid syscalls */ 155/* ... including the "new" 32-bit uid syscalls */
155#define __IGNORE_lchown32 156#define __IGNORE_lchown32
diff --git a/scripts/coccinelle/api/alloc/alloc_cast.cocci b/scripts/coccinelle/api/alloc/alloc_cast.cocci
index 408ee3879f9b..18fedf7c60ed 100644
--- a/scripts/coccinelle/api/alloc/alloc_cast.cocci
+++ b/scripts/coccinelle/api/alloc/alloc_cast.cocci
@@ -32,7 +32,7 @@ type T;
32 (T *) 32 (T *)
33 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| 33 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
34 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| 34 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
35 dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| 35 dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
36 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| 36 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
37 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| 37 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
38 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) 38 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
@@ -55,7 +55,7 @@ type r1.T;
55* (T *) 55* (T *)
56 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| 56 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
57 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| 57 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
58 dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| 58 dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
59 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| 59 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
60 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| 60 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
61 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) 61 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
@@ -78,7 +78,7 @@ type r1.T;
78- (T *) 78- (T *)
79 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| 79 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
80 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| 80 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
81 dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| 81 dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
82 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| 82 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
83 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| 83 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
84 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) 84 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
@@ -95,7 +95,7 @@ position p;
95 (T@p *) 95 (T@p *)
96 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| 96 \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\|
97 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| 97 kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\|
98 dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| 98 dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\|
99 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| 99 kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\|
100 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| 100 pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\|
101 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) 101 kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...)
diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
index d819275b7fde..5cd1991c582e 100644
--- a/scripts/coccinelle/api/alloc/zalloc-simple.cocci
+++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci
@@ -69,15 +69,6 @@ statement S;
69- x = (T)vmalloc(E1); 69- x = (T)vmalloc(E1);
70+ x = (T)vzalloc(E1); 70+ x = (T)vzalloc(E1);
71| 71|
72- x = dma_alloc_coherent(E2,E1,E3,E4);
73+ x = dma_zalloc_coherent(E2,E1,E3,E4);
74|
75- x = (T *)dma_alloc_coherent(E2,E1,E3,E4);
76+ x = dma_zalloc_coherent(E2,E1,E3,E4);
77|
78- x = (T)dma_alloc_coherent(E2,E1,E3,E4);
79+ x = (T)dma_zalloc_coherent(E2,E1,E3,E4);
80|
81- x = kmalloc_node(E1,E2,E3); 72- x = kmalloc_node(E1,E2,E3);
82+ x = kzalloc_node(E1,E2,E3); 73+ x = kzalloc_node(E1,E2,E3);
83| 74|
@@ -225,7 +216,7 @@ p << r2.p;
225x << r2.x; 216x << r2.x;
226@@ 217@@
227 218
228msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x) 219msg="WARNING: dma_alloc_coherent use in %s already zeroes out memory, so memset is not needed" % (x)
229coccilib.report.print_report(p[0], msg) 220coccilib.report.print_report(p[0], msg)
230 221
231//----------------------------------------------------------------- 222//-----------------------------------------------------------------
diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci
index ce8cc9c006e5..66a1140474c8 100644
--- a/scripts/coccinelle/iterators/use_after_iter.cocci
+++ b/scripts/coccinelle/iterators/use_after_iter.cocci
@@ -35,6 +35,7 @@ iterator name hlist_for_each_entry_from;
35iterator name hlist_for_each_entry_safe; 35iterator name hlist_for_each_entry_safe;
36statement S; 36statement S;
37position p1,p2; 37position p1,p2;
38type T;
38@@ 39@@
39 40
40( 41(
@@ -125,6 +126,8 @@ sizeof(<+...c...+>)
125| 126|
126 &c->member 127 &c->member
127| 128|
129T c;
130|
128c = E 131c = E
129| 132|
130*c@p2 133*c@p2
diff --git a/scripts/coccinelle/misc/boolinit.cocci b/scripts/coccinelle/misc/boolinit.cocci
index b9abed49cd95..aabb581fab5c 100644
--- a/scripts/coccinelle/misc/boolinit.cocci
+++ b/scripts/coccinelle/misc/boolinit.cocci
@@ -13,10 +13,17 @@ virtual context
13virtual org 13virtual org
14virtual report 14virtual report
15 15
16@boolok@
17symbol true,false;
18@@
19(
20true
21|
22false
23)
24
16@depends on patch@ 25@depends on patch@
17bool t; 26bool t;
18symbol true;
19symbol false;
20@@ 27@@
21 28
22( 29(
@@ -63,7 +70,7 @@ bool t;
63+ t 70+ t
64) 71)
65 72
66@depends on patch@ 73@depends on patch && boolok@
67bool b; 74bool b;
68@@ 75@@
69( 76(
@@ -116,15 +123,24 @@ position p;
116* t@p != 0 123* t@p != 0
117) 124)
118 125
119@r3 depends on !patch@ 126@r3 depends on !patch && boolok@
120bool b; 127bool b;
121position p1,p2; 128position p1;
122constant c;
123@@ 129@@
124( 130(
125*b@p1 = 0 131*b@p1 = 0
126| 132|
127*b@p1 = 1 133*b@p1 = 1
134)
135
136@r4 depends on !patch@
137bool b;
138position p2;
139identifier i;
140constant c != {0,1};
141@@
142(
143 b = i
128| 144|
129*b@p2 = c 145*b@p2 = c
130) 146)
@@ -139,19 +155,19 @@ cocci.print_main("WARNING: Comparison to bool",p)
139p << r2.p; 155p << r2.p;
140@@ 156@@
141 157
142cocci.print_main("WARNING: Comparison of bool to 0/1",p) 158cocci.print_main("WARNING: Comparison of 0/1 to bool variable",p)
143 159
144@script:python depends on org@ 160@script:python depends on org@
145p1 << r3.p1; 161p1 << r3.p1;
146@@ 162@@
147 163
148cocci.print_main("WARNING: Assignment of bool to 0/1",p1) 164cocci.print_main("WARNING: Assignment of 0/1 to bool variable",p1)
149 165
150@script:python depends on org@ 166@script:python depends on org@
151p2 << r3.p2; 167p2 << r4.p2;
152@@ 168@@
153 169
154cocci.print_main("ERROR: Assignment of bool to non-0/1 constant",p2) 170cocci.print_main("ERROR: Assignment of non-0/1 constant to bool variable",p2)
155 171
156@script:python depends on report@ 172@script:python depends on report@
157p << r1.p; 173p << r1.p;
@@ -163,16 +179,16 @@ coccilib.report.print_report(p[0],"WARNING: Comparison to bool")
163p << r2.p; 179p << r2.p;
164@@ 180@@
165 181
166coccilib.report.print_report(p[0],"WARNING: Comparison of bool to 0/1") 182coccilib.report.print_report(p[0],"WARNING: Comparison of 0/1 to bool variable")
167 183
168@script:python depends on report@ 184@script:python depends on report@
169p1 << r3.p1; 185p1 << r3.p1;
170@@ 186@@
171 187
172coccilib.report.print_report(p1[0],"WARNING: Assignment of bool to 0/1") 188coccilib.report.print_report(p1[0],"WARNING: Assignment of 0/1 to bool variable")
173 189
174@script:python depends on report@ 190@script:python depends on report@
175p2 << r3.p2; 191p2 << r4.p2;
176@@ 192@@
177 193
178coccilib.report.print_report(p2[0],"ERROR: Assignment of bool to non-0/1 constant") 194coccilib.report.print_report(p2[0],"ERROR: Assignment of non-0/1 constant to bool variable")
diff --git a/scripts/decode_stacktrace.sh b/scripts/decode_stacktrace.sh
index 64220e36ce3b..98a7d63a723e 100755
--- a/scripts/decode_stacktrace.sh
+++ b/scripts/decode_stacktrace.sh
@@ -78,7 +78,7 @@ parse_symbol() {
78 fi 78 fi
79 79
80 # Strip out the base of the path 80 # Strip out the base of the path
81 code=${code//$basepath/""} 81 code=${code//^$basepath/""}
82 82
83 # In the case of inlines, move everything to same line 83 # In the case of inlines, move everything to same line
84 code=${code//$'\n'/' '} 84 code=${code//$'\n'/' '}
diff --git a/scripts/decodecode b/scripts/decodecode
index 9cef558528aa..ba8b8d5834e6 100755
--- a/scripts/decodecode
+++ b/scripts/decodecode
@@ -60,6 +60,13 @@ case $width in
604) type=4byte ;; 604) type=4byte ;;
61esac 61esac
62 62
63if [ -z "$ARCH" ]; then
64 case `uname -m` in
65 aarch64*) ARCH=arm64 ;;
66 arm*) ARCH=arm ;;
67 esac
68fi
69
63disas() { 70disas() {
64 ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1 71 ${CROSS_COMPILE}as $AFLAGS -o $1.o $1.s > /dev/null 2>&1
65 72
diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile
index 056d5da6c477..5f227d8d39d8 100644
--- a/scripts/dtc/Makefile
+++ b/scripts/dtc/Makefile
@@ -12,6 +12,10 @@ dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
12HOST_EXTRACFLAGS := -I$(src)/libfdt 12HOST_EXTRACFLAGS := -I$(src)/libfdt
13 13
14ifeq ($(wildcard /usr/include/yaml.h),) 14ifeq ($(wildcard /usr/include/yaml.h),)
15ifneq ($(CHECK_DTBS),)
16$(error dtc needs libyaml for DT schema validation support. \
17 Install the necessary libyaml development package.)
18endif
15HOST_EXTRACFLAGS += -DNO_YAML 19HOST_EXTRACFLAGS += -DNO_YAML
16else 20else
17dtc-objs += yamltree.o 21dtc-objs += yamltree.o
diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
index 9c9b0c328af6..4834e44b37b2 100644
--- a/scripts/dtc/checks.c
+++ b/scripts/dtc/checks.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "dtc.h" 21#include "dtc.h"
22#include "srcpos.h"
22 23
23#ifdef TRACE_CHECKS 24#ifdef TRACE_CHECKS
24#define TRACE(c, ...) \ 25#define TRACE(c, ...) \
@@ -78,23 +79,56 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
78 const char *fmt, ...) 79 const char *fmt, ...)
79{ 80{
80 va_list ap; 81 va_list ap;
81 va_start(ap, fmt); 82 char *str = NULL;
83 struct srcpos *pos = NULL;
84 char *file_str;
85
86 if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2)))
87 return;
88
89 if (prop && prop->srcpos)
90 pos = prop->srcpos;
91 else if (node && node->srcpos)
92 pos = node->srcpos;
93
94 if (pos) {
95 file_str = srcpos_string(pos);
96 xasprintf(&str, "%s", file_str);
97 free(file_str);
98 } else if (streq(dti->outname, "-")) {
99 xasprintf(&str, "<stdout>");
100 } else {
101 xasprintf(&str, "%s", dti->outname);
102 }
82 103
83 if ((c->warn && (quiet < 1)) 104 xasprintf_append(&str, ": %s (%s): ",
84 || (c->error && (quiet < 2))) {
85 fprintf(stderr, "%s: %s (%s): ",
86 strcmp(dti->outname, "-") ? dti->outname : "<stdout>",
87 (c->error) ? "ERROR" : "Warning", c->name); 105 (c->error) ? "ERROR" : "Warning", c->name);
88 if (node) { 106
89 fprintf(stderr, "%s", node->fullpath); 107 if (node) {
90 if (prop) 108 if (prop)
91 fprintf(stderr, ":%s", prop->name); 109 xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name);
92 fputs(": ", stderr); 110 else
93 } 111 xasprintf_append(&str, "%s: ", node->fullpath);
94 vfprintf(stderr, fmt, ap);
95 fprintf(stderr, "\n");
96 } 112 }
113
114 va_start(ap, fmt);
115 xavsprintf_append(&str, fmt, ap);
97 va_end(ap); 116 va_end(ap);
117
118 xasprintf_append(&str, "\n");
119
120 if (!prop && pos) {
121 pos = node->srcpos;
122 while (pos->next) {
123 pos = pos->next;
124
125 file_str = srcpos_string(pos);
126 xasprintf_append(&str, " also defined at %s\n", file_str);
127 free(file_str);
128 }
129 }
130
131 fputs(str, stderr);
98} 132}
99 133
100#define FAIL(c, dti, node, ...) \ 134#define FAIL(c, dti, node, ...) \
@@ -910,7 +944,7 @@ static bool node_is_compatible(struct node *node, const char *compat)
910 944
911 for (str = prop->val.val, end = str + prop->val.len; str < end; 945 for (str = prop->val.val, end = str + prop->val.len; str < end;
912 str += strnlen(str, end - str) + 1) { 946 str += strnlen(str, end - str) + 1) {
913 if (strprefixeq(str, end - str, compat)) 947 if (streq(str, compat))
914 return true; 948 return true;
915 } 949 }
916 return false; 950 return false;
@@ -921,7 +955,8 @@ static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct
921 if (node_is_compatible(node, "simple-bus")) 955 if (node_is_compatible(node, "simple-bus"))
922 node->bus = &simple_bus; 956 node->bus = &simple_bus;
923} 957}
924WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL, &addr_size_cells); 958WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL,
959 &addr_size_cells, &compatible_is_string_list);
925 960
926static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node) 961static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
927{ 962{
@@ -1035,6 +1070,7 @@ static const struct bus_type spi_bus = {
1035 1070
1036static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node) 1071static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
1037{ 1072{
1073 int spi_addr_cells = 1;
1038 1074
1039 if (strprefixeq(node->name, node->basenamelen, "spi")) { 1075 if (strprefixeq(node->name, node->basenamelen, "spi")) {
1040 node->bus = &spi_bus; 1076 node->bus = &spi_bus;
@@ -1063,7 +1099,9 @@ static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct no
1063 if (node->bus != &spi_bus || !node->children) 1099 if (node->bus != &spi_bus || !node->children)
1064 return; 1100 return;
1065 1101
1066 if (node_addr_cells(node) != 1) 1102 if (get_property(node, "spi-slave"))
1103 spi_addr_cells = 0;
1104 if (node_addr_cells(node) != spi_addr_cells)
1067 FAIL(c, dti, node, "incorrect #address-cells for SPI bus"); 1105 FAIL(c, dti, node, "incorrect #address-cells for SPI bus");
1068 if (node_size_cells(node) != 0) 1106 if (node_size_cells(node) != 0)
1069 FAIL(c, dti, node, "incorrect #size-cells for SPI bus"); 1107 FAIL(c, dti, node, "incorrect #size-cells for SPI bus");
@@ -1082,6 +1120,9 @@ static void check_spi_bus_reg(struct check *c, struct dt_info *dti, struct node
1082 if (!node->parent || (node->parent->bus != &spi_bus)) 1120 if (!node->parent || (node->parent->bus != &spi_bus))
1083 return; 1121 return;
1084 1122
1123 if (get_property(node->parent, "spi-slave"))
1124 return;
1125
1085 prop = get_property(node, "reg"); 1126 prop = get_property(node, "reg");
1086 if (prop) 1127 if (prop)
1087 cells = (cell_t *)prop->val.val; 1128 cells = (cell_t *)prop->val.val;
diff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l
index 615b7ec6588f..06c040902444 100644
--- a/scripts/dtc/dtc-lexer.l
+++ b/scripts/dtc/dtc-lexer.l
@@ -213,14 +213,14 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
213<*>\&{LABEL} { /* label reference */ 213<*>\&{LABEL} { /* label reference */
214 DPRINT("Ref: %s\n", yytext+1); 214 DPRINT("Ref: %s\n", yytext+1);
215 yylval.labelref = xstrdup(yytext+1); 215 yylval.labelref = xstrdup(yytext+1);
216 return DT_REF; 216 return DT_LABEL_REF;
217 } 217 }
218 218
219<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */ 219<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
220 yytext[yyleng-1] = '\0'; 220 yytext[yyleng-1] = '\0';
221 DPRINT("Ref: %s\n", yytext+2); 221 DPRINT("Ref: %s\n", yytext+2);
222 yylval.labelref = xstrdup(yytext+2); 222 yylval.labelref = xstrdup(yytext+2);
223 return DT_REF; 223 return DT_PATH_REF;
224 } 224 }
225 225
226<BYTESTRING>[0-9a-fA-F]{2} { 226<BYTESTRING>[0-9a-fA-F]{2} {
diff --git a/scripts/dtc/dtc-parser.y b/scripts/dtc/dtc-parser.y
index dd70ebf386f4..2ec981e86111 100644
--- a/scripts/dtc/dtc-parser.y
+++ b/scripts/dtc/dtc-parser.y
@@ -70,7 +70,8 @@ extern bool treesource_error;
70%token <byte> DT_BYTE 70%token <byte> DT_BYTE
71%token <data> DT_STRING 71%token <data> DT_STRING
72%token <labelref> DT_LABEL 72%token <labelref> DT_LABEL
73%token <labelref> DT_REF 73%token <labelref> DT_LABEL_REF
74%token <labelref> DT_PATH_REF
74%token DT_INCBIN 75%token DT_INCBIN
75 76
76%type <data> propdata 77%type <data> propdata
@@ -83,6 +84,7 @@ extern bool treesource_error;
83%type <data> bytestring 84%type <data> bytestring
84%type <prop> propdef 85%type <prop> propdef
85%type <proplist> proplist 86%type <proplist> proplist
87%type <labelref> dt_ref
86 88
87%type <node> devicetree 89%type <node> devicetree
88%type <node> nodedef 90%type <node> nodedef
@@ -158,6 +160,8 @@ memreserve:
158 } 160 }
159 ; 161 ;
160 162
163dt_ref: DT_LABEL_REF | DT_PATH_REF;
164
161devicetree: 165devicetree:
162 '/' nodedef 166 '/' nodedef
163 { 167 {
@@ -167,7 +171,7 @@ devicetree:
167 { 171 {
168 $$ = merge_nodes($1, $3); 172 $$ = merge_nodes($1, $3);
169 } 173 }
170 | DT_REF nodedef 174 | dt_ref nodedef
171 { 175 {
172 /* 176 /*
173 * We rely on the rule being always: 177 * We rely on the rule being always:
@@ -176,9 +180,12 @@ devicetree:
176 */ 180 */
177 if (!($<flags>-1 & DTSF_PLUGIN)) 181 if (!($<flags>-1 & DTSF_PLUGIN))
178 ERROR(&@2, "Label or path %s not found", $1); 182 ERROR(&@2, "Label or path %s not found", $1);
179 $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1); 183 $$ = add_orphan_node(
184 name_node(build_node(NULL, NULL, NULL),
185 ""),
186 $2, $1);
180 } 187 }
181 | devicetree DT_LABEL DT_REF nodedef 188 | devicetree DT_LABEL dt_ref nodedef
182 { 189 {
183 struct node *target = get_node_by_ref($1, $3); 190 struct node *target = get_node_by_ref($1, $3);
184 191
@@ -189,7 +196,7 @@ devicetree:
189 ERROR(&@3, "Label or path %s not found", $3); 196 ERROR(&@3, "Label or path %s not found", $3);
190 $$ = $1; 197 $$ = $1;
191 } 198 }
192 | devicetree DT_REF nodedef 199 | devicetree DT_PATH_REF nodedef
193 { 200 {
194 /* 201 /*
195 * We rely on the rule being always: 202 * We rely on the rule being always:
@@ -208,7 +215,26 @@ devicetree:
208 } 215 }
209 $$ = $1; 216 $$ = $1;
210 } 217 }
211 | devicetree DT_DEL_NODE DT_REF ';' 218 | devicetree DT_LABEL_REF nodedef
219 {
220 struct node *target = get_node_by_ref($1, $2);
221
222 if (target) {
223 merge_nodes(target, $3);
224 } else {
225 /*
226 * We rely on the rule being always:
227 * versioninfo plugindecl memreserves devicetree
228 * so $-1 is what we want (plugindecl)
229 */
230 if ($<flags>-1 & DTSF_PLUGIN)
231 add_orphan_node($1, $3, $2);
232 else
233 ERROR(&@2, "Label or path %s not found", $2);
234 }
235 $$ = $1;
236 }
237 | devicetree DT_DEL_NODE dt_ref ';'
212 { 238 {
213 struct node *target = get_node_by_ref($1, $3); 239 struct node *target = get_node_by_ref($1, $3);
214 240
@@ -220,7 +246,7 @@ devicetree:
220 246
221 $$ = $1; 247 $$ = $1;
222 } 248 }
223 | devicetree DT_OMIT_NO_REF DT_REF ';' 249 | devicetree DT_OMIT_NO_REF dt_ref ';'
224 { 250 {
225 struct node *target = get_node_by_ref($1, $3); 251 struct node *target = get_node_by_ref($1, $3);
226 252
@@ -237,7 +263,7 @@ devicetree:
237nodedef: 263nodedef:
238 '{' proplist subnodes '}' ';' 264 '{' proplist subnodes '}' ';'
239 { 265 {
240 $$ = build_node($2, $3); 266 $$ = build_node($2, $3, &@$);
241 } 267 }
242 ; 268 ;
243 269
@@ -255,11 +281,11 @@ proplist:
255propdef: 281propdef:
256 DT_PROPNODENAME '=' propdata ';' 282 DT_PROPNODENAME '=' propdata ';'
257 { 283 {
258 $$ = build_property($1, $3); 284 $$ = build_property($1, $3, &@$);
259 } 285 }
260 | DT_PROPNODENAME ';' 286 | DT_PROPNODENAME ';'
261 { 287 {
262 $$ = build_property($1, empty_data); 288 $$ = build_property($1, empty_data, &@$);
263 } 289 }
264 | DT_DEL_PROP DT_PROPNODENAME ';' 290 | DT_DEL_PROP DT_PROPNODENAME ';'
265 { 291 {
@@ -285,7 +311,7 @@ propdata:
285 { 311 {
286 $$ = data_merge($1, $3); 312 $$ = data_merge($1, $3);
287 } 313 }
288 | propdataprefix DT_REF 314 | propdataprefix dt_ref
289 { 315 {
290 $1 = data_add_marker($1, TYPE_STRING, $2); 316 $1 = data_add_marker($1, TYPE_STRING, $2);
291 $$ = data_add_marker($1, REF_PATH, $2); 317 $$ = data_add_marker($1, REF_PATH, $2);
@@ -383,7 +409,7 @@ arrayprefix:
383 409
384 $$.data = data_append_integer($1.data, $2, $1.bits); 410 $$.data = data_append_integer($1.data, $2, $1.bits);
385 } 411 }
386 | arrayprefix DT_REF 412 | arrayprefix dt_ref
387 { 413 {
388 uint64_t val = ~0ULL >> (64 - $1.bits); 414 uint64_t val = ~0ULL >> (64 - $1.bits);
389 415
@@ -540,7 +566,7 @@ subnode:
540 } 566 }
541 | DT_DEL_NODE DT_PROPNODENAME ';' 567 | DT_DEL_NODE DT_PROPNODENAME ';'
542 { 568 {
543 $$ = name_node(build_node_delete(), $2); 569 $$ = name_node(build_node_delete(&@$), $2);
544 } 570 }
545 | DT_OMIT_NO_REF subnode 571 | DT_OMIT_NO_REF subnode
546 { 572 {
diff --git a/scripts/dtc/dtc.c b/scripts/dtc/dtc.c
index 64134aadb997..695e1f789fc7 100644
--- a/scripts/dtc/dtc.c
+++ b/scripts/dtc/dtc.c
@@ -35,6 +35,8 @@ int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties *
35int generate_symbols; /* enable symbols & fixup support */ 35int generate_symbols; /* enable symbols & fixup support */
36int generate_fixups; /* suppress generation of fixups on symbol support */ 36int generate_fixups; /* suppress generation of fixups on symbol support */
37int auto_label_aliases; /* auto generate labels -> aliases */ 37int auto_label_aliases; /* auto generate labels -> aliases */
38int annotate; /* Level of annotation: 1 for input source location
39 >1 for full input source location. */
38 40
39static int is_power_of_2(int x) 41static int is_power_of_2(int x)
40{ 42{
@@ -60,7 +62,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
60 62
61/* Usage related data. */ 63/* Usage related data. */
62static const char usage_synopsis[] = "dtc [options] <input file>"; 64static const char usage_synopsis[] = "dtc [options] <input file>";
63static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv"; 65static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv";
64static struct option const usage_long_opts[] = { 66static struct option const usage_long_opts[] = {
65 {"quiet", no_argument, NULL, 'q'}, 67 {"quiet", no_argument, NULL, 'q'},
66 {"in-format", a_argument, NULL, 'I'}, 68 {"in-format", a_argument, NULL, 'I'},
@@ -81,6 +83,7 @@ static struct option const usage_long_opts[] = {
81 {"error", a_argument, NULL, 'E'}, 83 {"error", a_argument, NULL, 'E'},
82 {"symbols", no_argument, NULL, '@'}, 84 {"symbols", no_argument, NULL, '@'},
83 {"auto-alias", no_argument, NULL, 'A'}, 85 {"auto-alias", no_argument, NULL, 'A'},
86 {"annotate", no_argument, NULL, 'T'},
84 {"help", no_argument, NULL, 'h'}, 87 {"help", no_argument, NULL, 'h'},
85 {"version", no_argument, NULL, 'v'}, 88 {"version", no_argument, NULL, 'v'},
86 {NULL, no_argument, NULL, 0x0}, 89 {NULL, no_argument, NULL, 0x0},
@@ -117,6 +120,7 @@ static const char * const usage_opts_help[] = {
117 "\n\tEnable/disable errors (prefix with \"no-\")", 120 "\n\tEnable/disable errors (prefix with \"no-\")",
118 "\n\tEnable generation of symbols", 121 "\n\tEnable generation of symbols",
119 "\n\tEnable auto-alias of labels", 122 "\n\tEnable auto-alias of labels",
123 "\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
120 "\n\tPrint this help and exit", 124 "\n\tPrint this help and exit",
121 "\n\tPrint version and exit", 125 "\n\tPrint version and exit",
122 NULL, 126 NULL,
@@ -264,6 +268,9 @@ int main(int argc, char *argv[])
264 case 'A': 268 case 'A':
265 auto_label_aliases = 1; 269 auto_label_aliases = 1;
266 break; 270 break;
271 case 'T':
272 annotate++;
273 break;
267 274
268 case 'h': 275 case 'h':
269 usage(NULL); 276 usage(NULL);
@@ -302,6 +309,8 @@ int main(int argc, char *argv[])
302 outform = "dts"; 309 outform = "dts";
303 } 310 }
304 } 311 }
312 if (annotate && (!streq(inform, "dts") || !streq(outform, "dts")))
313 die("--annotate requires -I dts -O dts\n");
305 if (streq(inform, "dts")) 314 if (streq(inform, "dts"))
306 dti = dt_from_source(arg); 315 dti = dt_from_source(arg);
307 else if (streq(inform, "fs")) 316 else if (streq(inform, "fs"))
diff --git a/scripts/dtc/dtc.h b/scripts/dtc/dtc.h
index cbe541525c2c..789e0b1bc057 100644
--- a/scripts/dtc/dtc.h
+++ b/scripts/dtc/dtc.h
@@ -58,6 +58,7 @@ extern int phandle_format; /* Use linux,phandle or phandle properties */
58extern int generate_symbols; /* generate symbols for nodes with labels */ 58extern int generate_symbols; /* generate symbols for nodes with labels */
59extern int generate_fixups; /* generate fixups */ 59extern int generate_fixups; /* generate fixups */
60extern int auto_label_aliases; /* auto generate labels -> aliases */ 60extern int auto_label_aliases; /* auto generate labels -> aliases */
61extern int annotate; /* annotate .dts with input source location */
61 62
62#define PHANDLE_LEGACY 0x1 63#define PHANDLE_LEGACY 0x1
63#define PHANDLE_EPAPR 0x2 64#define PHANDLE_EPAPR 0x2
@@ -158,6 +159,7 @@ struct property {
158 struct property *next; 159 struct property *next;
159 160
160 struct label *labels; 161 struct label *labels;
162 struct srcpos *srcpos;
161}; 163};
162 164
163struct node { 165struct node {
@@ -177,6 +179,7 @@ struct node {
177 179
178 struct label *labels; 180 struct label *labels;
179 const struct bus_type *bus; 181 const struct bus_type *bus;
182 struct srcpos *srcpos;
180 183
181 bool omit_if_unused, is_referenced; 184 bool omit_if_unused, is_referenced;
182}; 185};
@@ -205,13 +208,15 @@ struct node {
205void add_label(struct label **labels, char *label); 208void add_label(struct label **labels, char *label);
206void delete_labels(struct label **labels); 209void delete_labels(struct label **labels);
207 210
208struct property *build_property(char *name, struct data val); 211struct property *build_property(char *name, struct data val,
212 struct srcpos *srcpos);
209struct property *build_property_delete(char *name); 213struct property *build_property_delete(char *name);
210struct property *chain_property(struct property *first, struct property *list); 214struct property *chain_property(struct property *first, struct property *list);
211struct property *reverse_properties(struct property *first); 215struct property *reverse_properties(struct property *first);
212 216
213struct node *build_node(struct property *proplist, struct node *children); 217struct node *build_node(struct property *proplist, struct node *children,
214struct node *build_node_delete(void); 218 struct srcpos *srcpos);
219struct node *build_node_delete(struct srcpos *srcpos);
215struct node *name_node(struct node *node, char *name); 220struct node *name_node(struct node *node, char *name);
216struct node *omit_node_if_unused(struct node *node); 221struct node *omit_node_if_unused(struct node *node);
217struct node *reference_node(struct node *node); 222struct node *reference_node(struct node *node);
diff --git a/scripts/dtc/flattree.c b/scripts/dtc/flattree.c
index 851ea87dbc0f..acf04c30669f 100644
--- a/scripts/dtc/flattree.c
+++ b/scripts/dtc/flattree.c
@@ -692,7 +692,7 @@ static struct property *flat_read_property(struct inbuf *dtbuf,
692 692
693 val = flat_read_data(dtbuf, proplen); 693 val = flat_read_data(dtbuf, proplen);
694 694
695 return build_property(name, val); 695 return build_property(name, val, NULL);
696} 696}
697 697
698 698
@@ -750,7 +750,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
750 char *flatname; 750 char *flatname;
751 uint32_t val; 751 uint32_t val;
752 752
753 node = build_node(NULL, NULL); 753 node = build_node(NULL, NULL, NULL);
754 754
755 flatname = flat_read_string(dtbuf); 755 flatname = flat_read_string(dtbuf);
756 756
diff --git a/scripts/dtc/fstree.c b/scripts/dtc/fstree.c
index ae7d06c3c492..1e7eeba47ff6 100644
--- a/scripts/dtc/fstree.c
+++ b/scripts/dtc/fstree.c
@@ -34,7 +34,7 @@ static struct node *read_fstree(const char *dirname)
34 if (!d) 34 if (!d)
35 die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno)); 35 die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
36 36
37 tree = build_node(NULL, NULL); 37 tree = build_node(NULL, NULL, NULL);
38 38
39 while ((de = readdir(d)) != NULL) { 39 while ((de = readdir(d)) != NULL) {
40 char *tmpname; 40 char *tmpname;
@@ -60,7 +60,8 @@ static struct node *read_fstree(const char *dirname)
60 } else { 60 } else {
61 prop = build_property(xstrdup(de->d_name), 61 prop = build_property(xstrdup(de->d_name),
62 data_copy_file(pfile, 62 data_copy_file(pfile,
63 st.st_size)); 63 st.st_size),
64 NULL);
64 add_property(tree, prop); 65 add_property(tree, prop);
65 fclose(pfile); 66 fclose(pfile);
66 } 67 }
diff --git a/scripts/dtc/libfdt/Makefile.libfdt b/scripts/dtc/libfdt/Makefile.libfdt
index 098b3f36e668..3af3656df801 100644
--- a/scripts/dtc/libfdt/Makefile.libfdt
+++ b/scripts/dtc/libfdt/Makefile.libfdt
@@ -9,3 +9,7 @@ LIBFDT_VERSION = version.lds
9LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ 9LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \
10 fdt_addresses.c fdt_overlay.c 10 fdt_addresses.c fdt_overlay.c
11LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 11LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
12
13libfdt_clean:
14 @$(VECHO) CLEAN "(libfdt)"
15 rm -f $(STD_CLEANFILES:%=$(LIBFDT_dir)/%)
diff --git a/scripts/dtc/libfdt/fdt_addresses.c b/scripts/dtc/libfdt/fdt_addresses.c
index 49537b578d03..f13a87dfa068 100644
--- a/scripts/dtc/libfdt/fdt_addresses.c
+++ b/scripts/dtc/libfdt/fdt_addresses.c
@@ -64,7 +64,7 @@ static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
64 64
65 c = fdt_getprop(fdt, nodeoffset, name, &len); 65 c = fdt_getprop(fdt, nodeoffset, name, &len);
66 if (!c) 66 if (!c)
67 return 2; 67 return len;
68 68
69 if (len != sizeof(*c)) 69 if (len != sizeof(*c))
70 return -FDT_ERR_BADNCELLS; 70 return -FDT_ERR_BADNCELLS;
@@ -78,10 +78,20 @@ static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
78 78
79int fdt_address_cells(const void *fdt, int nodeoffset) 79int fdt_address_cells(const void *fdt, int nodeoffset)
80{ 80{
81 return fdt_cells(fdt, nodeoffset, "#address-cells"); 81 int val;
82
83 val = fdt_cells(fdt, nodeoffset, "#address-cells");
84 if (val == -FDT_ERR_NOTFOUND)
85 return 2;
86 return val;
82} 87}
83 88
84int fdt_size_cells(const void *fdt, int nodeoffset) 89int fdt_size_cells(const void *fdt, int nodeoffset)
85{ 90{
86 return fdt_cells(fdt, nodeoffset, "#size-cells"); 91 int val;
92
93 val = fdt_cells(fdt, nodeoffset, "#size-cells");
94 if (val == -FDT_ERR_NOTFOUND)
95 return 1;
96 return val;
87} 97}
diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
index 2bd151dd355f..627da2e079c9 100644
--- a/scripts/dtc/libfdt/libfdt.h
+++ b/scripts/dtc/libfdt/libfdt.h
@@ -163,18 +163,26 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
163 163
164static inline uint32_t fdt32_ld(const fdt32_t *p) 164static inline uint32_t fdt32_ld(const fdt32_t *p)
165{ 165{
166 fdt32_t v; 166 const uint8_t *bp = (const uint8_t *)p;
167 167
168 memcpy(&v, p, sizeof(v)); 168 return ((uint32_t)bp[0] << 24)
169 return fdt32_to_cpu(v); 169 | ((uint32_t)bp[1] << 16)
170 | ((uint32_t)bp[2] << 8)
171 | bp[3];
170} 172}
171 173
172static inline uint64_t fdt64_ld(const fdt64_t *p) 174static inline uint64_t fdt64_ld(const fdt64_t *p)
173{ 175{
174 fdt64_t v; 176 const uint8_t *bp = (const uint8_t *)p;
175 177
176 memcpy(&v, p, sizeof(v)); 178 return ((uint64_t)bp[0] << 56)
177 return fdt64_to_cpu(v); 179 | ((uint64_t)bp[1] << 48)
180 | ((uint64_t)bp[2] << 40)
181 | ((uint64_t)bp[3] << 32)
182 | ((uint64_t)bp[4] << 24)
183 | ((uint64_t)bp[5] << 16)
184 | ((uint64_t)bp[6] << 8)
185 | bp[7];
178} 186}
179 187
180/**********************************************************************/ 188/**********************************************************************/
@@ -1145,7 +1153,7 @@ int fdt_address_cells(const void *fdt, int nodeoffset);
1145 * 1153 *
1146 * returns: 1154 * returns:
1147 * 0 <= n < FDT_MAX_NCELLS, on success 1155 * 0 <= n < FDT_MAX_NCELLS, on success
1148 * 2, if the node has no #size-cells property 1156 * 1, if the node has no #size-cells property
1149 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid 1157 * -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
1150 * #size-cells property 1158 * #size-cells property
1151 * -FDT_ERR_BADMAGIC, 1159 * -FDT_ERR_BADMAGIC,
diff --git a/scripts/dtc/livetree.c b/scripts/dtc/livetree.c
index 4ff0679e0062..7a2e6446a17b 100644
--- a/scripts/dtc/livetree.c
+++ b/scripts/dtc/livetree.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "dtc.h" 21#include "dtc.h"
22#include "srcpos.h"
22 23
23/* 24/*
24 * Tree building functions 25 * Tree building functions
@@ -50,7 +51,8 @@ void delete_labels(struct label **labels)
50 label->deleted = 1; 51 label->deleted = 1;
51} 52}
52 53
53struct property *build_property(char *name, struct data val) 54struct property *build_property(char *name, struct data val,
55 struct srcpos *srcpos)
54{ 56{
55 struct property *new = xmalloc(sizeof(*new)); 57 struct property *new = xmalloc(sizeof(*new));
56 58
@@ -58,6 +60,7 @@ struct property *build_property(char *name, struct data val)
58 60
59 new->name = name; 61 new->name = name;
60 new->val = val; 62 new->val = val;
63 new->srcpos = srcpos_copy(srcpos);
61 64
62 return new; 65 return new;
63} 66}
@@ -97,7 +100,8 @@ struct property *reverse_properties(struct property *first)
97 return head; 100 return head;
98} 101}
99 102
100struct node *build_node(struct property *proplist, struct node *children) 103struct node *build_node(struct property *proplist, struct node *children,
104 struct srcpos *srcpos)
101{ 105{
102 struct node *new = xmalloc(sizeof(*new)); 106 struct node *new = xmalloc(sizeof(*new));
103 struct node *child; 107 struct node *child;
@@ -106,6 +110,7 @@ struct node *build_node(struct property *proplist, struct node *children)
106 110
107 new->proplist = reverse_properties(proplist); 111 new->proplist = reverse_properties(proplist);
108 new->children = children; 112 new->children = children;
113 new->srcpos = srcpos_copy(srcpos);
109 114
110 for_each_child(new, child) { 115 for_each_child(new, child) {
111 child->parent = new; 116 child->parent = new;
@@ -114,13 +119,14 @@ struct node *build_node(struct property *proplist, struct node *children)
114 return new; 119 return new;
115} 120}
116 121
117struct node *build_node_delete(void) 122struct node *build_node_delete(struct srcpos *srcpos)
118{ 123{
119 struct node *new = xmalloc(sizeof(*new)); 124 struct node *new = xmalloc(sizeof(*new));
120 125
121 memset(new, 0, sizeof(*new)); 126 memset(new, 0, sizeof(*new));
122 127
123 new->deleted = 1; 128 new->deleted = 1;
129 new->srcpos = srcpos_copy(srcpos);
124 130
125 return new; 131 return new;
126} 132}
@@ -183,6 +189,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
183 189
184 old_prop->val = new_prop->val; 190 old_prop->val = new_prop->val;
185 old_prop->deleted = 0; 191 old_prop->deleted = 0;
192 free(old_prop->srcpos);
193 old_prop->srcpos = new_prop->srcpos;
186 free(new_prop); 194 free(new_prop);
187 new_prop = NULL; 195 new_prop = NULL;
188 break; 196 break;
@@ -223,6 +231,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
223 add_child(old_node, new_child); 231 add_child(old_node, new_child);
224 } 232 }
225 233
234 old_node->srcpos = srcpos_extend(old_node->srcpos, new_node->srcpos);
235
226 /* The new node contents are now merged into the old node. Free 236 /* The new node contents are now merged into the old node. Free
227 * the new node. */ 237 * the new node. */
228 free(new_node); 238 free(new_node);
@@ -241,18 +251,18 @@ struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
241 if (ref[0] == '/') { 251 if (ref[0] == '/') {
242 d = data_append_data(d, ref, strlen(ref) + 1); 252 d = data_append_data(d, ref, strlen(ref) + 1);
243 253
244 p = build_property("target-path", d); 254 p = build_property("target-path", d, NULL);
245 } else { 255 } else {
246 d = data_add_marker(d, REF_PHANDLE, ref); 256 d = data_add_marker(d, REF_PHANDLE, ref);
247 d = data_append_integer(d, 0xffffffff, 32); 257 d = data_append_integer(d, 0xffffffff, 32);
248 258
249 p = build_property("target", d); 259 p = build_property("target", d, NULL);
250 } 260 }
251 261
252 xasprintf(&name, "fragment@%u", 262 xasprintf(&name, "fragment@%u",
253 next_orphan_fragment++); 263 next_orphan_fragment++);
254 name_node(new_node, "__overlay__"); 264 name_node(new_node, "__overlay__");
255 node = build_node(p, new_node); 265 node = build_node(p, new_node, NULL);
256 name_node(node, name); 266 name_node(node, name);
257 267
258 add_child(dt, node); 268 add_child(dt, node);
@@ -351,7 +361,7 @@ void append_to_property(struct node *node,
351 p->val = d; 361 p->val = d;
352 } else { 362 } else {
353 d = data_append_data(empty_data, data, len); 363 d = data_append_data(empty_data, data, len);
354 p = build_property(name, d); 364 p = build_property(name, d, NULL);
355 add_property(node, p); 365 add_property(node, p);
356 } 366 }
357} 367}
@@ -609,11 +619,11 @@ cell_t get_node_phandle(struct node *root, struct node *node)
609 619
610 if (!get_property(node, "linux,phandle") 620 if (!get_property(node, "linux,phandle")
611 && (phandle_format & PHANDLE_LEGACY)) 621 && (phandle_format & PHANDLE_LEGACY))
612 add_property(node, build_property("linux,phandle", d)); 622 add_property(node, build_property("linux,phandle", d, NULL));
613 623
614 if (!get_property(node, "phandle") 624 if (!get_property(node, "phandle")
615 && (phandle_format & PHANDLE_EPAPR)) 625 && (phandle_format & PHANDLE_EPAPR))
616 add_property(node, build_property("phandle", d)); 626 add_property(node, build_property("phandle", d, NULL));
617 627
618 /* If the node *does* have a phandle property, we must 628 /* If the node *does* have a phandle property, we must
619 * be dealing with a self-referencing phandle, which will be 629 * be dealing with a self-referencing phandle, which will be
@@ -787,7 +797,7 @@ static struct node *build_and_name_child_node(struct node *parent, char *name)
787{ 797{
788 struct node *node; 798 struct node *node;
789 799
790 node = build_node(NULL, NULL); 800 node = build_node(NULL, NULL, NULL);
791 name_node(node, xstrdup(name)); 801 name_node(node, xstrdup(name));
792 add_child(parent, node); 802 add_child(parent, node);
793 803
@@ -849,7 +859,8 @@ static void generate_label_tree_internal(struct dt_info *dti,
849 /* insert it */ 859 /* insert it */
850 p = build_property(l->label, 860 p = build_property(l->label,
851 data_copy_mem(node->fullpath, 861 data_copy_mem(node->fullpath,
852 strlen(node->fullpath) + 1)); 862 strlen(node->fullpath) + 1),
863 NULL);
853 add_property(an, p); 864 add_property(an, p);
854 } 865 }
855 866
diff --git a/scripts/dtc/srcpos.c b/scripts/dtc/srcpos.c
index cb6ed0e3e5e4..41f83700ee91 100644
--- a/scripts/dtc/srcpos.c
+++ b/scripts/dtc/srcpos.c
@@ -33,6 +33,9 @@ struct search_path {
33/* This is the list of directories that we search for source files */ 33/* This is the list of directories that we search for source files */
34static struct search_path *search_path_head, **search_path_tail; 34static struct search_path *search_path_head, **search_path_tail;
35 35
36/* Detect infinite include recursion. */
37#define MAX_SRCFILE_DEPTH (100)
38static int srcfile_depth; /* = 0 */
36 39
37static char *get_dirname(const char *path) 40static char *get_dirname(const char *path)
38{ 41{
@@ -51,11 +54,51 @@ static char *get_dirname(const char *path)
51 54
52FILE *depfile; /* = NULL */ 55FILE *depfile; /* = NULL */
53struct srcfile_state *current_srcfile; /* = NULL */ 56struct srcfile_state *current_srcfile; /* = NULL */
57static char *initial_path; /* = NULL */
58static int initial_pathlen; /* = 0 */
59static bool initial_cpp = true;
54 60
55/* Detect infinite include recursion. */ 61static void set_initial_path(char *fname)
56#define MAX_SRCFILE_DEPTH (100) 62{
57static int srcfile_depth; /* = 0 */ 63 int i, len = strlen(fname);
58 64
65 xasprintf(&initial_path, "%s", fname);
66 initial_pathlen = 0;
67 for (i = 0; i != len; i++)
68 if (initial_path[i] == '/')
69 initial_pathlen++;
70}
71
72static char *shorten_to_initial_path(char *fname)
73{
74 char *p1, *p2, *prevslash1 = NULL;
75 int slashes = 0;
76
77 for (p1 = fname, p2 = initial_path; *p1 && *p2; p1++, p2++) {
78 if (*p1 != *p2)
79 break;
80 if (*p1 == '/') {
81 prevslash1 = p1;
82 slashes++;
83 }
84 }
85 p1 = prevslash1 + 1;
86 if (prevslash1) {
87 int diff = initial_pathlen - slashes, i, j;
88 int restlen = strlen(fname) - (p1 - fname);
89 char *res;
90
91 res = xmalloc((3 * diff) + restlen + 1);
92 for (i = 0, j = 0; i != diff; i++) {
93 res[j++] = '.';
94 res[j++] = '.';
95 res[j++] = '/';
96 }
97 strcpy(res + j, p1);
98 return res;
99 }
100 return NULL;
101}
59 102
60/** 103/**
61 * Try to open a file in a given directory. 104 * Try to open a file in a given directory.
@@ -157,6 +200,9 @@ void srcfile_push(const char *fname)
157 srcfile->colno = 1; 200 srcfile->colno = 1;
158 201
159 current_srcfile = srcfile; 202 current_srcfile = srcfile;
203
204 if (srcfile_depth == 1)
205 set_initial_path(srcfile->name);
160} 206}
161 207
162bool srcfile_pop(void) 208bool srcfile_pop(void)
@@ -197,18 +243,6 @@ void srcfile_add_search_path(const char *dirname)
197 search_path_tail = &node->next; 243 search_path_tail = &node->next;
198} 244}
199 245
200/*
201 * The empty source position.
202 */
203
204struct srcpos srcpos_empty = {
205 .first_line = 0,
206 .first_column = 0,
207 .last_line = 0,
208 .last_column = 0,
209 .file = NULL,
210};
211
212void srcpos_update(struct srcpos *pos, const char *text, int len) 246void srcpos_update(struct srcpos *pos, const char *text, int len)
213{ 247{
214 int i; 248 int i;
@@ -234,13 +268,35 @@ struct srcpos *
234srcpos_copy(struct srcpos *pos) 268srcpos_copy(struct srcpos *pos)
235{ 269{
236 struct srcpos *pos_new; 270 struct srcpos *pos_new;
271 struct srcfile_state *srcfile_state;
272
273 if (!pos)
274 return NULL;
237 275
238 pos_new = xmalloc(sizeof(struct srcpos)); 276 pos_new = xmalloc(sizeof(struct srcpos));
277 assert(pos->next == NULL);
239 memcpy(pos_new, pos, sizeof(struct srcpos)); 278 memcpy(pos_new, pos, sizeof(struct srcpos));
240 279
280 /* allocate without free */
281 srcfile_state = xmalloc(sizeof(struct srcfile_state));
282 memcpy(srcfile_state, pos->file, sizeof(struct srcfile_state));
283 pos_new->file = srcfile_state;
284
241 return pos_new; 285 return pos_new;
242} 286}
243 287
288struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
289{
290 struct srcpos *p;
291
292 if (!pos)
293 return newtail;
294
295 for (p = pos; p->next != NULL; p = p->next);
296 p->next = newtail;
297 return pos;
298}
299
244char * 300char *
245srcpos_string(struct srcpos *pos) 301srcpos_string(struct srcpos *pos)
246{ 302{
@@ -266,6 +322,68 @@ srcpos_string(struct srcpos *pos)
266 return pos_str; 322 return pos_str;
267} 323}
268 324
325static char *
326srcpos_string_comment(struct srcpos *pos, bool first_line, int level)
327{
328 char *pos_str, *fname, *first, *rest;
329 bool fresh_fname = false;
330
331 if (!pos) {
332 if (level > 1) {
333 xasprintf(&pos_str, "<no-file>:<no-line>");
334 return pos_str;
335 } else {
336 return NULL;
337 }
338 }
339
340 if (!pos->file)
341 fname = "<no-file>";
342 else if (!pos->file->name)
343 fname = "<no-filename>";
344 else if (level > 1)
345 fname = pos->file->name;
346 else {
347 fname = shorten_to_initial_path(pos->file->name);
348 if (fname)
349 fresh_fname = true;
350 else
351 fname = pos->file->name;
352 }
353
354 if (level > 1)
355 xasprintf(&first, "%s:%d:%d-%d:%d", fname,
356 pos->first_line, pos->first_column,
357 pos->last_line, pos->last_column);
358 else
359 xasprintf(&first, "%s:%d", fname,
360 first_line ? pos->first_line : pos->last_line);
361
362 if (fresh_fname)
363 free(fname);
364
365 if (pos->next != NULL) {
366 rest = srcpos_string_comment(pos->next, first_line, level);
367 xasprintf(&pos_str, "%s, %s", first, rest);
368 free(first);
369 free(rest);
370 } else {
371 pos_str = first;
372 }
373
374 return pos_str;
375}
376
377char *srcpos_string_first(struct srcpos *pos, int level)
378{
379 return srcpos_string_comment(pos, true, level);
380}
381
382char *srcpos_string_last(struct srcpos *pos, int level)
383{
384 return srcpos_string_comment(pos, false, level);
385}
386
269void srcpos_verror(struct srcpos *pos, const char *prefix, 387void srcpos_verror(struct srcpos *pos, const char *prefix,
270 const char *fmt, va_list va) 388 const char *fmt, va_list va)
271{ 389{
@@ -294,4 +412,9 @@ void srcpos_set_line(char *f, int l)
294{ 412{
295 current_srcfile->name = f; 413 current_srcfile->name = f;
296 current_srcfile->lineno = l; 414 current_srcfile->lineno = l;
415
416 if (initial_cpp) {
417 initial_cpp = false;
418 set_initial_path(f);
419 }
297} 420}
diff --git a/scripts/dtc/srcpos.h b/scripts/dtc/srcpos.h
index 9ded12a3830a..6326a952c40e 100644
--- a/scripts/dtc/srcpos.h
+++ b/scripts/dtc/srcpos.h
@@ -74,6 +74,7 @@ struct srcpos {
74 int last_line; 74 int last_line;
75 int last_column; 75 int last_column;
76 struct srcfile_state *file; 76 struct srcfile_state *file;
77 struct srcpos *next;
77}; 78};
78 79
79#define YYLTYPE struct srcpos 80#define YYLTYPE struct srcpos
@@ -93,19 +94,18 @@ struct srcpos {
93 YYRHSLOC(Rhs, 0).last_column; \ 94 YYRHSLOC(Rhs, 0).last_column; \
94 (Current).file = YYRHSLOC (Rhs, 0).file; \ 95 (Current).file = YYRHSLOC (Rhs, 0).file; \
95 } \ 96 } \
97 (Current).next = NULL; \
96 } while (0) 98 } while (0)
97 99
98 100
99/*
100 * Fictional source position used for IR nodes that are
101 * created without otherwise knowing a true source position.
102 * For example,constant definitions from the command line.
103 */
104extern struct srcpos srcpos_empty;
105
106extern void srcpos_update(struct srcpos *pos, const char *text, int len); 101extern void srcpos_update(struct srcpos *pos, const char *text, int len);
107extern struct srcpos *srcpos_copy(struct srcpos *pos); 102extern struct srcpos *srcpos_copy(struct srcpos *pos);
103extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
104 struct srcpos *old_srcpos);
108extern char *srcpos_string(struct srcpos *pos); 105extern char *srcpos_string(struct srcpos *pos);
106extern char *srcpos_string_first(struct srcpos *pos, int level);
107extern char *srcpos_string_last(struct srcpos *pos, int level);
108
109 109
110extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix, 110extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
111 const char *fmt, va_list va); 111 const char *fmt, va_list va);
diff --git a/scripts/dtc/treesource.c b/scripts/dtc/treesource.c
index f2874f1d1465..1af36628b75f 100644
--- a/scripts/dtc/treesource.c
+++ b/scripts/dtc/treesource.c
@@ -64,6 +64,10 @@ static bool isstring(char c)
64static void write_propval_string(FILE *f, const char *s, size_t len) 64static void write_propval_string(FILE *f, const char *s, size_t len)
65{ 65{
66 const char *end = s + len - 1; 66 const char *end = s + len - 1;
67
68 if (!len)
69 return;
70
67 assert(*end == '\0'); 71 assert(*end == '\0');
68 72
69 fprintf(f, "\""); 73 fprintf(f, "\"");
@@ -118,18 +122,20 @@ static void write_propval_int(FILE *f, const char *p, size_t len, size_t width)
118 for (; p < end; p += width) { 122 for (; p < end; p += width) {
119 switch (width) { 123 switch (width) {
120 case 1: 124 case 1:
121 fprintf(f, " %02"PRIx8, *(const uint8_t*)p); 125 fprintf(f, "%02"PRIx8, *(const uint8_t*)p);
122 break; 126 break;
123 case 2: 127 case 2:
124 fprintf(f, " 0x%02"PRIx16, fdt16_to_cpu(*(const fdt16_t*)p)); 128 fprintf(f, "0x%02"PRIx16, fdt16_to_cpu(*(const fdt16_t*)p));
125 break; 129 break;
126 case 4: 130 case 4:
127 fprintf(f, " 0x%02"PRIx32, fdt32_to_cpu(*(const fdt32_t*)p)); 131 fprintf(f, "0x%02"PRIx32, fdt32_to_cpu(*(const fdt32_t*)p));
128 break; 132 break;
129 case 8: 133 case 8:
130 fprintf(f, " 0x%02"PRIx64, fdt64_to_cpu(*(const fdt64_t*)p)); 134 fprintf(f, "0x%02"PRIx64, fdt64_to_cpu(*(const fdt64_t*)p));
131 break; 135 break;
132 } 136 }
137 if (p + width < end)
138 fputc(' ', f);
133 } 139 }
134} 140}
135 141
@@ -162,10 +168,10 @@ static const char *delim_start[] = {
162 [TYPE_STRING] = "", 168 [TYPE_STRING] = "",
163}; 169};
164static const char *delim_end[] = { 170static const char *delim_end[] = {
165 [TYPE_UINT8] = " ]", 171 [TYPE_UINT8] = "]",
166 [TYPE_UINT16] = " >", 172 [TYPE_UINT16] = ">",
167 [TYPE_UINT32] = " >", 173 [TYPE_UINT32] = ">",
168 [TYPE_UINT64] = " >", 174 [TYPE_UINT64] = ">",
169 [TYPE_STRING] = "", 175 [TYPE_STRING] = "",
170}; 176};
171 177
@@ -208,13 +214,22 @@ static void write_propval(FILE *f, struct property *prop)
208 struct marker *m = prop->val.markers; 214 struct marker *m = prop->val.markers;
209 struct marker dummy_marker; 215 struct marker dummy_marker;
210 enum markertype emit_type = TYPE_NONE; 216 enum markertype emit_type = TYPE_NONE;
217 char *srcstr;
211 218
212 if (len == 0) { 219 if (len == 0) {
213 fprintf(f, ";\n"); 220 fprintf(f, ";");
221 if (annotate) {
222 srcstr = srcpos_string_first(prop->srcpos, annotate);
223 if (srcstr) {
224 fprintf(f, " /* %s */", srcstr);
225 free(srcstr);
226 }
227 }
228 fprintf(f, "\n");
214 return; 229 return;
215 } 230 }
216 231
217 fprintf(f, " = "); 232 fprintf(f, " =");
218 233
219 if (!next_type_marker(m)) { 234 if (!next_type_marker(m)) {
220 /* data type information missing, need to guess */ 235 /* data type information missing, need to guess */
@@ -225,32 +240,23 @@ static void write_propval(FILE *f, struct property *prop)
225 m = &dummy_marker; 240 m = &dummy_marker;
226 } 241 }
227 242
228 struct marker *m_label = prop->val.markers;
229 for_each_marker(m) { 243 for_each_marker(m) {
230 size_t chunk_len; 244 size_t chunk_len = (m->next ? m->next->offset : len) - m->offset;
245 size_t data_len = type_marker_length(m) ? : len - m->offset;
231 const char *p = &prop->val.val[m->offset]; 246 const char *p = &prop->val.val[m->offset];
232 247
233 if (!has_data_type_information(m)) 248 if (has_data_type_information(m)) {
234 continue; 249 emit_type = m->type;
235 250 fprintf(f, " %s", delim_start[emit_type]);
236 chunk_len = type_marker_length(m); 251 } else if (m->type == LABEL)
237 if (!chunk_len) 252 fprintf(f, " %s:", m->ref);
238 chunk_len = len - m->offset; 253 else if (m->offset)
239 254 fputc(' ', f);
240 if (emit_type != TYPE_NONE)
241 fprintf(f, "%s, ", delim_end[emit_type]);
242 emit_type = m->type;
243
244 for_each_marker_of_type(m_label, LABEL) {
245 if (m_label->offset > m->offset)
246 break;
247 fprintf(f, "%s: ", m_label->ref);
248 }
249
250 fprintf(f, "%s", delim_start[emit_type]);
251 255
252 if (chunk_len <= 0) 256 if (emit_type == TYPE_NONE) {
257 assert(chunk_len == 0);
253 continue; 258 continue;
259 }
254 260
255 switch(emit_type) { 261 switch(emit_type) {
256 case TYPE_UINT16: 262 case TYPE_UINT16:
@@ -268,15 +274,23 @@ static void write_propval(FILE *f, struct property *prop)
268 default: 274 default:
269 write_propval_int(f, p, chunk_len, 1); 275 write_propval_int(f, p, chunk_len, 1);
270 } 276 }
271 }
272 277
273 /* Wrap up any labels at the end of the value */ 278 if (chunk_len == data_len) {
274 for_each_marker_of_type(m_label, LABEL) { 279 size_t pos = m->offset + chunk_len;
275 assert (m_label->offset == len); 280 fprintf(f, pos == len ? "%s" : "%s,",
276 fprintf(f, " %s:", m_label->ref); 281 delim_end[emit_type] ? : "");
282 emit_type = TYPE_NONE;
283 }
277 } 284 }
278 285 fprintf(f, ";");
279 fprintf(f, "%s;\n", delim_end[emit_type] ? : ""); 286 if (annotate) {
287 srcstr = srcpos_string_first(prop->srcpos, annotate);
288 if (srcstr) {
289 fprintf(f, " /* %s */", srcstr);
290 free(srcstr);
291 }
292 }
293 fprintf(f, "\n");
280} 294}
281 295
282static void write_tree_source_node(FILE *f, struct node *tree, int level) 296static void write_tree_source_node(FILE *f, struct node *tree, int level)
@@ -284,14 +298,24 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
284 struct property *prop; 298 struct property *prop;
285 struct node *child; 299 struct node *child;
286 struct label *l; 300 struct label *l;
301 char *srcstr;
287 302
288 write_prefix(f, level); 303 write_prefix(f, level);
289 for_each_label(tree->labels, l) 304 for_each_label(tree->labels, l)
290 fprintf(f, "%s: ", l->label); 305 fprintf(f, "%s: ", l->label);
291 if (tree->name && (*tree->name)) 306 if (tree->name && (*tree->name))
292 fprintf(f, "%s {\n", tree->name); 307 fprintf(f, "%s {", tree->name);
293 else 308 else
294 fprintf(f, "/ {\n"); 309 fprintf(f, "/ {");
310
311 if (annotate) {
312 srcstr = srcpos_string_first(tree->srcpos, annotate);
313 if (srcstr) {
314 fprintf(f, " /* %s */", srcstr);
315 free(srcstr);
316 }
317 }
318 fprintf(f, "\n");
295 319
296 for_each_property(tree, prop) { 320 for_each_property(tree, prop) {
297 write_prefix(f, level+1); 321 write_prefix(f, level+1);
@@ -305,10 +329,17 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
305 write_tree_source_node(f, child, level+1); 329 write_tree_source_node(f, child, level+1);
306 } 330 }
307 write_prefix(f, level); 331 write_prefix(f, level);
308 fprintf(f, "};\n"); 332 fprintf(f, "};");
333 if (annotate) {
334 srcstr = srcpos_string_last(tree->srcpos, annotate);
335 if (srcstr) {
336 fprintf(f, " /* %s */", srcstr);
337 free(srcstr);
338 }
339 }
340 fprintf(f, "\n");
309} 341}
310 342
311
312void dt_to_source(FILE *f, struct dt_info *dti) 343void dt_to_source(FILE *f, struct dt_info *dti)
313{ 344{
314 struct reserve_info *re; 345 struct reserve_info *re;
diff --git a/scripts/dtc/util.c b/scripts/dtc/util.c
index a69b7a13463d..9c6fb5f286ae 100644
--- a/scripts/dtc/util.c
+++ b/scripts/dtc/util.c
@@ -46,36 +46,54 @@ char *xstrdup(const char *s)
46 return d; 46 return d;
47} 47}
48 48
49/* based in part from (3) vsnprintf */ 49int xavsprintf_append(char **strp, const char *fmt, va_list ap)
50int xasprintf(char **strp, const char *fmt, ...)
51{ 50{
52 int n, size = 128; /* start with 128 bytes */ 51 int n, size = 0; /* start with 128 bytes */
53 char *p; 52 char *p;
54 va_list ap; 53 va_list ap_copy;
55 54
56 /* initial pointer is NULL making the fist realloc to be malloc */ 55 p = *strp;
57 p = NULL; 56 if (p)
58 while (1) { 57 size = strlen(p);
59 p = xrealloc(p, size);
60 58
61 /* Try to print in the allocated space. */ 59 va_copy(ap_copy, ap);
62 va_start(ap, fmt); 60 n = vsnprintf(NULL, 0, fmt, ap_copy) + 1;
63 n = vsnprintf(p, size, fmt, ap); 61 va_end(ap_copy);
64 va_end(ap); 62
63 p = xrealloc(p, size + n);
64
65 n = vsnprintf(p + size, n, fmt, ap);
65 66
66 /* If that worked, return the string. */
67 if (n > -1 && n < size)
68 break;
69 /* Else try again with more space. */
70 if (n > -1) /* glibc 2.1 */
71 size = n + 1; /* precisely what is needed */
72 else /* glibc 2.0 */
73 size *= 2; /* twice the old size */
74 }
75 *strp = p; 67 *strp = p;
76 return strlen(p); 68 return strlen(p);
77} 69}
78 70
71int xasprintf_append(char **strp, const char *fmt, ...)
72{
73 int n;
74 va_list ap;
75
76 va_start(ap, fmt);
77 n = xavsprintf_append(strp, fmt, ap);
78 va_end(ap);
79
80 return n;
81}
82
83int xasprintf(char **strp, const char *fmt, ...)
84{
85 int n;
86 va_list ap;
87
88 *strp = NULL;
89
90 va_start(ap, fmt);
91 n = xavsprintf_append(strp, fmt, ap);
92 va_end(ap);
93
94 return n;
95}
96
79char *join_path(const char *path, const char *name) 97char *join_path(const char *path, const char *name)
80{ 98{
81 int lenp = strlen(path); 99 int lenp = strlen(path);
diff --git a/scripts/dtc/util.h b/scripts/dtc/util.h
index f6cea8274174..7658781a6200 100644
--- a/scripts/dtc/util.h
+++ b/scripts/dtc/util.h
@@ -72,6 +72,8 @@ static inline void *xrealloc(void *p, size_t len)
72extern char *xstrdup(const char *s); 72extern char *xstrdup(const char *s);
73 73
74extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...); 74extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...);
75extern int PRINTF(2, 3) xasprintf_append(char **strp, const char *fmt, ...);
76extern int xavsprintf_append(char **strp, const char *fmt, va_list ap);
75extern char *join_path(const char *path, const char *name); 77extern char *join_path(const char *path, const char *name);
76 78
77/** 79/**
diff --git a/scripts/dtc/version_gen.h b/scripts/dtc/version_gen.h
index 6d23fd095f16..75f383c0b9d3 100644
--- a/scripts/dtc/version_gen.h
+++ b/scripts/dtc/version_gen.h
@@ -1 +1 @@
#define DTC_VERSION "DTC 1.4.7-gc86da84d" #define DTC_VERSION "DTC 1.4.7-gf267e674"
diff --git a/scripts/gcc-goto.sh b/scripts/gcc-goto.sh
index 083c526073ef..8b980fb2270a 100755
--- a/scripts/gcc-goto.sh
+++ b/scripts/gcc-goto.sh
@@ -3,7 +3,7 @@
3# Test for gcc 'asm goto' support 3# Test for gcc 'asm goto' support
4# Copyright (C) 2010, Jason Baron <jbaron@redhat.com> 4# Copyright (C) 2010, Jason Baron <jbaron@redhat.com>
5 5
6cat << "END" | $@ -x c - -c -o /dev/null >/dev/null 2>&1 && echo "y" 6cat << "END" | $@ -x c - -fno-PIE -c -o /dev/null
7int main(void) 7int main(void)
8{ 8{
9#if defined(__arm__) || defined(__aarch64__) 9#if defined(__arm__) || defined(__aarch64__)
diff --git a/scripts/gcc-plugins/Kconfig b/scripts/gcc-plugins/Kconfig
index 0d5c799688f0..d45f7f36b859 100644
--- a/scripts/gcc-plugins/Kconfig
+++ b/scripts/gcc-plugins/Kconfig
@@ -190,4 +190,8 @@ config STACKLEAK_RUNTIME_DISABLE
190 runtime to control kernel stack erasing for kernels built with 190 runtime to control kernel stack erasing for kernels built with
191 CONFIG_GCC_PLUGIN_STACKLEAK. 191 CONFIG_GCC_PLUGIN_STACKLEAK.
192 192
193config GCC_PLUGIN_ARM_SSP_PER_TASK
194 bool
195 depends on GCC_PLUGINS && ARM
196
193endif 197endif
diff --git a/scripts/gcc-plugins/arm_ssp_per_task_plugin.c b/scripts/gcc-plugins/arm_ssp_per_task_plugin.c
new file mode 100644
index 000000000000..89c47f57d1ce
--- /dev/null
+++ b/scripts/gcc-plugins/arm_ssp_per_task_plugin.c
@@ -0,0 +1,122 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include "gcc-common.h"
4
5__visible int plugin_is_GPL_compatible;
6
7static unsigned int sp_mask, canary_offset;
8
9static unsigned int arm_pertask_ssp_rtl_execute(void)
10{
11 rtx_insn *insn;
12
13 for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
14 const char *sym;
15 rtx body;
16 rtx mask, masked_sp;
17
18 /*
19 * Find a SET insn involving a SYMBOL_REF to __stack_chk_guard
20 */
21 if (!INSN_P(insn))
22 continue;
23 body = PATTERN(insn);
24 if (GET_CODE(body) != SET ||
25 GET_CODE(SET_SRC(body)) != SYMBOL_REF)
26 continue;
27 sym = XSTR(SET_SRC(body), 0);
28 if (strcmp(sym, "__stack_chk_guard"))
29 continue;
30
31 /*
32 * Replace the source of the SET insn with an expression that
33 * produces the address of the copy of the stack canary value
34 * stored in struct thread_info
35 */
36 mask = GEN_INT(sext_hwi(sp_mask, GET_MODE_PRECISION(Pmode)));
37 masked_sp = gen_reg_rtx(Pmode);
38
39 emit_insn_before(gen_rtx_SET(masked_sp,
40 gen_rtx_AND(Pmode,
41 stack_pointer_rtx,
42 mask)),
43 insn);
44
45 SET_SRC(body) = gen_rtx_PLUS(Pmode, masked_sp,
46 GEN_INT(canary_offset));
47 }
48 return 0;
49}
50
51#define PASS_NAME arm_pertask_ssp_rtl
52
53#define NO_GATE
54#include "gcc-generate-rtl-pass.h"
55
56#if BUILDING_GCC_VERSION >= 9000
57static bool no(void)
58{
59 return false;
60}
61
62static void arm_pertask_ssp_start_unit(void *gcc_data, void *user_data)
63{
64 targetm.have_stack_protect_combined_set = no;
65 targetm.have_stack_protect_combined_test = no;
66}
67#endif
68
69__visible int plugin_init(struct plugin_name_args *plugin_info,
70 struct plugin_gcc_version *version)
71{
72 const char * const plugin_name = plugin_info->base_name;
73 const int argc = plugin_info->argc;
74 const struct plugin_argument *argv = plugin_info->argv;
75 int tso = 0;
76 int i;
77
78 if (!plugin_default_version_check(version, &gcc_version)) {
79 error(G_("incompatible gcc/plugin versions"));
80 return 1;
81 }
82
83 for (i = 0; i < argc; ++i) {
84 if (!strcmp(argv[i].key, "disable"))
85 return 0;
86
87 /* all remaining options require a value */
88 if (!argv[i].value) {
89 error(G_("no value supplied for option '-fplugin-arg-%s-%s'"),
90 plugin_name, argv[i].key);
91 return 1;
92 }
93
94 if (!strcmp(argv[i].key, "tso")) {
95 tso = atoi(argv[i].value);
96 continue;
97 }
98
99 if (!strcmp(argv[i].key, "offset")) {
100 canary_offset = atoi(argv[i].value);
101 continue;
102 }
103 error(G_("unknown option '-fplugin-arg-%s-%s'"),
104 plugin_name, argv[i].key);
105 return 1;
106 }
107
108 /* create the mask that produces the base of the stack */
109 sp_mask = ~((1U << (12 + tso)) - 1);
110
111 PASS_INFO(arm_pertask_ssp_rtl, "expand", 1, PASS_POS_INSERT_AFTER);
112
113 register_callback(plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP,
114 NULL, &arm_pertask_ssp_rtl_pass_info);
115
116#if BUILDING_GCC_VERSION >= 9000
117 register_callback(plugin_info->base_name, PLUGIN_START_UNIT,
118 arm_pertask_ssp_start_unit, NULL);
119#endif
120
121 return 0;
122}
diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c
index 2f48da98b5d4..dbd37460c573 100644
--- a/scripts/gcc-plugins/stackleak_plugin.c
+++ b/scripts/gcc-plugins/stackleak_plugin.c
@@ -363,10 +363,12 @@ __visible int plugin_init(struct plugin_name_args *plugin_info,
363 PASS_POS_INSERT_BEFORE); 363 PASS_POS_INSERT_BEFORE);
364 364
365 /* 365 /*
366 * The stackleak_cleanup pass should be executed after the 366 * The stackleak_cleanup pass should be executed before the "*free_cfg"
367 * "reload" pass, when the stack frame size is final. 367 * pass. It's the moment when the stack frame size is already final,
368 * function prologues and epilogues are generated, and the
369 * machine-dependent code transformations are not done.
368 */ 370 */
369 PASS_INFO(stackleak_cleanup, "reload", 1, PASS_POS_INSERT_AFTER); 371 PASS_INFO(stackleak_cleanup, "*free_cfg", 1, PASS_POS_INSERT_BEFORE);
370 372
371 if (!plugin_default_version_check(version, &gcc_version)) { 373 if (!plugin_default_version_check(version, &gcc_version)) {
372 error(G_("incompatible gcc/plugin versions")); 374 error(G_("incompatible gcc/plugin versions"));
diff --git a/scripts/gdb/linux/proc.py b/scripts/gdb/linux/proc.py
index 086d27223c0c..0aebd7565b03 100644
--- a/scripts/gdb/linux/proc.py
+++ b/scripts/gdb/linux/proc.py
@@ -41,7 +41,7 @@ class LxVersion(gdb.Command):
41 41
42 def invoke(self, arg, from_tty): 42 def invoke(self, arg, from_tty):
43 # linux_banner should contain a newline 43 # linux_banner should contain a newline
44 gdb.write(gdb.parse_and_eval("linux_banner").string()) 44 gdb.write(gdb.parse_and_eval("(char *)linux_banner").string())
45 45
46LxVersion() 46LxVersion()
47 47
diff --git a/scripts/gen_compile_commands.py b/scripts/gen_compile_commands.py
new file mode 100755
index 000000000000..7915823b92a5
--- /dev/null
+++ b/scripts/gen_compile_commands.py
@@ -0,0 +1,151 @@
1#!/usr/bin/env python
2# SPDX-License-Identifier: GPL-2.0
3#
4# Copyright (C) Google LLC, 2018
5#
6# Author: Tom Roeder <tmroeder@google.com>
7#
8"""A tool for generating compile_commands.json in the Linux kernel."""
9
10import argparse
11import json
12import logging
13import os
14import re
15
16_DEFAULT_OUTPUT = 'compile_commands.json'
17_DEFAULT_LOG_LEVEL = 'WARNING'
18
19_FILENAME_PATTERN = r'^\..*\.cmd$'
20_LINE_PATTERN = r'^cmd_[^ ]*\.o := (.* )([^ ]*\.c)$'
21_VALID_LOG_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
22
23# A kernel build generally has over 2000 entries in its compile_commands.json
24# database. If this code finds 500 or fewer, then warn the user that they might
25# not have all the .cmd files, and they might need to compile the kernel.
26_LOW_COUNT_THRESHOLD = 500
27
28
29def parse_arguments():
30 """Sets up and parses command-line arguments.
31
32 Returns:
33 log_level: A logging level to filter log output.
34 directory: The directory to search for .cmd files.
35 output: Where to write the compile-commands JSON file.
36 """
37 usage = 'Creates a compile_commands.json database from kernel .cmd files'
38 parser = argparse.ArgumentParser(description=usage)
39
40 directory_help = ('Path to the kernel source directory to search '
41 '(defaults to the working directory)')
42 parser.add_argument('-d', '--directory', type=str, help=directory_help)
43
44 output_help = ('The location to write compile_commands.json (defaults to '
45 'compile_commands.json in the search directory)')
46 parser.add_argument('-o', '--output', type=str, help=output_help)
47
48 log_level_help = ('The level of log messages to produce (one of ' +
49 ', '.join(_VALID_LOG_LEVELS) + '; defaults to ' +
50 _DEFAULT_LOG_LEVEL + ')')
51 parser.add_argument(
52 '--log_level', type=str, default=_DEFAULT_LOG_LEVEL,
53 help=log_level_help)
54
55 args = parser.parse_args()
56
57 log_level = args.log_level
58 if log_level not in _VALID_LOG_LEVELS:
59 raise ValueError('%s is not a valid log level' % log_level)
60
61 directory = args.directory or os.getcwd()
62 output = args.output or os.path.join(directory, _DEFAULT_OUTPUT)
63 directory = os.path.abspath(directory)
64
65 return log_level, directory, output
66
67
68def process_line(root_directory, file_directory, command_prefix, relative_path):
69 """Extracts information from a .cmd line and creates an entry from it.
70
71 Args:
72 root_directory: The directory that was searched for .cmd files. Usually
73 used directly in the "directory" entry in compile_commands.json.
74 file_directory: The path to the directory the .cmd file was found in.
75 command_prefix: The extracted command line, up to the last element.
76 relative_path: The .c file from the end of the extracted command.
77 Usually relative to root_directory, but sometimes relative to
78 file_directory and sometimes neither.
79
80 Returns:
81 An entry to append to compile_commands.
82
83 Raises:
84 ValueError: Could not find the extracted file based on relative_path and
85 root_directory or file_directory.
86 """
87 # The .cmd files are intended to be included directly by Make, so they
88 # escape the pound sign '#', either as '\#' or '$(pound)' (depending on the
89 # kernel version). The compile_commands.json file is not interepreted
90 # by Make, so this code replaces the escaped version with '#'.
91 prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#')
92
93 cur_dir = root_directory
94 expected_path = os.path.join(cur_dir, relative_path)
95 if not os.path.exists(expected_path):
96 # Try using file_directory instead. Some of the tools have a different
97 # style of .cmd file than the kernel.
98 cur_dir = file_directory
99 expected_path = os.path.join(cur_dir, relative_path)
100 if not os.path.exists(expected_path):
101 raise ValueError('File %s not in %s or %s' %
102 (relative_path, root_directory, file_directory))
103 return {
104 'directory': cur_dir,
105 'file': relative_path,
106 'command': prefix + relative_path,
107 }
108
109
110def main():
111 """Walks through the directory and finds and parses .cmd files."""
112 log_level, directory, output = parse_arguments()
113
114 level = getattr(logging, log_level)
115 logging.basicConfig(format='%(levelname)s: %(message)s', level=level)
116
117 filename_matcher = re.compile(_FILENAME_PATTERN)
118 line_matcher = re.compile(_LINE_PATTERN)
119
120 compile_commands = []
121 for dirpath, _, filenames in os.walk(directory):
122 for filename in filenames:
123 if not filename_matcher.match(filename):
124 continue
125 filepath = os.path.join(dirpath, filename)
126
127 with open(filepath, 'rt') as f:
128 for line in f:
129 result = line_matcher.match(line)
130 if not result:
131 continue
132
133 try:
134 entry = process_line(directory, dirpath,
135 result.group(1), result.group(2))
136 compile_commands.append(entry)
137 except ValueError as err:
138 logging.info('Could not add line from %s: %s',
139 filepath, err)
140
141 with open(output, 'wt') as f:
142 json.dump(compile_commands, f, indent=2, sort_keys=True)
143
144 count = len(compile_commands)
145 if count < _LOW_COUNT_THRESHOLD:
146 logging.warning(
147 'Found %s entries. Have you compiled the kernel?', count)
148
149
150if __name__ == '__main__':
151 main()
diff --git a/scripts/gen_ksymdeps.sh b/scripts/gen_ksymdeps.sh
new file mode 100755
index 000000000000..1324986e1362
--- /dev/null
+++ b/scripts/gen_ksymdeps.sh
@@ -0,0 +1,25 @@
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4set -e
5
6# List of exported symbols
7ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z)
8
9if [ -z "$ksyms" ]; then
10 exit 0
11fi
12
13echo
14echo "ksymdeps_$1 := \\"
15
16for s in $ksyms
17do
18 echo $s | sed -e 's:^_*: $(wildcard include/ksym/:' \
19 -e 's:__*:/:g' -e 's/$/.h) \\/'
20done
21
22echo
23echo "$1: \$(ksymdeps_$1)"
24echo
25echo "\$(ksymdeps_$1):"
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 109a1af7e444..77cebad0474e 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -334,10 +334,10 @@ static void write_src(void)
334 printf("#include <asm/types.h>\n"); 334 printf("#include <asm/types.h>\n");
335 printf("#if BITS_PER_LONG == 64\n"); 335 printf("#if BITS_PER_LONG == 64\n");
336 printf("#define PTR .quad\n"); 336 printf("#define PTR .quad\n");
337 printf("#define ALGN .align 8\n"); 337 printf("#define ALGN .balign 8\n");
338 printf("#else\n"); 338 printf("#else\n");
339 printf("#define PTR .long\n"); 339 printf("#define PTR .long\n");
340 printf("#define ALGN .align 4\n"); 340 printf("#define ALGN .balign 4\n");
341 printf("#endif\n"); 341 printf("#endif\n");
342 342
343 printf("\t.section .rodata, \"a\"\n"); 343 printf("\t.section .rodata, \"a\"\n");
diff --git a/scripts/kconfig/.gitignore b/scripts/kconfig/.gitignore
index 0aabc1d6a182..b5bf92f66d11 100644
--- a/scripts/kconfig/.gitignore
+++ b/scripts/kconfig/.gitignore
@@ -2,6 +2,7 @@
2# Generated files 2# Generated files
3# 3#
4*.moc 4*.moc
5*conf-cfg
5 6
6# 7#
7# configuration programs 8# configuration programs
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 63b609243d03..181973509a05 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -142,75 +142,68 @@ help:
142 @echo ' testconfig - Run Kconfig unit tests (requires python3 and pytest)' 142 @echo ' testconfig - Run Kconfig unit tests (requires python3 and pytest)'
143 143
144# =========================================================================== 144# ===========================================================================
145# Shared Makefile for the various kconfig executables:
146# conf: Used for defconfig, oldconfig and related targets
147# object files used by all kconfig flavours 145# object files used by all kconfig flavours
146common-objs := confdata.o expr.o symbol.o preprocess.o zconf.lex.o zconf.tab.o
148 147
149conf-objs := conf.o zconf.tab.o 148$(obj)/zconf.lex.o: $(obj)/zconf.tab.h
150
151hostprogs-y := conf
152
153targets += zconf.lex.c
154
155# generated files seem to need this to find local include files
156HOSTCFLAGS_zconf.lex.o := -I$(src) 149HOSTCFLAGS_zconf.lex.o := -I$(src)
157HOSTCFLAGS_zconf.tab.o := -I$(src) 150HOSTCFLAGS_zconf.tab.o := -I$(src)
158 151
152# conf: Used for defconfig, oldconfig and related targets
153hostprogs-y += conf
154conf-objs := conf.o $(common-objs)
155
159# nconf: Used for the nconfig target based on ncurses 156# nconf: Used for the nconfig target based on ncurses
160hostprogs-y += nconf 157hostprogs-y += nconf
161nconf-objs := nconf.o zconf.tab.o nconf.gui.o 158nconf-objs := nconf.o nconf.gui.o $(common-objs)
162 159
163HOSTLDLIBS_nconf = $(shell . $(obj)/.nconf-cfg && echo $$libs) 160HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs)
164HOSTCFLAGS_nconf.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags) 161HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
165HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags) 162HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
166 163
167$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/.nconf-cfg 164$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
168 165
169# mconf: Used for the menuconfig target based on lxdialog 166# mconf: Used for the menuconfig target based on lxdialog
170hostprogs-y += mconf 167hostprogs-y += mconf
171lxdialog := checklist.o inputbox.o menubox.o textbox.o util.o yesno.o 168lxdialog := checklist.o inputbox.o menubox.o textbox.o util.o yesno.o
172mconf-objs := mconf.o zconf.tab.o $(addprefix lxdialog/, $(lxdialog)) 169mconf-objs := mconf.o $(addprefix lxdialog/, $(lxdialog)) $(common-objs)
173 170
174HOSTLDLIBS_mconf = $(shell . $(obj)/.mconf-cfg && echo $$libs) 171HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
175$(foreach f, mconf.o $(lxdialog), \ 172$(foreach f, mconf.o $(lxdialog), \
176 $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/.mconf-cfg && echo $$$$cflags))) 173 $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
177 174
178$(obj)/mconf.o: $(obj)/.mconf-cfg 175$(obj)/mconf.o: $(obj)/mconf-cfg
179$(addprefix $(obj)/lxdialog/, $(lxdialog)): $(obj)/.mconf-cfg 176$(addprefix $(obj)/lxdialog/, $(lxdialog)): $(obj)/mconf-cfg
180 177
181# qconf: Used for the xconfig target based on Qt 178# qconf: Used for the xconfig target based on Qt
182hostprogs-y += qconf 179hostprogs-y += qconf
183qconf-cxxobjs := qconf.o 180qconf-cxxobjs := qconf.o
184qconf-objs := zconf.tab.o 181qconf-objs := images.o $(common-objs)
185 182
186HOSTLDLIBS_qconf = $(shell . $(obj)/.qconf-cfg && echo $$libs) 183HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
187HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/.qconf-cfg && echo $$cflags) 184HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
188 185
189$(obj)/qconf.o: $(obj)/.qconf-cfg $(obj)/qconf.moc 186$(obj)/qconf.o: $(obj)/qconf-cfg $(obj)/qconf.moc
190 187
191quiet_cmd_moc = MOC $@ 188quiet_cmd_moc = MOC $@
192 cmd_moc = $(shell . $(obj)/.qconf-cfg && echo $$moc) -i $< -o $@ 189 cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) -i $< -o $@
193 190
194$(obj)/%.moc: $(src)/%.h $(obj)/.qconf-cfg 191$(obj)/%.moc: $(src)/%.h $(obj)/qconf-cfg
195 $(call cmd,moc) 192 $(call cmd,moc)
196 193
197# gconf: Used for the gconfig target based on GTK+ 194# gconf: Used for the gconfig target based on GTK+
198hostprogs-y += gconf 195hostprogs-y += gconf
199gconf-objs := gconf.o zconf.tab.o 196gconf-objs := gconf.o images.o $(common-objs)
200
201HOSTLDLIBS_gconf = $(shell . $(obj)/.gconf-cfg && echo $$libs)
202HOSTCFLAGS_gconf.o = $(shell . $(obj)/.gconf-cfg && echo $$cflags)
203 197
204$(obj)/gconf.o: $(obj)/.gconf-cfg 198HOSTLDLIBS_gconf = $(shell . $(obj)/gconf-cfg && echo $$libs)
199HOSTCFLAGS_gconf.o = $(shell . $(obj)/gconf-cfg && echo $$cflags)
205 200
206$(obj)/zconf.tab.o: $(obj)/zconf.lex.c 201$(obj)/gconf.o: $(obj)/gconf-cfg
207 202
208# check if necessary packages are available, and configure build flags 203# check if necessary packages are available, and configure build flags
209define filechk_conf_cfg 204filechk_conf_cfg = $(CONFIG_SHELL) $<
210 $(CONFIG_SHELL) $<
211endef
212 205
213$(obj)/.%conf-cfg: $(src)/%conf-cfg.sh FORCE 206$(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
214 $(call filechk,conf_cfg) 207 $(call filechk,conf_cfg)
215 208
216clean-files += .*conf-cfg 209clean-files += *conf-cfg
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 98e0c7a34699..da89ef788a8d 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <ctype.h> 6#include <ctype.h>
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 91d0a5c014ac..08ba146a83c5 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -1,12 +1,13 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <sys/stat.h> 6#include <sys/stat.h>
7#include <ctype.h> 7#include <ctype.h>
8#include <errno.h> 8#include <errno.h>
9#include <fcntl.h> 9#include <fcntl.h>
10#include <limits.h>
10#include <stdarg.h> 11#include <stdarg.h>
11#include <stdio.h> 12#include <stdio.h>
12#include <stdlib.h> 13#include <stdlib.h>
@@ -74,6 +75,47 @@ static int make_parent_dir(const char *path)
74 return 0; 75 return 0;
75} 76}
76 77
78static char depfile_path[PATH_MAX];
79static size_t depfile_prefix_len;
80
81/* touch depfile for symbol 'name' */
82static int conf_touch_dep(const char *name)
83{
84 int fd, ret;
85 const char *s;
86 char *d, c;
87
88 /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
89 if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))
90 return -1;
91
92 d = depfile_path + depfile_prefix_len;
93 s = name;
94
95 while ((c = *s++))
96 *d++ = (c == '_') ? '/' : tolower(c);
97 strcpy(d, ".h");
98
99 /* Assume directory path already exists. */
100 fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
101 if (fd == -1) {
102 if (errno != ENOENT)
103 return -1;
104
105 ret = make_parent_dir(depfile_path);
106 if (ret)
107 return ret;
108
109 /* Try it again. */
110 fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
111 if (fd == -1)
112 return -1;
113 }
114 close(fd);
115
116 return 0;
117}
118
77struct conf_printer { 119struct conf_printer {
78 void (*print_symbol)(FILE *, struct symbol *, const char *, void *); 120 void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
79 void (*print_comment)(FILE *, const char *, void *); 121 void (*print_comment)(FILE *, const char *, void *);
@@ -186,14 +228,6 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
186 conf_warning("symbol value '%s' invalid for %s", 228 conf_warning("symbol value '%s' invalid for %s",
187 p, sym->name); 229 p, sym->name);
188 return 1; 230 return 1;
189 case S_OTHER:
190 if (*p != '"') {
191 for (p2 = p; *p2 && !isspace(*p2); p2++)
192 ;
193 sym->type = S_STRING;
194 goto done;
195 }
196 /* fall through */
197 case S_STRING: 231 case S_STRING:
198 if (*p++ != '"') 232 if (*p++ != '"')
199 break; 233 break;
@@ -212,7 +246,6 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
212 /* fall through */ 246 /* fall through */
213 case S_INT: 247 case S_INT:
214 case S_HEX: 248 case S_HEX:
215 done:
216 if (sym_string_valid(sym, p)) { 249 if (sym_string_valid(sym, p)) {
217 sym->def[def].val = xstrdup(p); 250 sym->def[def].val = xstrdup(p);
218 sym->flags |= def_flags; 251 sym->flags |= def_flags;
@@ -363,7 +396,7 @@ load:
363 sym = sym_find(line + 2 + strlen(CONFIG_)); 396 sym = sym_find(line + 2 + strlen(CONFIG_));
364 if (!sym) { 397 if (!sym) {
365 sym_add_change_count(1); 398 sym_add_change_count(1);
366 goto setsym; 399 continue;
367 } 400 }
368 } else { 401 } else {
369 sym = sym_lookup(line + 2 + strlen(CONFIG_), 0); 402 sym = sym_lookup(line + 2 + strlen(CONFIG_), 0);
@@ -393,17 +426,22 @@ load:
393 if (*p2 == '\r') 426 if (*p2 == '\r')
394 *p2 = 0; 427 *p2 = 0;
395 } 428 }
396 if (def == S_DEF_USER) { 429
397 sym = sym_find(line + strlen(CONFIG_)); 430 sym = sym_find(line + strlen(CONFIG_));
398 if (!sym) { 431 if (!sym) {
432 if (def == S_DEF_AUTO)
433 /*
434 * Reading from include/config/auto.conf
435 * If CONFIG_FOO previously existed in
436 * auto.conf but it is missing now,
437 * include/config/foo.h must be touched.
438 */
439 conf_touch_dep(line + strlen(CONFIG_));
440 else
399 sym_add_change_count(1); 441 sym_add_change_count(1);
400 goto setsym; 442 continue;
401 }
402 } else {
403 sym = sym_lookup(line + strlen(CONFIG_), 0);
404 if (sym->type == S_UNKNOWN)
405 sym->type = S_OTHER;
406 } 443 }
444
407 if (sym->flags & def_flags) { 445 if (sym->flags & def_flags) {
408 conf_warning("override: reassigning to symbol %s", sym->name); 446 conf_warning("override: reassigning to symbol %s", sym->name);
409 } 447 }
@@ -416,7 +454,7 @@ load:
416 454
417 continue; 455 continue;
418 } 456 }
419setsym: 457
420 if (sym && sym_is_choice_value(sym)) { 458 if (sym && sym_is_choice_value(sym)) {
421 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym)); 459 struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));
422 switch (sym->def[def].tri) { 460 switch (sym->def[def].tri) {
@@ -669,7 +707,6 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym,
669 const char *str; 707 const char *str;
670 708
671 switch (sym->type) { 709 switch (sym->type) {
672 case S_OTHER:
673 case S_UNKNOWN: 710 case S_UNKNOWN:
674 break; 711 break;
675 case S_STRING: 712 case S_STRING:
@@ -906,24 +943,19 @@ static int conf_write_dep(const char *name)
906 return 0; 943 return 0;
907} 944}
908 945
909static int conf_split_config(void) 946static int conf_touch_deps(void)
910{ 947{
911 const char *name; 948 const char *name;
912 char path[PATH_MAX+1];
913 char *s, *d, c;
914 struct symbol *sym; 949 struct symbol *sym;
915 int res, i, fd; 950 int res, i;
951
952 strcpy(depfile_path, "include/config/");
953 depfile_prefix_len = strlen(depfile_path);
916 954
917 name = conf_get_autoconfig_name(); 955 name = conf_get_autoconfig_name();
918 conf_read_simple(name, S_DEF_AUTO); 956 conf_read_simple(name, S_DEF_AUTO);
919 sym_calc_value(modules_sym); 957 sym_calc_value(modules_sym);
920 958
921 if (make_parent_dir("include/config/foo.h"))
922 return 1;
923 if (chdir("include/config"))
924 return 1;
925
926 res = 0;
927 for_all_symbols(i, sym) { 959 for_all_symbols(i, sym) {
928 sym_calc_value(sym); 960 sym_calc_value(sym);
929 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) 961 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
@@ -975,42 +1007,12 @@ static int conf_split_config(void)
975 * different from 'no'). 1007 * different from 'no').
976 */ 1008 */
977 1009
978 /* Replace all '_' and append ".h" */ 1010 res = conf_touch_dep(sym->name);
979 s = sym->name; 1011 if (res)
980 d = path; 1012 return res;
981 while ((c = *s++)) {
982 c = tolower(c);
983 *d++ = (c == '_') ? '/' : c;
984 }
985 strcpy(d, ".h");
986
987 /* Assume directory path already exists. */
988 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
989 if (fd == -1) {
990 if (errno != ENOENT) {
991 res = 1;
992 break;
993 }
994
995 if (make_parent_dir(path)) {
996 res = 1;
997 goto out;
998 }
999
1000 /* Try it again. */
1001 fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
1002 if (fd == -1) {
1003 res = 1;
1004 break;
1005 }
1006 }
1007 close(fd);
1008 } 1013 }
1009out:
1010 if (chdir("../.."))
1011 return 1;
1012 1014
1013 return res; 1015 return 0;
1014} 1016}
1015 1017
1016int conf_write_autoconf(int overwrite) 1018int conf_write_autoconf(int overwrite)
@@ -1028,7 +1030,7 @@ int conf_write_autoconf(int overwrite)
1028 1030
1029 conf_write_dep("include/config/auto.conf.cmd"); 1031 conf_write_dep("include/config/auto.conf.cmd");
1030 1032
1031 if (conf_split_config()) 1033 if (conf_touch_deps())
1032 return 1; 1034 return 1;
1033 1035
1034 out = fopen(".tmpconfig", "w"); 1036 out = fopen(".tmpconfig", "w");
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index e1a39e90841d..77ffff3a053c 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -1,8 +1,10 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <ctype.h>
7#include <errno.h>
6#include <stdio.h> 8#include <stdio.h>
7#include <stdlib.h> 9#include <stdlib.h>
8#include <string.h> 10#include <string.h>
@@ -980,7 +982,6 @@ enum string_value_kind {
980 k_string, 982 k_string,
981 k_signed, 983 k_signed,
982 k_unsigned, 984 k_unsigned,
983 k_invalid
984}; 985};
985 986
986union string_value { 987union string_value {
@@ -1011,13 +1012,10 @@ static enum string_value_kind expr_parse_string(const char *str,
1011 val->u = strtoull(str, &tail, 16); 1012 val->u = strtoull(str, &tail, 16);
1012 kind = k_unsigned; 1013 kind = k_unsigned;
1013 break; 1014 break;
1014 case S_STRING: 1015 default:
1015 case S_UNKNOWN:
1016 val->s = strtoll(str, &tail, 0); 1016 val->s = strtoll(str, &tail, 0);
1017 kind = k_signed; 1017 kind = k_signed;
1018 break; 1018 break;
1019 default:
1020 return k_invalid;
1021 } 1019 }
1022 return !errno && !*tail && tail > str && isxdigit(tail[-1]) 1020 return !errno && !*tail && tail > str && isxdigit(tail[-1])
1023 ? kind : k_string; 1021 ? kind : k_string;
@@ -1073,13 +1071,7 @@ tristate expr_calc_value(struct expr *e)
1073 1071
1074 if (k1 == k_string || k2 == k_string) 1072 if (k1 == k_string || k2 == k_string)
1075 res = strcmp(str1, str2); 1073 res = strcmp(str1, str2);
1076 else if (k1 == k_invalid || k2 == k_invalid) { 1074 else if (k1 == k_unsigned || k2 == k_unsigned)
1077 if (e->type != E_EQUAL && e->type != E_UNEQUAL) {
1078 printf("Cannot compare \"%s\" and \"%s\"\n", str1, str2);
1079 return no;
1080 }
1081 res = strcmp(str1, str2);
1082 } else if (k1 == k_unsigned || k2 == k_unsigned)
1083 res = (lval.u > rval.u) - (lval.u < rval.u); 1075 res = (lval.u > rval.u) - (lval.u < rval.u);
1084 else /* if (k1 == k_signed && k2 == k_signed) */ 1076 else /* if (k1 == k_signed && k2 == k_signed) */
1085 res = (lval.s > rval.s) - (lval.s < rval.s); 1077 res = (lval.s > rval.s) - (lval.s < rval.s);
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 7c329e179007..999edb60cd53 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -1,6 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#ifndef EXPR_H 6#ifndef EXPR_H
@@ -62,7 +62,7 @@ struct symbol_value {
62}; 62};
63 63
64enum symbol_type { 64enum symbol_type {
65 S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER 65 S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING
66}; 66};
67 67
68/* enum values are used as index to symbol.def[] */ 68/* enum values are used as index to symbol.def[] */
@@ -131,7 +131,7 @@ struct symbol {
131 struct expr_value implied; 131 struct expr_value implied;
132}; 132};
133 133
134#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER) 134#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next)
135 135
136#define SYMBOL_CONST 0x0001 /* symbol is const */ 136#define SYMBOL_CONST 0x0001 /* symbol is const */
137#define SYMBOL_CHECK 0x0008 /* used during dependency checking */ 137#define SYMBOL_CHECK 0x0008 /* used during dependency checking */
diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index 36f578415c4a..5d4ecf309ee4 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -1,9 +1,6 @@
1/* Hey EMACS -*- linux-c -*- */ 1// SPDX-License-Identifier: GPL-2.0
2/* 2/*
3 *
4 * Copyright (C) 2002-2003 Romain Lievin <roms@tilp.info> 3 * Copyright (C) 2002-2003 Romain Lievin <roms@tilp.info>
5 * Released under the terms of the GNU GPL v2.0.
6 *
7 */ 4 */
8 5
9#ifdef HAVE_CONFIG_H 6#ifdef HAVE_CONFIG_H
@@ -12,7 +9,7 @@
12 9
13#include <stdlib.h> 10#include <stdlib.h>
14#include "lkc.h" 11#include "lkc.h"
15#include "images.c" 12#include "images.h"
16 13
17#include <glade/glade.h> 14#include <glade/glade.h>
18#include <gtk/gtk.h> 15#include <gtk/gtk.h>
@@ -78,8 +75,8 @@ static gchar **fill_row(struct menu *menu);
78static void conf_changed(void); 75static void conf_changed(void);
79 76
80/* Helping/Debugging Functions */ 77/* Helping/Debugging Functions */
81 78#ifdef DEBUG
82const char *dbg_sym_flags(int val) 79static const char *dbg_sym_flags(int val)
83{ 80{
84 static char buf[256]; 81 static char buf[256];
85 82
@@ -108,9 +105,10 @@ const char *dbg_sym_flags(int val)
108 105
109 return buf; 106 return buf;
110} 107}
108#endif
111 109
112void replace_button_icon(GladeXML * xml, GdkDrawable * window, 110static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
113 GtkStyle * style, gchar * btn_name, gchar ** xpm) 111 GtkStyle *style, gchar *btn_name, gchar **xpm)
114{ 112{
115 GdkPixmap *pixmap; 113 GdkPixmap *pixmap;
116 GdkBitmap *mask; 114 GdkBitmap *mask;
@@ -128,7 +126,7 @@ void replace_button_icon(GladeXML * xml, GdkDrawable * window,
128} 126}
129 127
130/* Main Window Initialization */ 128/* Main Window Initialization */
131void init_main_window(const gchar * glade_file) 129static void init_main_window(const gchar *glade_file)
132{ 130{
133 GladeXML *xml; 131 GladeXML *xml;
134 GtkWidget *widget; 132 GtkWidget *widget;
@@ -190,7 +188,7 @@ void init_main_window(const gchar * glade_file)
190 gtk_widget_show(main_wnd); 188 gtk_widget_show(main_wnd);
191} 189}
192 190
193void init_tree_model(void) 191static void init_tree_model(void)
194{ 192{
195 gint i; 193 gint i;
196 194
@@ -220,7 +218,7 @@ void init_tree_model(void)
220 model1 = GTK_TREE_MODEL(tree1); 218 model1 = GTK_TREE_MODEL(tree1);
221} 219}
222 220
223void init_left_tree(void) 221static void init_left_tree(void)
224{ 222{
225 GtkTreeView *view = GTK_TREE_VIEW(tree1_w); 223 GtkTreeView *view = GTK_TREE_VIEW(tree1_w);
226 GtkCellRenderer *renderer; 224 GtkCellRenderer *renderer;
@@ -262,7 +260,7 @@ static void renderer_edited(GtkCellRendererText * cell,
262 const gchar * path_string, 260 const gchar * path_string,
263 const gchar * new_text, gpointer user_data); 261 const gchar * new_text, gpointer user_data);
264 262
265void init_right_tree(void) 263static void init_right_tree(void)
266{ 264{
267 GtkTreeView *view = GTK_TREE_VIEW(tree2_w); 265 GtkTreeView *view = GTK_TREE_VIEW(tree2_w);
268 GtkCellRenderer *renderer; 266 GtkCellRenderer *renderer;
@@ -1212,8 +1210,8 @@ static GtkTreeIter found;
1212/* 1210/*
1213 * Find a menu in the GtkTree starting at parent. 1211 * Find a menu in the GtkTree starting at parent.
1214 */ 1212 */
1215GtkTreeIter *gtktree_iter_find_node(GtkTreeIter * parent, 1213static GtkTreeIter *gtktree_iter_find_node(GtkTreeIter *parent,
1216 struct menu *tofind) 1214 struct menu *tofind)
1217{ 1215{
1218 GtkTreeIter iter; 1216 GtkTreeIter iter;
1219 GtkTreeIter *child = &iter; 1217 GtkTreeIter *child = &iter;
@@ -1424,7 +1422,7 @@ static void display_list(void)
1424 tree = tree2; 1422 tree = tree2;
1425} 1423}
1426 1424
1427void fixup_rootmenu(struct menu *menu) 1425static void fixup_rootmenu(struct menu *menu)
1428{ 1426{
1429 struct menu *child; 1427 struct menu *child;
1430 static int menu_cnt = 0; 1428 static int menu_cnt = 0;
diff --git a/scripts/kconfig/images.c b/scripts/kconfig/images.c
index d4f84bd4a96b..b4fa0e4a63a5 100644
--- a/scripts/kconfig/images.c
+++ b/scripts/kconfig/images.c
@@ -1,9 +1,11 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6static const char *xpm_load[] = { 6#include "images.h"
7
8const char *xpm_load[] = {
7"22 22 5 1", 9"22 22 5 1",
8". c None", 10". c None",
9"# c #000000", 11"# c #000000",
@@ -33,7 +35,7 @@ static const char *xpm_load[] = {
33"###############.......", 35"###############.......",
34"......................"}; 36"......................"};
35 37
36static const char *xpm_save[] = { 38const char *xpm_save[] = {
37"22 22 5 1", 39"22 22 5 1",
38". c None", 40". c None",
39"# c #000000", 41"# c #000000",
@@ -63,7 +65,7 @@ static const char *xpm_save[] = {
63"..##################..", 65"..##################..",
64"......................"}; 66"......................"};
65 67
66static const char *xpm_back[] = { 68const char *xpm_back[] = {
67"22 22 3 1", 69"22 22 3 1",
68". c None", 70". c None",
69"# c #000083", 71"# c #000083",
@@ -91,7 +93,7 @@ static const char *xpm_back[] = {
91"......................", 93"......................",
92"......................"}; 94"......................"};
93 95
94static const char *xpm_tree_view[] = { 96const char *xpm_tree_view[] = {
95"22 22 2 1", 97"22 22 2 1",
96". c None", 98". c None",
97"# c #000000", 99"# c #000000",
@@ -118,7 +120,7 @@ static const char *xpm_tree_view[] = {
118"......................", 120"......................",
119"......................"}; 121"......................"};
120 122
121static const char *xpm_single_view[] = { 123const char *xpm_single_view[] = {
122"22 22 2 1", 124"22 22 2 1",
123". c None", 125". c None",
124"# c #000000", 126"# c #000000",
@@ -145,7 +147,7 @@ static const char *xpm_single_view[] = {
145"......................", 147"......................",
146"......................"}; 148"......................"};
147 149
148static const char *xpm_split_view[] = { 150const char *xpm_split_view[] = {
149"22 22 2 1", 151"22 22 2 1",
150". c None", 152". c None",
151"# c #000000", 153"# c #000000",
@@ -172,7 +174,7 @@ static const char *xpm_split_view[] = {
172"......................", 174"......................",
173"......................"}; 175"......................"};
174 176
175static const char *xpm_symbol_no[] = { 177const char *xpm_symbol_no[] = {
176"12 12 2 1", 178"12 12 2 1",
177" c white", 179" c white",
178". c black", 180". c black",
@@ -189,7 +191,7 @@ static const char *xpm_symbol_no[] = {
189" .......... ", 191" .......... ",
190" "}; 192" "};
191 193
192static const char *xpm_symbol_mod[] = { 194const char *xpm_symbol_mod[] = {
193"12 12 2 1", 195"12 12 2 1",
194" c white", 196" c white",
195". c black", 197". c black",
@@ -206,7 +208,7 @@ static const char *xpm_symbol_mod[] = {
206" .......... ", 208" .......... ",
207" "}; 209" "};
208 210
209static const char *xpm_symbol_yes[] = { 211const char *xpm_symbol_yes[] = {
210"12 12 2 1", 212"12 12 2 1",
211" c white", 213" c white",
212". c black", 214". c black",
@@ -223,7 +225,7 @@ static const char *xpm_symbol_yes[] = {
223" .......... ", 225" .......... ",
224" "}; 226" "};
225 227
226static const char *xpm_choice_no[] = { 228const char *xpm_choice_no[] = {
227"12 12 2 1", 229"12 12 2 1",
228" c white", 230" c white",
229". c black", 231". c black",
@@ -240,7 +242,7 @@ static const char *xpm_choice_no[] = {
240" .... ", 242" .... ",
241" "}; 243" "};
242 244
243static const char *xpm_choice_yes[] = { 245const char *xpm_choice_yes[] = {
244"12 12 2 1", 246"12 12 2 1",
245" c white", 247" c white",
246". c black", 248". c black",
@@ -257,7 +259,7 @@ static const char *xpm_choice_yes[] = {
257" .... ", 259" .... ",
258" "}; 260" "};
259 261
260static const char *xpm_menu[] = { 262const char *xpm_menu[] = {
261"12 12 2 1", 263"12 12 2 1",
262" c white", 264" c white",
263". c black", 265". c black",
@@ -274,7 +276,7 @@ static const char *xpm_menu[] = {
274" .......... ", 276" .......... ",
275" "}; 277" "};
276 278
277static const char *xpm_menu_inv[] = { 279const char *xpm_menu_inv[] = {
278"12 12 2 1", 280"12 12 2 1",
279" c white", 281" c white",
280". c black", 282". c black",
@@ -291,7 +293,7 @@ static const char *xpm_menu_inv[] = {
291" .......... ", 293" .......... ",
292" "}; 294" "};
293 295
294static const char *xpm_menuback[] = { 296const char *xpm_menuback[] = {
295"12 12 2 1", 297"12 12 2 1",
296" c white", 298" c white",
297". c black", 299". c black",
@@ -308,7 +310,7 @@ static const char *xpm_menuback[] = {
308" .......... ", 310" .......... ",
309" "}; 311" "};
310 312
311static const char *xpm_void[] = { 313const char *xpm_void[] = {
312"12 12 2 1", 314"12 12 2 1",
313" c white", 315" c white",
314". c black", 316". c black",
diff --git a/scripts/kconfig/images.h b/scripts/kconfig/images.h
new file mode 100644
index 000000000000..d8ff614bd087
--- /dev/null
+++ b/scripts/kconfig/images.h
@@ -0,0 +1,33 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 */
5
6#ifndef IMAGES_H
7#define IMAGES_H
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13extern const char *xpm_load[];
14extern const char *xpm_save[];
15extern const char *xpm_back[];
16extern const char *xpm_tree_view[];
17extern const char *xpm_single_view[];
18extern const char *xpm_split_view[];
19extern const char *xpm_symbol_no[];
20extern const char *xpm_symbol_mod[];
21extern const char *xpm_symbol_yes[];
22extern const char *xpm_choice_no[];
23extern const char *xpm_choice_yes[];
24extern const char *xpm_menu[];
25extern const char *xpm_menu_inv[];
26extern const char *xpm_menuback[];
27extern const char *xpm_void[];
28
29#ifdef __cplusplus
30}
31#endif
32
33#endif /* IMAGES_H */
diff --git a/scripts/kconfig/kconf_id.c b/scripts/kconfig/kconf_id.c
deleted file mode 100644
index b3e0ea0ac732..000000000000
--- a/scripts/kconfig/kconf_id.c
+++ /dev/null
@@ -1,52 +0,0 @@
1
2static struct kconf_id kconf_id_array[] = {
3 { "mainmenu", T_MAINMENU, TF_COMMAND },
4 { "menu", T_MENU, TF_COMMAND },
5 { "endmenu", T_ENDMENU, TF_COMMAND },
6 { "source", T_SOURCE, TF_COMMAND },
7 { "choice", T_CHOICE, TF_COMMAND },
8 { "endchoice", T_ENDCHOICE, TF_COMMAND },
9 { "comment", T_COMMENT, TF_COMMAND },
10 { "config", T_CONFIG, TF_COMMAND },
11 { "menuconfig", T_MENUCONFIG, TF_COMMAND },
12 { "help", T_HELP, TF_COMMAND },
13 { "---help---", T_HELP, TF_COMMAND },
14 { "if", T_IF, TF_COMMAND|TF_PARAM },
15 { "endif", T_ENDIF, TF_COMMAND },
16 { "depends", T_DEPENDS, TF_COMMAND },
17 { "optional", T_OPTIONAL, TF_COMMAND },
18 { "default", T_DEFAULT, TF_COMMAND, S_UNKNOWN },
19 { "prompt", T_PROMPT, TF_COMMAND },
20 { "tristate", T_TYPE, TF_COMMAND, S_TRISTATE },
21 { "def_tristate", T_DEFAULT, TF_COMMAND, S_TRISTATE },
22 { "bool", T_TYPE, TF_COMMAND, S_BOOLEAN },
23 { "def_bool", T_DEFAULT, TF_COMMAND, S_BOOLEAN },
24 { "int", T_TYPE, TF_COMMAND, S_INT },
25 { "hex", T_TYPE, TF_COMMAND, S_HEX },
26 { "string", T_TYPE, TF_COMMAND, S_STRING },
27 { "select", T_SELECT, TF_COMMAND },
28 { "imply", T_IMPLY, TF_COMMAND },
29 { "range", T_RANGE, TF_COMMAND },
30 { "visible", T_VISIBLE, TF_COMMAND },
31 { "option", T_OPTION, TF_COMMAND },
32 { "on", T_ON, TF_PARAM },
33 { "modules", T_OPT_MODULES, TF_OPTION },
34 { "defconfig_list", T_OPT_DEFCONFIG_LIST, TF_OPTION },
35 { "allnoconfig_y", T_OPT_ALLNOCONFIG_Y, TF_OPTION },
36};
37
38#define KCONF_ID_ARRAY_SIZE (sizeof(kconf_id_array)/sizeof(struct kconf_id))
39
40static const struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len)
41{
42 int i;
43
44 for (i = 0; i < KCONF_ID_ARRAY_SIZE; i++) {
45 struct kconf_id *id = kconf_id_array+i;
46 int l = strlen(id->name);
47
48 if (len == l && !memcmp(str, id->name, len))
49 return id;
50 }
51 return NULL;
52}
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 9eb7c837cd8f..531ff7c57d92 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -1,6 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#ifndef LKC_H 6#ifndef LKC_H
@@ -30,10 +30,6 @@ static inline const char *CONFIG_prefix(void)
30#undef CONFIG_ 30#undef CONFIG_
31#define CONFIG_ CONFIG_prefix() 31#define CONFIG_ CONFIG_prefix()
32 32
33#define TF_COMMAND 0x0001
34#define TF_PARAM 0x0002
35#define TF_OPTION 0x0004
36
37enum conf_def_mode { 33enum conf_def_mode {
38 def_default, 34 def_default,
39 def_yes, 35 def_yes,
@@ -42,17 +38,6 @@ enum conf_def_mode {
42 def_random 38 def_random
43}; 39};
44 40
45#define T_OPT_MODULES 1
46#define T_OPT_DEFCONFIG_LIST 2
47#define T_OPT_ALLNOCONFIG_Y 4
48
49struct kconf_id {
50 const char *name;
51 int token;
52 unsigned int flags;
53 enum symbol_type stype;
54};
55
56extern int yylineno; 41extern int yylineno;
57void zconfdump(FILE *out); 42void zconfdump(FILE *out);
58void zconf_starthelp(void); 43void zconf_starthelp(void);
@@ -91,7 +76,9 @@ void menu_add_visibility(struct expr *dep);
91struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep); 76struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
92void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); 77void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
93void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep); 78void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
94void menu_add_option(int token, char *arg); 79void menu_add_option_modules(void);
80void menu_add_option_defconfig_list(void);
81void menu_add_option_allnoconfig_y(void);
95void menu_finalize(struct menu *parent); 82void menu_finalize(struct menu *parent);
96void menu_set_type(int type); 83void menu_set_type(int type);
97 84
@@ -103,6 +90,9 @@ void *xrealloc(void *p, size_t size);
103char *xstrdup(const char *s); 90char *xstrdup(const char *s);
104char *xstrndup(const char *s, size_t n); 91char *xstrndup(const char *s, size_t n);
105 92
93/* zconf.l */
94int yylex(void);
95
106struct gstr { 96struct gstr {
107 size_t len; 97 size_t len;
108 char *s; 98 char *s;
@@ -121,6 +111,7 @@ const char *str_get(struct gstr *gs);
121/* symbol.c */ 111/* symbol.c */
122void sym_clear_all_valid(void); 112void sym_clear_all_valid(void);
123struct symbol *sym_choice_default(struct symbol *sym); 113struct symbol *sym_choice_default(struct symbol *sym);
114struct property *sym_get_range_prop(struct symbol *sym);
124const char *sym_get_string_default(struct symbol *sym); 115const char *sym_get_string_default(struct symbol *sym);
125struct symbol *sym_check_deps(struct symbol *sym); 116struct symbol *sym_check_deps(struct symbol *sym);
126struct property *prop_alloc(enum prop_type type, struct symbol *sym); 117struct property *prop_alloc(enum prop_type type, struct symbol *sym);
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index 2e96323ad11b..fd161cfff121 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * checklist.c -- implements the checklist box 3 * checklist.c -- implements the checklist box
3 * 4 *
@@ -5,20 +6,6 @@
5 * Stuart Herbert - S.Herbert@sheffield.ac.uk: radiolist extension 6 * Stuart Herbert - S.Herbert@sheffield.ac.uk: radiolist extension
6 * Alessandro Rubini - rubini@ipvvis.unipv.it: merged the two 7 * Alessandro Rubini - rubini@ipvvis.unipv.it: merged the two
7 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) 8 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 9 */
23 10
24#include "dialog.h" 11#include "dialog.h"
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index 0b00be5abaa6..68b565e3c495 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -1,21 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
1/* 2/*
2 * dialog.h -- common declarations for all dialog modules 3 * dialog.h -- common declarations for all dialog modules
3 * 4 *
4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 6 */
20 7
21#include <sys/types.h> 8#include <sys/types.h>
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index fe82ff6d744e..611945611bf8 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -1,22 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * inputbox.c -- implements the input box 3 * inputbox.c -- implements the input box
3 * 4 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) 6 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 7 */
21 8
22#include "dialog.h" 9#include "dialog.h"
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index d70cab36137e..58c2f8afe59b 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -1,22 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * menubox.c -- implements the menu box 3 * menubox.c -- implements the menu box
3 * 4 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) 6 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 7 */
21 8
22/* 9/*
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index 88d2818ed956..4e339b12664e 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -1,22 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * textbox.c -- implements the text box 3 * textbox.c -- implements the text box
3 * 4 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) 6 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 7 */
21 8
22#include "dialog.h" 9#include "dialog.h"
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index f7abdeb92af0..1b490d4af0d3 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -1,22 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * util.c 3 * util.c
3 * 4 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) 6 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 7 */
21 8
22#include <stdarg.h> 9#include <stdarg.h>
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index cd1223c903d1..bcaac9b7bab2 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -1,22 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0+
1/* 2/*
2 * yesno.c -- implements the yes/no box 3 * yesno.c -- implements the yes/no box
3 * 4 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) 6 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 7 */
21 8
22#include "dialog.h" 9#include "dialog.h"
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 143c05fec161..5f8c82a4cb08 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 * 4 *
5 * Introduced single menu mode (show all sub-menus in one large tree). 5 * Introduced single menu mode (show all sub-menus in one large tree).
6 * 2002-11-06 Petr Baudis <pasky@ucw.cz> 6 * 2002-11-06 Petr Baudis <pasky@ucw.cz>
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 4cf15d449c05..d9d16469859a 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <ctype.h> 6#include <ctype.h>
@@ -195,29 +195,26 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
195 menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep); 195 menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
196} 196}
197 197
198void menu_add_option(int token, char *arg) 198void menu_add_option_modules(void)
199{ 199{
200 switch (token) { 200 if (modules_sym)
201 case T_OPT_MODULES: 201 zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'",
202 if (modules_sym) 202 current_entry->sym->name, modules_sym->name);
203 zconf_error("symbol '%s' redefines option 'modules'" 203 modules_sym = current_entry->sym;
204 " already defined by symbol '%s'", 204}
205 current_entry->sym->name, 205
206 modules_sym->name 206void menu_add_option_defconfig_list(void)
207 ); 207{
208 modules_sym = current_entry->sym; 208 if (!sym_defconfig_list)
209 break; 209 sym_defconfig_list = current_entry->sym;
210 case T_OPT_DEFCONFIG_LIST: 210 else if (sym_defconfig_list != current_entry->sym)
211 if (!sym_defconfig_list) 211 zconf_error("trying to redefine defconfig symbol");
212 sym_defconfig_list = current_entry->sym; 212 sym_defconfig_list->flags |= SYMBOL_NO_WRITE;
213 else if (sym_defconfig_list != current_entry->sym) 213}
214 zconf_error("trying to redefine defconfig symbol"); 214
215 sym_defconfig_list->flags |= SYMBOL_NO_WRITE; 215void menu_add_option_allnoconfig_y(void)
216 break; 216{
217 case T_OPT_ALLNOCONFIG_Y: 217 current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
218 current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y;
219 break;
220 }
221} 218}
222 219
223static int menu_validate_number(struct symbol *sym, struct symbol *sym2) 220static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
diff --git a/scripts/kconfig/merge_config.sh b/scripts/kconfig/merge_config.sh
index 0ef906499646..d924c51d28b7 100755
--- a/scripts/kconfig/merge_config.sh
+++ b/scripts/kconfig/merge_config.sh
@@ -1,4 +1,6 @@
1#!/bin/sh 1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
2# merge_config.sh - Takes a list of config fragment values, and merges 4# merge_config.sh - Takes a list of config fragment values, and merges
3# them one by one. Provides warnings on overridden values, and specified 5# them one by one. Provides warnings on overridden values, and specified
4# values that did not make it to the resulting .config file (due to missed 6# values that did not make it to the resulting .config file (due to missed
@@ -10,18 +12,10 @@
10# 12#
11# Copyright (c) 2009-2010 Wind River Systems, Inc. 13# Copyright (c) 2009-2010 Wind River Systems, Inc.
12# Copyright 2011 Linaro 14# Copyright 2011 Linaro
13#
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License version 2 as
16# published by the Free Software Foundation.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21# See the GNU General Public License for more details.
22 15
23clean_up() { 16clean_up() {
24 rm -f $TMP_FILE 17 rm -f $TMP_FILE
18 rm -f $MERGE_FILE
25 exit 19 exit
26} 20}
27trap clean_up HUP INT TERM 21trap clean_up HUP INT TERM
@@ -32,6 +26,7 @@ usage() {
32 echo " -m only merge the fragments, do not execute the make command" 26 echo " -m only merge the fragments, do not execute the make command"
33 echo " -n use allnoconfig instead of alldefconfig" 27 echo " -n use allnoconfig instead of alldefconfig"
34 echo " -r list redundant entries when merging fragments" 28 echo " -r list redundant entries when merging fragments"
29 echo " -y make builtin have precedence over modules"
35 echo " -O dir to put generated output files. Consider setting \$KCONFIG_CONFIG instead." 30 echo " -O dir to put generated output files. Consider setting \$KCONFIG_CONFIG instead."
36 echo 31 echo
37 echo "Used prefix: '$CONFIG_PREFIX'. You can redefine it with \$CONFIG_ environment variable." 32 echo "Used prefix: '$CONFIG_PREFIX'. You can redefine it with \$CONFIG_ environment variable."
@@ -40,6 +35,7 @@ usage() {
40RUNMAKE=true 35RUNMAKE=true
41ALLTARGET=alldefconfig 36ALLTARGET=alldefconfig
42WARNREDUN=false 37WARNREDUN=false
38BUILTIN=false
43OUTPUT=. 39OUTPUT=.
44CONFIG_PREFIX=${CONFIG_-CONFIG_} 40CONFIG_PREFIX=${CONFIG_-CONFIG_}
45 41
@@ -64,6 +60,11 @@ while true; do
64 shift 60 shift
65 continue 61 continue
66 ;; 62 ;;
63 "-y")
64 BUILTIN=true
65 shift
66 continue
67 ;;
67 "-O") 68 "-O")
68 if [ -d $2 ];then 69 if [ -d $2 ];then
69 OUTPUT=$(echo $2 | sed 's/\/*$//') 70 OUTPUT=$(echo $2 | sed 's/\/*$//')
@@ -106,32 +107,45 @@ SED_CONFIG_EXP1="s/^\(${CONFIG_PREFIX}[a-zA-Z0-9_]*\)=.*/\1/p"
106SED_CONFIG_EXP2="s/^# \(${CONFIG_PREFIX}[a-zA-Z0-9_]*\) is not set$/\1/p" 107SED_CONFIG_EXP2="s/^# \(${CONFIG_PREFIX}[a-zA-Z0-9_]*\) is not set$/\1/p"
107 108
108TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX) 109TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
110MERGE_FILE=$(mktemp ./.merge_tmp.config.XXXXXXXXXX)
109 111
110echo "Using $INITFILE as base" 112echo "Using $INITFILE as base"
111cat $INITFILE > $TMP_FILE 113cat $INITFILE > $TMP_FILE
112 114
113# Merge files, printing warnings on overridden values 115# Merge files, printing warnings on overridden values
114for MERGE_FILE in $MERGE_LIST ; do 116for ORIG_MERGE_FILE in $MERGE_LIST ; do
115 echo "Merging $MERGE_FILE" 117 echo "Merging $ORIG_MERGE_FILE"
116 if [ ! -r "$MERGE_FILE" ]; then 118 if [ ! -r "$ORIG_MERGE_FILE" ]; then
117 echo "The merge file '$MERGE_FILE' does not exist. Exit." >&2 119 echo "The merge file '$ORIG_MERGE_FILE' does not exist. Exit." >&2
118 exit 1 120 exit 1
119 fi 121 fi
122 cat $ORIG_MERGE_FILE > $MERGE_FILE
120 CFG_LIST=$(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $MERGE_FILE) 123 CFG_LIST=$(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $MERGE_FILE)
121 124
122 for CFG in $CFG_LIST ; do 125 for CFG in $CFG_LIST ; do
123 grep -q -w $CFG $TMP_FILE || continue 126 grep -q -w $CFG $TMP_FILE || continue
124 PREV_VAL=$(grep -w $CFG $TMP_FILE) 127 PREV_VAL=$(grep -w $CFG $TMP_FILE)
125 NEW_VAL=$(grep -w $CFG $MERGE_FILE) 128 NEW_VAL=$(grep -w $CFG $MERGE_FILE)
126 if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then 129 BUILTIN_FLAG=false
127 echo Value of $CFG is redefined by fragment $MERGE_FILE: 130 if [ "$BUILTIN" = "true" ] && [ "${NEW_VAL#CONFIG_*=}" = "m" ] && [ "${PREV_VAL#CONFIG_*=}" = "y" ]; then
131 echo Previous value: $PREV_VAL
132 echo New value: $NEW_VAL
133 echo -y passed, will not demote y to m
134 echo
135 BUILTIN_FLAG=true
136 elif [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
137 echo Value of $CFG is redefined by fragment $ORIG_MERGE_FILE:
128 echo Previous value: $PREV_VAL 138 echo Previous value: $PREV_VAL
129 echo New value: $NEW_VAL 139 echo New value: $NEW_VAL
130 echo 140 echo
131 elif [ "$WARNREDUN" = "true" ]; then 141 elif [ "$WARNREDUN" = "true" ]; then
132 echo Value of $CFG is redundant by fragment $MERGE_FILE: 142 echo Value of $CFG is redundant by fragment $ORIG_MERGE_FILE:
143 fi
144 if [ "$BUILTIN_FLAG" = "false" ]; then
145 sed -i "/$CFG[ =]/d" $TMP_FILE
146 else
147 sed -i "/$CFG[ =]/d" $MERGE_FILE
133 fi 148 fi
134 sed -i "/$CFG[ =]/d" $TMP_FILE
135 done 149 done
136 cat $MERGE_FILE >> $TMP_FILE 150 cat $MERGE_FILE >> $TMP_FILE
137done 151done
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 1ef232ae5ab9..a4670f4e825a 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -1,9 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com? 3 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com>
3 * Released under the terms of the GNU GPL v2.0.
4 * 4 *
5 * Derived from menuconfig. 5 * Derived from menuconfig.
6 *
7 */ 6 */
8#ifndef _GNU_SOURCE 7#ifndef _GNU_SOURCE
9#define _GNU_SOURCE 8#define _GNU_SOURCE
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 88874acfda36..7be620a1fcdb 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -1,9 +1,8 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com? 3 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com>
3 * Released under the terms of the GNU GPL v2.0.
4 * 4 *
5 * Derived from menuconfig. 5 * Derived from menuconfig.
6 *
7 */ 6 */
8#include "nconf.h" 7#include "nconf.h"
9#include "lkc.h" 8#include "lkc.h"
diff --git a/scripts/kconfig/nconf.h b/scripts/kconfig/nconf.h
index 2b9e19f603c4..fa5245eb93a7 100644
--- a/scripts/kconfig/nconf.h
+++ b/scripts/kconfig/nconf.h
@@ -1,9 +1,8 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com? 3 * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com>
3 * Released under the terms of the GNU GPL v2.0.
4 * 4 *
5 * Derived from menuconfig. 5 * Derived from menuconfig.
6 *
7 */ 6 */
8 7
9#include <ctype.h> 8#include <ctype.h>
diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c
index 5ca2df790d3c..592dfbfa9fb3 100644
--- a/scripts/kconfig/preprocess.c
+++ b/scripts/kconfig/preprocess.c
@@ -2,6 +2,7 @@
2// 2//
3// Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com> 3// Copyright (C) 2018 Masahiro Yamada <yamada.masahiro@socionext.com>
4 4
5#include <ctype.h>
5#include <stdarg.h> 6#include <stdarg.h>
6#include <stdbool.h> 7#include <stdbool.h>
7#include <stdio.h> 8#include <stdio.h>
@@ -9,6 +10,7 @@
9#include <string.h> 10#include <string.h>
10 11
11#include "list.h" 12#include "list.h"
13#include "lkc.h"
12 14
13#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 15#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
14 16
@@ -555,8 +557,7 @@ char *expand_string(const char *in)
555 557
556static bool is_end_of_token(char c) 558static bool is_end_of_token(char c)
557{ 559{
558 /* Why are '.' and '/' valid characters for symbols? */ 560 return !(isalnum(c) || c == '_' || c == '-');
559 return !(isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/');
560} 561}
561 562
562/* 563/*
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index ef4310f2558b..8be8a70c5542 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -1,7 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com> 4 * Copyright (C) 2015 Boris Barbulovski <bbarbulovski@gmail.com>
4 * Released under the terms of the GNU GPL v2.0.
5 */ 5 */
6 6
7#include <qglobal.h> 7#include <qglobal.h>
@@ -32,7 +32,7 @@
32#include "qconf.h" 32#include "qconf.h"
33 33
34#include "qconf.moc" 34#include "qconf.moc"
35#include "images.c" 35#include "images.h"
36 36
37 37
38static QApplication *configApp; 38static QApplication *configApp;
diff --git a/scripts/kconfig/qconf.h b/scripts/kconfig/qconf.h
index a40036d1b059..41df466e67d9 100644
--- a/scripts/kconfig/qconf.h
+++ b/scripts/kconfig/qconf.h
@@ -1,6 +1,6 @@
1/* SPDX-License-Identifier: GPL-2.0 */
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <QTextBrowser> 6#include <QTextBrowser>
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
index 4686531e2f8c..08d76d7b3b81 100755
--- a/scripts/kconfig/streamline_config.pl
+++ b/scripts/kconfig/streamline_config.pl
@@ -1,7 +1,7 @@
1#!/usr/bin/env perl 1#!/usr/bin/env perl
2# SPDX-License-Identifier: GPL-2.0
2# 3#
3# Copyright 2005-2009 - Steven Rostedt 4# Copyright 2005-2009 - Steven Rostedt
4# Licensed under the terms of the GNU GPL License version 2
5# 5#
6# It's simple enough to figure out how this works. 6# It's simple enough to figure out how this works.
7# If not, then you can ask me at stripconfig@goodmis.org 7# If not, then you can ask me at stripconfig@goodmis.org
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 703b9b899ee9..1f9266dadedf 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
4 */ 4 */
5 5
6#include <ctype.h> 6#include <ctype.h>
@@ -61,8 +61,6 @@ const char *sym_type_name(enum symbol_type type)
61 return "string"; 61 return "string";
62 case S_UNKNOWN: 62 case S_UNKNOWN:
63 return "unknown"; 63 return "unknown";
64 case S_OTHER:
65 break;
66 } 64 }
67 return "???"; 65 return "???";
68} 66}
@@ -88,7 +86,7 @@ static struct property *sym_get_default_prop(struct symbol *sym)
88 return NULL; 86 return NULL;
89} 87}
90 88
91static struct property *sym_get_range_prop(struct symbol *sym) 89struct property *sym_get_range_prop(struct symbol *sym)
92{ 90{
93 struct property *prop; 91 struct property *prop;
94 92
@@ -757,7 +755,6 @@ const char *sym_get_string_default(struct symbol *sym)
757 return str; 755 return str;
758 case S_STRING: 756 case S_STRING:
759 return str; 757 return str;
760 case S_OTHER:
761 case S_UNKNOWN: 758 case S_UNKNOWN:
762 break; 759 break;
763 } 760 }
diff --git a/scripts/kconfig/tests/auto_submenu/Kconfig b/scripts/kconfig/tests/auto_submenu/Kconfig
index c17bf2caa7e6..b20761edc2f4 100644
--- a/scripts/kconfig/tests/auto_submenu/Kconfig
+++ b/scripts/kconfig/tests/auto_submenu/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config A 3config A
2 bool "A" 4 bool "A"
3 default y 5 default y
diff --git a/scripts/kconfig/tests/auto_submenu/__init__.py b/scripts/kconfig/tests/auto_submenu/__init__.py
index 32e79b85faeb..25abd927fd0a 100644
--- a/scripts/kconfig/tests/auto_submenu/__init__.py
+++ b/scripts/kconfig/tests/auto_submenu/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Create submenu for symbols that depend on the preceding one. 3Create submenu for symbols that depend on the preceding one.
3 4
diff --git a/scripts/kconfig/tests/choice/Kconfig b/scripts/kconfig/tests/choice/Kconfig
index cc60e9ce2c03..a412205b1b0c 100644
--- a/scripts/kconfig/tests/choice/Kconfig
+++ b/scripts/kconfig/tests/choice/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config MODULES 3config MODULES
2 bool "Enable loadable module support" 4 bool "Enable loadable module support"
3 option modules 5 option modules
diff --git a/scripts/kconfig/tests/choice/__init__.py b/scripts/kconfig/tests/choice/__init__.py
index 9edcc5262134..4318fce05912 100644
--- a/scripts/kconfig/tests/choice/__init__.py
+++ b/scripts/kconfig/tests/choice/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Basic choice tests. 3Basic choice tests.
3 4
diff --git a/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig b/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig
index 11ac25c26040..7106c26bb3a8 100644
--- a/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig
+++ b/scripts/kconfig/tests/choice_value_with_m_dep/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config MODULES 3config MODULES
2 def_bool y 4 def_bool y
3 option modules 5 option modules
diff --git a/scripts/kconfig/tests/choice_value_with_m_dep/__init__.py b/scripts/kconfig/tests/choice_value_with_m_dep/__init__.py
index f8d728c7b101..075b4e08696e 100644
--- a/scripts/kconfig/tests/choice_value_with_m_dep/__init__.py
+++ b/scripts/kconfig/tests/choice_value_with_m_dep/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Hide tristate choice values with mod dependency in y choice. 3Hide tristate choice values with mod dependency in y choice.
3 4
diff --git a/scripts/kconfig/tests/err_recursive_inc/__init__.py b/scripts/kconfig/tests/err_recursive_inc/__init__.py
index 0e4c839c54aa..27aa1895a0b2 100644
--- a/scripts/kconfig/tests/err_recursive_inc/__init__.py
+++ b/scripts/kconfig/tests/err_recursive_inc/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Detect recursive inclusion error. 3Detect recursive inclusion error.
3 4
diff --git a/scripts/kconfig/tests/inter_choice/Kconfig b/scripts/kconfig/tests/inter_choice/Kconfig
index e44449f075df..5698a4018dd0 100644
--- a/scripts/kconfig/tests/inter_choice/Kconfig
+++ b/scripts/kconfig/tests/inter_choice/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config MODULES 3config MODULES
2 def_bool y 4 def_bool y
3 option modules 5 option modules
diff --git a/scripts/kconfig/tests/inter_choice/__init__.py b/scripts/kconfig/tests/inter_choice/__init__.py
index 5c7fc365ed40..ffea6b1148a6 100644
--- a/scripts/kconfig/tests/inter_choice/__init__.py
+++ b/scripts/kconfig/tests/inter_choice/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Do not affect user-assigned choice value by another choice. 3Do not affect user-assigned choice value by another choice.
3 4
diff --git a/scripts/kconfig/tests/new_choice_with_dep/Kconfig b/scripts/kconfig/tests/new_choice_with_dep/Kconfig
index 53ef1b86e7bf..127731c046b5 100644
--- a/scripts/kconfig/tests/new_choice_with_dep/Kconfig
+++ b/scripts/kconfig/tests/new_choice_with_dep/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config A 3config A
2 bool "A" 4 bool "A"
3 help 5 help
diff --git a/scripts/kconfig/tests/new_choice_with_dep/__init__.py b/scripts/kconfig/tests/new_choice_with_dep/__init__.py
index f0e0ead0f32f..fe9d322539c9 100644
--- a/scripts/kconfig/tests/new_choice_with_dep/__init__.py
+++ b/scripts/kconfig/tests/new_choice_with_dep/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Ask new choice values when they become visible. 3Ask new choice values when they become visible.
3 4
diff --git a/scripts/kconfig/tests/no_write_if_dep_unmet/Kconfig b/scripts/kconfig/tests/no_write_if_dep_unmet/Kconfig
index c00b8fe54f45..4767aab6d8e3 100644
--- a/scripts/kconfig/tests/no_write_if_dep_unmet/Kconfig
+++ b/scripts/kconfig/tests/no_write_if_dep_unmet/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1config A 3config A
2 bool "A" 4 bool "A"
3 5
diff --git a/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py b/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py
index 207261b0fe00..ffd469d1f226 100644
--- a/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py
+++ b/scripts/kconfig/tests/no_write_if_dep_unmet/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Do not write choice values to .config if the dependency is unmet. 3Do not write choice values to .config if the dependency is unmet.
3 4
diff --git a/scripts/kconfig/tests/rand_nested_choice/Kconfig b/scripts/kconfig/tests/rand_nested_choice/Kconfig
index c591d512929f..8350de7f732b 100644
--- a/scripts/kconfig/tests/rand_nested_choice/Kconfig
+++ b/scripts/kconfig/tests/rand_nested_choice/Kconfig
@@ -1,3 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
1choice 3choice
2 prompt "choice" 4 prompt "choice"
3 5
diff --git a/scripts/kconfig/tests/rand_nested_choice/__init__.py b/scripts/kconfig/tests/rand_nested_choice/__init__.py
index e729a4e85218..9e4b2db53581 100644
--- a/scripts/kconfig/tests/rand_nested_choice/__init__.py
+++ b/scripts/kconfig/tests/rand_nested_choice/__init__.py
@@ -1,3 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
1""" 2"""
2Set random values recursively in nested choices. 3Set random values recursively in nested choices.
3 4
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index d999683bb2a7..29585394df71 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -1,8 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002-2005 Roman Zippel <zippel@linux-m68k.org>
3 * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org> 4 * Copyright (C) 2002-2005 Sam Ravnborg <sam@ravnborg.org>
4 *
5 * Released under the terms of the GNU GPL v2.0.
6 */ 5 */
7 6
8#include <stdarg.h> 7#include <stdarg.h>
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 25bd2b89fe3f..b2d0a3b0bce9 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -1,11 +1,11 @@
1%option nostdinit noyywrap never-interactive full ecs 1/* SPDX-License-Identifier: GPL-2.0 */
2%option 8bit nodefault yylineno
3%x COMMAND HELP STRING PARAM ASSIGN_VAL
4%{
5/* 2/*
6 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
7 * Released under the terms of the GNU GPL v2.0.
8 */ 4 */
5%option nostdinit noyywrap never-interactive full ecs
6%option 8bit nodefault yylineno
7%x ASSIGN_VAL HELP STRING
8%{
9 9
10#include <assert.h> 10#include <assert.h>
11#include <limits.h> 11#include <limits.h>
@@ -15,6 +15,9 @@
15#include <unistd.h> 15#include <unistd.h>
16 16
17#include "lkc.h" 17#include "lkc.h"
18#include "zconf.tab.h"
19
20#define YY_DECL static int yylex1(void)
18 21
19#define START_STRSIZE 16 22#define START_STRSIZE 16
20 23
@@ -23,6 +26,8 @@ static struct {
23 int lineno; 26 int lineno;
24} current_pos; 27} current_pos;
25 28
29static int prev_prev_token = T_EOL;
30static int prev_token = T_EOL;
26static char *text; 31static char *text;
27static int text_size, text_asize; 32static int text_size, text_asize;
28 33
@@ -73,7 +78,7 @@ static void warn_ignored_character(char chr)
73{ 78{
74 fprintf(stderr, 79 fprintf(stderr,
75 "%s:%d:warning: ignoring unsupported character '%c'\n", 80 "%s:%d:warning: ignoring unsupported character '%c'\n",
76 zconf_curname(), zconf_lineno(), chr); 81 current_file->name, yylineno, chr);
77} 82}
78%} 83%}
79 84
@@ -83,54 +88,73 @@ n [A-Za-z0-9_-]
83 int str = 0; 88 int str = 0;
84 int ts, i; 89 int ts, i;
85 90
86[ \t]*#.*\n | 91#.* /* ignore comment */
87[ \t]*\n { 92[ \t]* /* whitespaces */
88 return T_EOL; 93\\\n /* escaped new line */
89} 94\n return T_EOL;
90[ \t]*#.* 95"allnoconfig_y" return T_ALLNOCONFIG_Y;
91 96"bool" return T_BOOL;
92 97"choice" return T_CHOICE;
93[ \t]+ { 98"comment" return T_COMMENT;
94 BEGIN(COMMAND); 99"config" return T_CONFIG;
95} 100"def_bool" return T_DEF_BOOL;
96 101"def_tristate" return T_DEF_TRISTATE;
97. { 102"default" return T_DEFAULT;
98 unput(yytext[0]); 103"defconfig_list" return T_DEFCONFIG_LIST;
99 BEGIN(COMMAND); 104"depends" return T_DEPENDS;
100} 105"endchoice" return T_ENDCHOICE;
101 106"endif" return T_ENDIF;
102 107"endmenu" return T_ENDMENU;
103<COMMAND>{ 108"help"|"---help---" return T_HELP;
104 {n}+ { 109"hex" return T_HEX;
105 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); 110"if" return T_IF;
106 current_pos.file = current_file; 111"imply" return T_IMPLY;
107 current_pos.lineno = yylineno; 112"int" return T_INT;
108 if (id && id->flags & TF_COMMAND) { 113"mainmenu" return T_MAINMENU;
109 BEGIN(PARAM); 114"menu" return T_MENU;
110 yylval.id = id; 115"menuconfig" return T_MENUCONFIG;
111 return id->token; 116"modules" return T_MODULES;
112 } 117"on" return T_ON;
113 alloc_string(yytext, yyleng); 118"option" return T_OPTION;
114 yylval.string = text; 119"optional" return T_OPTIONAL;
115 return T_VARIABLE; 120"prompt" return T_PROMPT;
116 } 121"range" return T_RANGE;
117 ({n}|$)+ { 122"select" return T_SELECT;
118 /* this token includes at least one '$' */ 123"source" return T_SOURCE;
119 yylval.string = expand_token(yytext, yyleng); 124"string" return T_STRING;
120 if (strlen(yylval.string)) 125"tristate" return T_TRISTATE;
121 return T_VARIABLE; 126"visible" return T_VISIBLE;
122 free(yylval.string); 127"||" return T_OR;
123 } 128"&&" return T_AND;
124 "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; } 129"=" return T_EQUAL;
125 ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; } 130"!=" return T_UNEQUAL;
126 "+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; } 131"<" return T_LESS;
127 [[:blank:]]+ 132"<=" return T_LESS_EQUAL;
128 . warn_ignored_character(*yytext); 133">" return T_GREATER;
129 \n { 134">=" return T_GREATER_EQUAL;
130 BEGIN(INITIAL); 135"!" return T_NOT;
131 return T_EOL; 136"(" return T_OPEN_PAREN;
132 } 137")" return T_CLOSE_PAREN;
133} 138":=" return T_COLON_EQUAL;
139"+=" return T_PLUS_EQUAL;
140\"|\' {
141 str = yytext[0];
142 new_string();
143 BEGIN(STRING);
144 }
145{n}+ {
146 alloc_string(yytext, yyleng);
147 yylval.string = text;
148 return T_WORD;
149 }
150({n}|$)+ {
151 /* this token includes at least one '$' */
152 yylval.string = expand_token(yytext, yyleng);
153 if (strlen(yylval.string))
154 return T_WORD;
155 free(yylval.string);
156 }
157. warn_ignored_character(*yytext);
134 158
135<ASSIGN_VAL>{ 159<ASSIGN_VAL>{
136 [^[:blank:]\n]+.* { 160 [^[:blank:]\n]+.* {
@@ -142,71 +166,17 @@ n [A-Za-z0-9_-]
142 . 166 .
143} 167}
144 168
145<PARAM>{
146 "&&" return T_AND;
147 "||" return T_OR;
148 "(" return T_OPEN_PAREN;
149 ")" return T_CLOSE_PAREN;
150 "!" return T_NOT;
151 "=" return T_EQUAL;
152 "!=" return T_UNEQUAL;
153 "<=" return T_LESS_EQUAL;
154 ">=" return T_GREATER_EQUAL;
155 "<" return T_LESS;
156 ">" return T_GREATER;
157 \"|\' {
158 str = yytext[0];
159 new_string();
160 BEGIN(STRING);
161 }
162 \n BEGIN(INITIAL); return T_EOL;
163 ({n}|[/.])+ {
164 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
165 if (id && id->flags & TF_PARAM) {
166 yylval.id = id;
167 return id->token;
168 }
169 alloc_string(yytext, yyleng);
170 yylval.string = text;
171 return T_WORD;
172 }
173 ({n}|[/.$])+ {
174 /* this token includes at least one '$' */
175 yylval.string = expand_token(yytext, yyleng);
176 if (strlen(yylval.string))
177 return T_WORD;
178 free(yylval.string);
179 }
180 #.* /* comment */
181 \\\n ;
182 [[:blank:]]+
183 . warn_ignored_character(*yytext);
184 <<EOF>> {
185 BEGIN(INITIAL);
186 }
187}
188
189<STRING>{ 169<STRING>{
190 "$".* append_expanded_string(yytext); 170 "$".* append_expanded_string(yytext);
191 [^$'"\\\n]+/\n {
192 append_string(yytext, yyleng);
193 yylval.string = text;
194 return T_WORD_QUOTE;
195 }
196 [^$'"\\\n]+ { 171 [^$'"\\\n]+ {
197 append_string(yytext, yyleng); 172 append_string(yytext, yyleng);
198 } 173 }
199 \\.?/\n {
200 append_string(yytext + 1, yyleng - 1);
201 yylval.string = text;
202 return T_WORD_QUOTE;
203 }
204 \\.? { 174 \\.? {
205 append_string(yytext + 1, yyleng - 1); 175 append_string(yytext + 1, yyleng - 1);
206 } 176 }
207 \'|\" { 177 \'|\" {
208 if (str == yytext[0]) { 178 if (str == yytext[0]) {
209 BEGIN(PARAM); 179 BEGIN(INITIAL);
210 yylval.string = text; 180 yylval.string = text;
211 return T_WORD_QUOTE; 181 return T_WORD_QUOTE;
212 } else 182 } else
@@ -216,11 +186,15 @@ n [A-Za-z0-9_-]
216 fprintf(stderr, 186 fprintf(stderr,
217 "%s:%d:warning: multi-line strings not supported\n", 187 "%s:%d:warning: multi-line strings not supported\n",
218 zconf_curname(), zconf_lineno()); 188 zconf_curname(), zconf_lineno());
189 unput('\n');
219 BEGIN(INITIAL); 190 BEGIN(INITIAL);
220 return T_EOL; 191 yylval.string = text;
192 return T_WORD_QUOTE;
221 } 193 }
222 <<EOF>> { 194 <<EOF>> {
223 BEGIN(INITIAL); 195 BEGIN(INITIAL);
196 yylval.string = text;
197 return T_WORD_QUOTE;
224 } 198 }
225} 199}
226 200
@@ -271,6 +245,12 @@ n [A-Za-z0-9_-]
271} 245}
272 246
273<<EOF>> { 247<<EOF>> {
248 BEGIN(INITIAL);
249
250 if (prev_token != T_EOL && prev_token != T_HELPTEXT)
251 fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
252 current_file->name, yylineno);
253
274 if (current_file) { 254 if (current_file) {
275 zconf_endfile(); 255 zconf_endfile();
276 return T_EOL; 256 return T_EOL;
@@ -280,6 +260,41 @@ n [A-Za-z0-9_-]
280} 260}
281 261
282%% 262%%
263
264/* second stage lexer */
265int yylex(void)
266{
267 int token;
268
269repeat:
270 token = yylex1();
271
272 if (prev_token == T_EOL || prev_token == T_HELPTEXT) {
273 if (token == T_EOL) {
274 /* Do not pass unneeded T_EOL to the parser. */
275 goto repeat;
276 } else {
277 /*
278 * For the parser, update file/lineno at the first token
279 * of each statement. Generally, \n is a statement
280 * terminator in Kconfig, but it is not always true
281 * because \n could be escaped by a backslash.
282 */
283 current_pos.file = current_file;
284 current_pos.lineno = yylineno;
285 }
286 }
287
288 if (prev_prev_token == T_EOL && prev_token == T_WORD &&
289 (token == T_EQUAL || token == T_COLON_EQUAL || token == T_PLUS_EQUAL))
290 BEGIN(ASSIGN_VAL);
291
292 prev_prev_token = prev_token;
293 prev_token = token;
294
295 return token;
296}
297
283static char *expand_token(const char *in, size_t n) 298static char *expand_token(const char *in, size_t n)
284{ 299{
285 char *out; 300 char *out;
diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y
index 22fceb264cf5..60936c76865b 100644
--- a/scripts/kconfig/zconf.y
+++ b/scripts/kconfig/zconf.y
@@ -1,8 +1,8 @@
1%{ 1/* SPDX-License-Identifier: GPL-2.0 */
2/* 2/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
5 */ 4 */
5%{
6 6
7#include <ctype.h> 7#include <ctype.h>
8#include <stdarg.h> 8#include <stdarg.h>
@@ -20,66 +20,68 @@
20 20
21int cdebug = PRINTD; 21int cdebug = PRINTD;
22 22
23int yylex(void);
24static void yyerror(const char *err); 23static void yyerror(const char *err);
25static void zconfprint(const char *err, ...); 24static void zconfprint(const char *err, ...);
26static void zconf_error(const char *err, ...); 25static void zconf_error(const char *err, ...);
27static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken); 26static bool zconf_endtoken(const char *tokenname,
27 const char *expected_tokenname);
28 28
29struct symbol *symbol_hash[SYMBOL_HASHSIZE]; 29struct symbol *symbol_hash[SYMBOL_HASHSIZE];
30 30
31static struct menu *current_menu, *current_entry; 31static struct menu *current_menu, *current_entry;
32 32
33%} 33%}
34%expect 30
35 34
36%union 35%union
37{ 36{
38 char *string; 37 char *string;
39 struct file *file;
40 struct symbol *symbol; 38 struct symbol *symbol;
41 struct expr *expr; 39 struct expr *expr;
42 struct menu *menu; 40 struct menu *menu;
43 const struct kconf_id *id; 41 enum symbol_type type;
44 enum variable_flavor flavor; 42 enum variable_flavor flavor;
45} 43}
46 44
47%token <id>T_MAINMENU
48%token <id>T_MENU
49%token <id>T_ENDMENU
50%token <id>T_SOURCE
51%token <id>T_CHOICE
52%token <id>T_ENDCHOICE
53%token <id>T_COMMENT
54%token <id>T_CONFIG
55%token <id>T_MENUCONFIG
56%token <id>T_HELP
57%token <string> T_HELPTEXT 45%token <string> T_HELPTEXT
58%token <id>T_IF
59%token <id>T_ENDIF
60%token <id>T_DEPENDS
61%token <id>T_OPTIONAL
62%token <id>T_PROMPT
63%token <id>T_TYPE
64%token <id>T_DEFAULT
65%token <id>T_SELECT
66%token <id>T_IMPLY
67%token <id>T_RANGE
68%token <id>T_VISIBLE
69%token <id>T_OPTION
70%token <id>T_ON
71%token <string> T_WORD 46%token <string> T_WORD
72%token <string> T_WORD_QUOTE 47%token <string> T_WORD_QUOTE
73%token T_UNEQUAL 48%token T_ALLNOCONFIG_Y
74%token T_LESS 49%token T_BOOL
75%token T_LESS_EQUAL 50%token T_CHOICE
76%token T_GREATER
77%token T_GREATER_EQUAL
78%token T_CLOSE_PAREN 51%token T_CLOSE_PAREN
52%token T_COLON_EQUAL
53%token T_COMMENT
54%token T_CONFIG
55%token T_DEFAULT
56%token T_DEFCONFIG_LIST
57%token T_DEF_BOOL
58%token T_DEF_TRISTATE
59%token T_DEPENDS
60%token T_ENDCHOICE
61%token T_ENDIF
62%token T_ENDMENU
63%token T_HELP
64%token T_HEX
65%token T_IF
66%token T_IMPLY
67%token T_INT
68%token T_MAINMENU
69%token T_MENU
70%token T_MENUCONFIG
71%token T_MODULES
72%token T_ON
79%token T_OPEN_PAREN 73%token T_OPEN_PAREN
74%token T_OPTION
75%token T_OPTIONAL
76%token T_PLUS_EQUAL
77%token T_PROMPT
78%token T_RANGE
79%token T_SELECT
80%token T_SOURCE
81%token T_STRING
82%token T_TRISTATE
83%token T_VISIBLE
80%token T_EOL 84%token T_EOL
81%token <string> T_VARIABLE
82%token <flavor> T_ASSIGN
83%token <string> T_ASSIGN_VAL 85%token <string> T_ASSIGN_VAL
84 86
85%left T_OR 87%left T_OR
@@ -91,12 +93,13 @@ static struct menu *current_menu, *current_entry;
91%type <string> prompt 93%type <string> prompt
92%type <symbol> nonconst_symbol 94%type <symbol> nonconst_symbol
93%type <symbol> symbol 95%type <symbol> symbol
96%type <type> type logic_type default
94%type <expr> expr 97%type <expr> expr
95%type <expr> if_expr 98%type <expr> if_expr
96%type <id> end 99%type <string> end
97%type <id> option_name
98%type <menu> if_entry menu_entry choice_entry 100%type <menu> if_entry menu_entry choice_entry
99%type <string> symbol_option_arg word_opt assign_val 101%type <string> word_opt assign_val
102%type <flavor> assign_op
100 103
101%destructor { 104%destructor {
102 fprintf(stderr, "%s:%d: missing end statement for this entry\n", 105 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
@@ -105,15 +108,8 @@ static struct menu *current_menu, *current_entry;
105 menu_end_menu(); 108 menu_end_menu();
106} if_entry menu_entry choice_entry 109} if_entry menu_entry choice_entry
107 110
108%{
109/* Include kconf_id.c here so it can see the token constants. */
110#include "kconf_id.c"
111%}
112
113%% 111%%
114input: nl start | start; 112input: mainmenu_stmt stmt_list | stmt_list;
115
116start: mainmenu_stmt stmt_list | stmt_list;
117 113
118/* mainmenu entry */ 114/* mainmenu entry */
119 115
@@ -127,22 +123,12 @@ stmt_list:
127 | stmt_list common_stmt 123 | stmt_list common_stmt
128 | stmt_list choice_stmt 124 | stmt_list choice_stmt
129 | stmt_list menu_stmt 125 | stmt_list menu_stmt
130 | stmt_list end { zconf_error("unexpected end statement"); }
131 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); } 126 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
132 | stmt_list option_name error T_EOL
133{
134 zconf_error("unexpected option \"%s\"", $2->name);
135}
136 | stmt_list error T_EOL { zconf_error("invalid statement"); } 127 | stmt_list error T_EOL { zconf_error("invalid statement"); }
137; 128;
138 129
139option_name:
140 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
141;
142
143common_stmt: 130common_stmt:
144 T_EOL 131 if_stmt
145 | if_stmt
146 | comment_stmt 132 | comment_stmt
147 | config_stmt 133 | config_stmt
148 | menuconfig_stmt 134 | menuconfig_stmt
@@ -150,12 +136,6 @@ common_stmt:
150 | assignment_stmt 136 | assignment_stmt
151; 137;
152 138
153option_error:
154 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
155 | error T_EOL { zconf_error("invalid option"); }
156;
157
158
159/* config/menuconfig entry */ 139/* config/menuconfig entry */
160 140
161config_entry_start: T_CONFIG nonconst_symbol T_EOL 141config_entry_start: T_CONFIG nonconst_symbol T_EOL
@@ -189,19 +169,16 @@ menuconfig_stmt: menuconfig_entry_start config_option_list
189config_option_list: 169config_option_list:
190 /* empty */ 170 /* empty */
191 | config_option_list config_option 171 | config_option_list config_option
192 | config_option_list symbol_option
193 | config_option_list depends 172 | config_option_list depends
194 | config_option_list help 173 | config_option_list help
195 | config_option_list option_error
196 | config_option_list T_EOL
197; 174;
198 175
199config_option: T_TYPE prompt_stmt_opt T_EOL 176config_option: type prompt_stmt_opt T_EOL
200{ 177{
201 menu_set_type($1->stype); 178 menu_set_type($1);
202 printd(DEBUG_PARSE, "%s:%d:type(%u)\n", 179 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
203 zconf_curname(), zconf_lineno(), 180 zconf_curname(), zconf_lineno(),
204 $1->stype); 181 $1);
205}; 182};
206 183
207config_option: T_PROMPT prompt if_expr T_EOL 184config_option: T_PROMPT prompt if_expr T_EOL
@@ -210,14 +187,14 @@ config_option: T_PROMPT prompt if_expr T_EOL
210 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); 187 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
211}; 188};
212 189
213config_option: T_DEFAULT expr if_expr T_EOL 190config_option: default expr if_expr T_EOL
214{ 191{
215 menu_add_expr(P_DEFAULT, $2, $3); 192 menu_add_expr(P_DEFAULT, $2, $3);
216 if ($1->stype != S_UNKNOWN) 193 if ($1 != S_UNKNOWN)
217 menu_set_type($1->stype); 194 menu_set_type($1);
218 printd(DEBUG_PARSE, "%s:%d:default(%u)\n", 195 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
219 zconf_curname(), zconf_lineno(), 196 zconf_curname(), zconf_lineno(),
220 $1->stype); 197 $1);
221}; 198};
222 199
223config_option: T_SELECT nonconst_symbol if_expr T_EOL 200config_option: T_SELECT nonconst_symbol if_expr T_EOL
@@ -238,27 +215,20 @@ config_option: T_RANGE symbol symbol if_expr T_EOL
238 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); 215 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
239}; 216};
240 217
241symbol_option: T_OPTION symbol_option_list T_EOL 218config_option: T_OPTION T_MODULES T_EOL
242; 219{
220 menu_add_option_modules();
221};
243 222
244symbol_option_list: 223config_option: T_OPTION T_DEFCONFIG_LIST T_EOL
245 /* empty */
246 | symbol_option_list T_WORD symbol_option_arg
247{ 224{
248 const struct kconf_id *id = kconf_id_lookup($2, strlen($2)); 225 menu_add_option_defconfig_list();
249 if (id && id->flags & TF_OPTION) {
250 menu_add_option(id->token, $3);
251 free($3);
252 }
253 else
254 zconfprint("warning: ignoring unknown option %s", $2);
255 free($2);
256}; 226};
257 227
258symbol_option_arg: 228config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL
259 /* empty */ { $$ = NULL; } 229{
260 | T_EQUAL prompt { $$ = $2; } 230 menu_add_option_allnoconfig_y();
261; 231};
262 232
263/* choice entry */ 233/* choice entry */
264 234
@@ -279,7 +249,7 @@ choice_entry: choice choice_option_list
279 249
280choice_end: end 250choice_end: end
281{ 251{
282 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) { 252 if (zconf_endtoken($1, "choice")) {
283 menu_end_menu(); 253 menu_end_menu();
284 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno()); 254 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
285 } 255 }
@@ -293,8 +263,6 @@ choice_option_list:
293 | choice_option_list choice_option 263 | choice_option_list choice_option
294 | choice_option_list depends 264 | choice_option_list depends
295 | choice_option_list help 265 | choice_option_list help
296 | choice_option_list T_EOL
297 | choice_option_list option_error
298; 266;
299 267
300choice_option: T_PROMPT prompt if_expr T_EOL 268choice_option: T_PROMPT prompt if_expr T_EOL
@@ -303,15 +271,11 @@ choice_option: T_PROMPT prompt if_expr T_EOL
303 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); 271 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
304}; 272};
305 273
306choice_option: T_TYPE prompt_stmt_opt T_EOL 274choice_option: logic_type prompt_stmt_opt T_EOL
307{ 275{
308 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) { 276 menu_set_type($1);
309 menu_set_type($1->stype); 277 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
310 printd(DEBUG_PARSE, "%s:%d:type(%u)\n", 278 zconf_curname(), zconf_lineno(), $1);
311 zconf_curname(), zconf_lineno(),
312 $1->stype);
313 } else
314 YYERROR;
315}; 279};
316 280
317choice_option: T_OPTIONAL T_EOL 281choice_option: T_OPTIONAL T_EOL
@@ -322,14 +286,26 @@ choice_option: T_OPTIONAL T_EOL
322 286
323choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL 287choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
324{ 288{
325 if ($1->stype == S_UNKNOWN) { 289 menu_add_symbol(P_DEFAULT, $2, $3);
326 menu_add_symbol(P_DEFAULT, $2, $3); 290 printd(DEBUG_PARSE, "%s:%d:default\n",
327 printd(DEBUG_PARSE, "%s:%d:default\n", 291 zconf_curname(), zconf_lineno());
328 zconf_curname(), zconf_lineno());
329 } else
330 YYERROR;
331}; 292};
332 293
294type:
295 logic_type
296 | T_INT { $$ = S_INT; }
297 | T_HEX { $$ = S_HEX; }
298 | T_STRING { $$ = S_STRING; }
299
300logic_type:
301 T_BOOL { $$ = S_BOOLEAN; }
302 | T_TRISTATE { $$ = S_TRISTATE; }
303
304default:
305 T_DEFAULT { $$ = S_UNKNOWN; }
306 | T_DEF_BOOL { $$ = S_BOOLEAN; }
307 | T_DEF_TRISTATE { $$ = S_TRISTATE; }
308
333choice_block: 309choice_block:
334 /* empty */ 310 /* empty */
335 | choice_block common_stmt 311 | choice_block common_stmt
@@ -347,20 +323,13 @@ if_entry: T_IF expr T_EOL
347 323
348if_end: end 324if_end: end
349{ 325{
350 if (zconf_endtoken($1, T_IF, T_ENDIF)) { 326 if (zconf_endtoken($1, "if")) {
351 menu_end_menu(); 327 menu_end_menu();
352 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno()); 328 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
353 } 329 }
354}; 330};
355 331
356if_stmt: if_entry if_block if_end 332if_stmt: if_entry stmt_list if_end
357;
358
359if_block:
360 /* empty */
361 | if_block common_stmt
362 | if_block menu_stmt
363 | if_block choice_stmt
364; 333;
365 334
366/* menu entry */ 335/* menu entry */
@@ -372,27 +341,26 @@ menu: T_MENU prompt T_EOL
372 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); 341 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
373}; 342};
374 343
375menu_entry: menu visibility_list depends_list 344menu_entry: menu menu_option_list
376{ 345{
377 $$ = menu_add_menu(); 346 $$ = menu_add_menu();
378}; 347};
379 348
380menu_end: end 349menu_end: end
381{ 350{
382 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) { 351 if (zconf_endtoken($1, "menu")) {
383 menu_end_menu(); 352 menu_end_menu();
384 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno()); 353 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
385 } 354 }
386}; 355};
387 356
388menu_stmt: menu_entry menu_block menu_end 357menu_stmt: menu_entry stmt_list menu_end
389; 358;
390 359
391menu_block: 360menu_option_list:
392 /* empty */ 361 /* empty */
393 | menu_block common_stmt 362 | menu_option_list visible
394 | menu_block menu_stmt 363 | menu_option_list depends
395 | menu_block choice_stmt
396; 364;
397 365
398source_stmt: T_SOURCE prompt T_EOL 366source_stmt: T_SOURCE prompt T_EOL
@@ -411,7 +379,12 @@ comment: T_COMMENT prompt T_EOL
411 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno()); 379 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
412}; 380};
413 381
414comment_stmt: comment depends_list 382comment_stmt: comment comment_option_list
383;
384
385comment_option_list:
386 /* empty */
387 | comment_option_list depends
415; 388;
416 389
417/* help option */ 390/* help option */
@@ -440,13 +413,6 @@ help: help_start T_HELPTEXT
440 413
441/* depends option */ 414/* depends option */
442 415
443depends_list:
444 /* empty */
445 | depends_list depends
446 | depends_list T_EOL
447 | depends_list option_error
448;
449
450depends: T_DEPENDS T_ON expr T_EOL 416depends: T_DEPENDS T_ON expr T_EOL
451{ 417{
452 menu_add_dep($3); 418 menu_add_dep($3);
@@ -454,14 +420,7 @@ depends: T_DEPENDS T_ON expr T_EOL
454}; 420};
455 421
456/* visibility option */ 422/* visibility option */
457 423visible: T_VISIBLE if_expr T_EOL
458visibility_list:
459 /* empty */
460 | visibility_list visible
461 | visibility_list T_EOL
462;
463
464visible: T_VISIBLE if_expr
465{ 424{
466 menu_add_visibility($2); 425 menu_add_visibility($2);
467}; 426};
@@ -479,14 +438,9 @@ prompt: T_WORD
479 | T_WORD_QUOTE 438 | T_WORD_QUOTE
480; 439;
481 440
482end: T_ENDMENU T_EOL { $$ = $1; } 441end: T_ENDMENU T_EOL { $$ = "menu"; }
483 | T_ENDCHOICE T_EOL { $$ = $1; } 442 | T_ENDCHOICE T_EOL { $$ = "choice"; }
484 | T_ENDIF T_EOL { $$ = $1; } 443 | T_ENDIF T_EOL { $$ = "if"; }
485;
486
487nl:
488 T_EOL
489 | nl T_EOL
490; 444;
491 445
492if_expr: /* empty */ { $$ = NULL; } 446if_expr: /* empty */ { $$ = NULL; }
@@ -518,7 +472,13 @@ word_opt: /* empty */ { $$ = NULL; }
518 472
519/* assignment statement */ 473/* assignment statement */
520 474
521assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); } 475assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
476
477assign_op:
478 T_EQUAL { $$ = VAR_RECURSIVE; }
479 | T_COLON_EQUAL { $$ = VAR_SIMPLE; }
480 | T_PLUS_EQUAL { $$ = VAR_APPEND; }
481;
522 482
523assign_val: 483assign_val:
524 /* empty */ { $$ = xstrdup(""); }; 484 /* empty */ { $$ = xstrdup(""); };
@@ -563,35 +523,21 @@ void conf_parse(const char *name)
563 sym_set_change_count(1); 523 sym_set_change_count(1);
564} 524}
565 525
566static const char *zconf_tokenname(int token) 526static bool zconf_endtoken(const char *tokenname,
567{ 527 const char *expected_tokenname)
568 switch (token) {
569 case T_MENU: return "menu";
570 case T_ENDMENU: return "endmenu";
571 case T_CHOICE: return "choice";
572 case T_ENDCHOICE: return "endchoice";
573 case T_IF: return "if";
574 case T_ENDIF: return "endif";
575 case T_DEPENDS: return "depends";
576 case T_VISIBLE: return "visible";
577 }
578 return "<token>";
579}
580
581static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
582{ 528{
583 if (id->token != endtoken) { 529 if (strcmp(tokenname, expected_tokenname)) {
584 zconf_error("unexpected '%s' within %s block", 530 zconf_error("unexpected '%s' within %s block",
585 id->name, zconf_tokenname(starttoken)); 531 tokenname, expected_tokenname);
586 yynerrs++; 532 yynerrs++;
587 return false; 533 return false;
588 } 534 }
589 if (current_menu->file != current_file) { 535 if (current_menu->file != current_file) {
590 zconf_error("'%s' in different file than '%s'", 536 zconf_error("'%s' in different file than '%s'",
591 id->name, zconf_tokenname(starttoken)); 537 tokenname, expected_tokenname);
592 fprintf(stderr, "%s:%d: location of the '%s'\n", 538 fprintf(stderr, "%s:%d: location of the '%s'\n",
593 current_menu->file->name, current_menu->lineno, 539 current_menu->file->name, current_menu->lineno,
594 zconf_tokenname(starttoken)); 540 expected_tokenname);
595 yynerrs++; 541 yynerrs++;
596 return false; 542 return false;
597 } 543 }
@@ -781,10 +727,5 @@ void zconfdump(FILE *out)
781 } 727 }
782} 728}
783 729
784#include "zconf.lex.c"
785#include "util.c" 730#include "util.c"
786#include "confdata.c"
787#include "expr.c"
788#include "symbol.c"
789#include "menu.c" 731#include "menu.c"
790#include "preprocess.c"
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index ffbe901a37b5..c5333d251985 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -212,7 +212,7 @@ my $anon_struct_union = 0;
212my $type_constant = '\b``([^\`]+)``\b'; 212my $type_constant = '\b``([^\`]+)``\b';
213my $type_constant2 = '\%([-_\w]+)'; 213my $type_constant2 = '\%([-_\w]+)';
214my $type_func = '(\w+)\(\)'; 214my $type_func = '(\w+)\(\)';
215my $type_param = '\@(\w*(\.\w+)*(\.\.\.)?)'; 215my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
216my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 216my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
217my $type_env = '(\$\w+)'; 217my $type_env = '(\$\w+)';
218my $type_enum = '\&(enum\s*([_\w]+))'; 218my $type_enum = '\&(enum\s*([_\w]+))';
@@ -361,7 +361,7 @@ my $doc_com = '\s*\*\s*';
361my $doc_com_body = '\s*\* ?'; 361my $doc_com_body = '\s*\* ?';
362my $doc_decl = $doc_com . '(\w+)'; 362my $doc_decl = $doc_com . '(\w+)';
363# @params and a strictly limited set of supported section names 363# @params and a strictly limited set of supported section names
364my $doc_sect = $doc_com . 364my $doc_sect = $doc_com .
365 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 365 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
366my $doc_content = $doc_com_body . '(.*)'; 366my $doc_content = $doc_com_body . '(.*)';
367my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 367my $doc_block = $doc_com . 'DOC:\s*(.*)?';
@@ -751,7 +751,7 @@ sub output_blockhead_rst(%) {
751 751
752# 752#
753# Apply the RST highlights to a sub-block of text. 753# Apply the RST highlights to a sub-block of text.
754# 754#
755sub highlight_block($) { 755sub highlight_block($) {
756 # The dohighlight kludge requires the text be called $contents 756 # The dohighlight kludge requires the text be called $contents
757 my $contents = shift; 757 my $contents = shift;
@@ -1062,7 +1062,7 @@ sub dump_struct($$) {
1062 my $x = shift; 1062 my $x = shift;
1063 my $file = shift; 1063 my $file = shift;
1064 1064
1065 if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}/) { 1065 if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
1066 my $decl_type = $1; 1066 my $decl_type = $1;
1067 $declaration_name = $2; 1067 $declaration_name = $2;
1068 my $members = $3; 1068 my $members = $3;
@@ -1073,8 +1073,9 @@ sub dump_struct($$) {
1073 # strip comments: 1073 # strip comments:
1074 $members =~ s/\/\*.*?\*\///gos; 1074 $members =~ s/\/\*.*?\*\///gos;
1075 # strip attributes 1075 # strip attributes
1076 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1076 $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)//gi;
1077 $members =~ s/__aligned\s*\([^;]*\)//gos; 1077 $members =~ s/\s*__aligned\s*\([^;]*\)//gos;
1078 $members =~ s/\s*__packed\s*//gos;
1078 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1079 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
1079 # replace DECLARE_BITMAP 1080 # replace DECLARE_BITMAP
1080 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 1081 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index a5b4af47987a..42c5d50f2bcc 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -4,8 +4,6 @@ OBJECT_FILES_NON_STANDARD := y
4hostprogs-y := modpost mk_elfconfig 4hostprogs-y := modpost mk_elfconfig
5always := $(hostprogs-y) empty.o 5always := $(hostprogs-y) empty.o
6 6
7CFLAGS_REMOVE_empty.o := $(ASM_MACRO_FLAGS)
8
9modpost-objs := modpost.o file2alias.o sumversion.o 7modpost-objs := modpost.o file2alias.o sumversion.o
10 8
11devicetable-offsets-file := devicetable-offsets.h 9devicetable-offsets-file := devicetable-offsets.h
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 28a61665bb9c..a37af7d71973 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -47,49 +47,9 @@ typedef struct {
47struct devtable { 47struct devtable {
48 const char *device_id; /* name of table, __mod_<name>__*_device_table. */ 48 const char *device_id; /* name of table, __mod_<name>__*_device_table. */
49 unsigned long id_size; 49 unsigned long id_size;
50 void *function; 50 int (*do_entry)(const char *filename, void *symval, char *alias);
51}; 51};
52 52
53#define ___cat(a,b) a ## b
54#define __cat(a,b) ___cat(a,b)
55
56/* we need some special handling for this host tool running eventually on
57 * Darwin. The Mach-O section handling is a bit different than ELF section
58 * handling. The differnces in detail are:
59 * a) we have segments which have sections
60 * b) we need a API call to get the respective section symbols */
61#if defined(__MACH__)
62#include <mach-o/getsect.h>
63
64#define INIT_SECTION(name) do { \
65 unsigned long name ## _len; \
66 char *__cat(pstart_,name) = getsectdata("__TEXT", \
67 #name, &__cat(name,_len)); \
68 char *__cat(pstop_,name) = __cat(pstart_,name) + \
69 __cat(name, _len); \
70 __cat(__start_,name) = (void *)__cat(pstart_,name); \
71 __cat(__stop_,name) = (void *)__cat(pstop_,name); \
72 } while (0)
73#define SECTION(name) __attribute__((section("__TEXT, " #name)))
74
75struct devtable **__start___devtable, **__stop___devtable;
76#else
77#define INIT_SECTION(name) /* no-op for ELF */
78#define SECTION(name) __attribute__((section(#name)))
79
80/* We construct a table of pointers in an ELF section (pointers generally
81 * go unpadded by gcc). ld creates boundary syms for us. */
82extern struct devtable *__start___devtable[], *__stop___devtable[];
83#endif /* __MACH__ */
84
85#if !defined(__used)
86# if __GNUC__ == 3 && __GNUC_MINOR__ < 3
87# define __used __attribute__((__unused__))
88# else
89# define __used __attribute__((__used__))
90# endif
91#endif
92
93/* Define a variable f that holds the value of field f of struct devid 53/* Define a variable f that holds the value of field f of struct devid
94 * based at address m. 54 * based at address m.
95 */ 55 */
@@ -110,16 +70,6 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
110#define DEF_FIELD_ADDR(m, devid, f) \ 70#define DEF_FIELD_ADDR(m, devid, f) \
111 DEF_FIELD_ADDR_VAR(m, devid, f, f) 71 DEF_FIELD_ADDR_VAR(m, devid, f, f)
112 72
113/* Add a table entry. We test function type matches while we're here. */
114#define ADD_TO_DEVTABLE(device_id, type, function) \
115 static struct devtable __cat(devtable,__LINE__) = { \
116 device_id + 0*sizeof((function)((const char *)NULL, \
117 (void *)NULL, \
118 (char *)NULL)), \
119 SIZE_##type, (function) }; \
120 static struct devtable *SECTION(__devtable) __used \
121 __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
122
123#define ADD(str, sep, cond, field) \ 73#define ADD(str, sep, cond, field) \
124do { \ 74do { \
125 strcat(str, sep); \ 75 strcat(str, sep); \
@@ -439,7 +389,6 @@ static int do_hid_entry(const char *filename,
439 389
440 return 1; 390 return 1;
441} 391}
442ADD_TO_DEVTABLE("hid", hid_device_id, do_hid_entry);
443 392
444/* Looks like: ieee1394:venNmoNspNverN */ 393/* Looks like: ieee1394:venNmoNspNverN */
445static int do_ieee1394_entry(const char *filename, 394static int do_ieee1394_entry(const char *filename,
@@ -464,7 +413,6 @@ static int do_ieee1394_entry(const char *filename,
464 add_wildcard(alias); 413 add_wildcard(alias);
465 return 1; 414 return 1;
466} 415}
467ADD_TO_DEVTABLE("ieee1394", ieee1394_device_id, do_ieee1394_entry);
468 416
469/* Looks like: pci:vNdNsvNsdNbcNscNiN. */ 417/* Looks like: pci:vNdNsvNsdNbcNscNiN. */
470static int do_pci_entry(const char *filename, 418static int do_pci_entry(const char *filename,
@@ -508,7 +456,6 @@ static int do_pci_entry(const char *filename,
508 add_wildcard(alias); 456 add_wildcard(alias);
509 return 1; 457 return 1;
510} 458}
511ADD_TO_DEVTABLE("pci", pci_device_id, do_pci_entry);
512 459
513/* looks like: "ccw:tNmNdtNdmN" */ 460/* looks like: "ccw:tNmNdtNdmN" */
514static int do_ccw_entry(const char *filename, 461static int do_ccw_entry(const char *filename,
@@ -532,7 +479,6 @@ static int do_ccw_entry(const char *filename,
532 add_wildcard(alias); 479 add_wildcard(alias);
533 return 1; 480 return 1;
534} 481}
535ADD_TO_DEVTABLE("ccw", ccw_device_id, do_ccw_entry);
536 482
537/* looks like: "ap:tN" */ 483/* looks like: "ap:tN" */
538static int do_ap_entry(const char *filename, 484static int do_ap_entry(const char *filename,
@@ -543,7 +489,6 @@ static int do_ap_entry(const char *filename,
543 sprintf(alias, "ap:t%02X*", dev_type); 489 sprintf(alias, "ap:t%02X*", dev_type);
544 return 1; 490 return 1;
545} 491}
546ADD_TO_DEVTABLE("ap", ap_device_id, do_ap_entry);
547 492
548/* looks like: "css:tN" */ 493/* looks like: "css:tN" */
549static int do_css_entry(const char *filename, 494static int do_css_entry(const char *filename,
@@ -554,7 +499,6 @@ static int do_css_entry(const char *filename,
554 sprintf(alias, "css:t%01X", type); 499 sprintf(alias, "css:t%01X", type);
555 return 1; 500 return 1;
556} 501}
557ADD_TO_DEVTABLE("css", css_device_id, do_css_entry);
558 502
559/* Looks like: "serio:tyNprNidNexN" */ 503/* Looks like: "serio:tyNprNidNexN" */
560static int do_serio_entry(const char *filename, 504static int do_serio_entry(const char *filename,
@@ -574,7 +518,6 @@ static int do_serio_entry(const char *filename,
574 add_wildcard(alias); 518 add_wildcard(alias);
575 return 1; 519 return 1;
576} 520}
577ADD_TO_DEVTABLE("serio", serio_device_id, do_serio_entry);
578 521
579/* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or 522/* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
580 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if) 523 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
@@ -612,7 +555,6 @@ static int do_acpi_entry(const char *filename,
612 } 555 }
613 return 1; 556 return 1;
614} 557}
615ADD_TO_DEVTABLE("acpi", acpi_device_id, do_acpi_entry);
616 558
617/* looks like: "pnp:dD" */ 559/* looks like: "pnp:dD" */
618static void do_pnp_device_entry(void *symval, unsigned long size, 560static void do_pnp_device_entry(void *symval, unsigned long size,
@@ -736,7 +678,6 @@ static int do_pcmcia_entry(const char *filename,
736 add_wildcard(alias); 678 add_wildcard(alias);
737 return 1; 679 return 1;
738} 680}
739ADD_TO_DEVTABLE("pcmcia", pcmcia_device_id, do_pcmcia_entry);
740 681
741static int do_vio_entry(const char *filename, void *symval, 682static int do_vio_entry(const char *filename, void *symval,
742 char *alias) 683 char *alias)
@@ -756,7 +697,6 @@ static int do_vio_entry(const char *filename, void *symval,
756 add_wildcard(alias); 697 add_wildcard(alias);
757 return 1; 698 return 1;
758} 699}
759ADD_TO_DEVTABLE("vio", vio_device_id, do_vio_entry);
760 700
761#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 701#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
762 702
@@ -829,7 +769,6 @@ static int do_input_entry(const char *filename, void *symval,
829 do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX); 769 do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX);
830 return 1; 770 return 1;
831} 771}
832ADD_TO_DEVTABLE("input", input_device_id, do_input_entry);
833 772
834static int do_eisa_entry(const char *filename, void *symval, 773static int do_eisa_entry(const char *filename, void *symval,
835 char *alias) 774 char *alias)
@@ -841,7 +780,6 @@ static int do_eisa_entry(const char *filename, void *symval,
841 strcat(alias, "*"); 780 strcat(alias, "*");
842 return 1; 781 return 1;
843} 782}
844ADD_TO_DEVTABLE("eisa", eisa_device_id, do_eisa_entry);
845 783
846/* Looks like: parisc:tNhvNrevNsvN */ 784/* Looks like: parisc:tNhvNrevNsvN */
847static int do_parisc_entry(const char *filename, void *symval, 785static int do_parisc_entry(const char *filename, void *symval,
@@ -861,7 +799,6 @@ static int do_parisc_entry(const char *filename, void *symval,
861 add_wildcard(alias); 799 add_wildcard(alias);
862 return 1; 800 return 1;
863} 801}
864ADD_TO_DEVTABLE("parisc", parisc_device_id, do_parisc_entry);
865 802
866/* Looks like: sdio:cNvNdN. */ 803/* Looks like: sdio:cNvNdN. */
867static int do_sdio_entry(const char *filename, 804static int do_sdio_entry(const char *filename,
@@ -878,7 +815,6 @@ static int do_sdio_entry(const char *filename,
878 add_wildcard(alias); 815 add_wildcard(alias);
879 return 1; 816 return 1;
880} 817}
881ADD_TO_DEVTABLE("sdio", sdio_device_id, do_sdio_entry);
882 818
883/* Looks like: ssb:vNidNrevN. */ 819/* Looks like: ssb:vNidNrevN. */
884static int do_ssb_entry(const char *filename, 820static int do_ssb_entry(const char *filename,
@@ -895,7 +831,6 @@ static int do_ssb_entry(const char *filename,
895 add_wildcard(alias); 831 add_wildcard(alias);
896 return 1; 832 return 1;
897} 833}
898ADD_TO_DEVTABLE("ssb", ssb_device_id, do_ssb_entry);
899 834
900/* Looks like: bcma:mNidNrevNclN. */ 835/* Looks like: bcma:mNidNrevNclN. */
901static int do_bcma_entry(const char *filename, 836static int do_bcma_entry(const char *filename,
@@ -914,7 +849,6 @@ static int do_bcma_entry(const char *filename,
914 add_wildcard(alias); 849 add_wildcard(alias);
915 return 1; 850 return 1;
916} 851}
917ADD_TO_DEVTABLE("bcma", bcma_device_id, do_bcma_entry);
918 852
919/* Looks like: virtio:dNvN */ 853/* Looks like: virtio:dNvN */
920static int do_virtio_entry(const char *filename, void *symval, 854static int do_virtio_entry(const char *filename, void *symval,
@@ -930,7 +864,6 @@ static int do_virtio_entry(const char *filename, void *symval,
930 add_wildcard(alias); 864 add_wildcard(alias);
931 return 1; 865 return 1;
932} 866}
933ADD_TO_DEVTABLE("virtio", virtio_device_id, do_virtio_entry);
934 867
935/* 868/*
936 * Looks like: vmbus:guid 869 * Looks like: vmbus:guid
@@ -953,7 +886,6 @@ static int do_vmbus_entry(const char *filename, void *symval,
953 886
954 return 1; 887 return 1;
955} 888}
956ADD_TO_DEVTABLE("vmbus", hv_vmbus_device_id, do_vmbus_entry);
957 889
958/* Looks like: rpmsg:S */ 890/* Looks like: rpmsg:S */
959static int do_rpmsg_entry(const char *filename, void *symval, 891static int do_rpmsg_entry(const char *filename, void *symval,
@@ -964,7 +896,6 @@ static int do_rpmsg_entry(const char *filename, void *symval,
964 896
965 return 1; 897 return 1;
966} 898}
967ADD_TO_DEVTABLE("rpmsg", rpmsg_device_id, do_rpmsg_entry);
968 899
969/* Looks like: i2c:S */ 900/* Looks like: i2c:S */
970static int do_i2c_entry(const char *filename, void *symval, 901static int do_i2c_entry(const char *filename, void *symval,
@@ -975,7 +906,6 @@ static int do_i2c_entry(const char *filename, void *symval,
975 906
976 return 1; 907 return 1;
977} 908}
978ADD_TO_DEVTABLE("i2c", i2c_device_id, do_i2c_entry);
979 909
980/* Looks like: spi:S */ 910/* Looks like: spi:S */
981static int do_spi_entry(const char *filename, void *symval, 911static int do_spi_entry(const char *filename, void *symval,
@@ -986,7 +916,6 @@ static int do_spi_entry(const char *filename, void *symval,
986 916
987 return 1; 917 return 1;
988} 918}
989ADD_TO_DEVTABLE("spi", spi_device_id, do_spi_entry);
990 919
991static const struct dmifield { 920static const struct dmifield {
992 const char *prefix; 921 const char *prefix;
@@ -1041,7 +970,6 @@ static int do_dmi_entry(const char *filename, void *symval,
1041 strcat(alias, ":"); 970 strcat(alias, ":");
1042 return 1; 971 return 1;
1043} 972}
1044ADD_TO_DEVTABLE("dmi", dmi_system_id, do_dmi_entry);
1045 973
1046static int do_platform_entry(const char *filename, 974static int do_platform_entry(const char *filename,
1047 void *symval, char *alias) 975 void *symval, char *alias)
@@ -1050,7 +978,6 @@ static int do_platform_entry(const char *filename,
1050 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name); 978 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name);
1051 return 1; 979 return 1;
1052} 980}
1053ADD_TO_DEVTABLE("platform", platform_device_id, do_platform_entry);
1054 981
1055static int do_mdio_entry(const char *filename, 982static int do_mdio_entry(const char *filename,
1056 void *symval, char *alias) 983 void *symval, char *alias)
@@ -1075,7 +1002,6 @@ static int do_mdio_entry(const char *filename,
1075 1002
1076 return 1; 1003 return 1;
1077} 1004}
1078ADD_TO_DEVTABLE("mdio", mdio_device_id, do_mdio_entry);
1079 1005
1080/* Looks like: zorro:iN. */ 1006/* Looks like: zorro:iN. */
1081static int do_zorro_entry(const char *filename, void *symval, 1007static int do_zorro_entry(const char *filename, void *symval,
@@ -1086,7 +1012,6 @@ static int do_zorro_entry(const char *filename, void *symval,
1086 ADD(alias, "i", id != ZORRO_WILDCARD, id); 1012 ADD(alias, "i", id != ZORRO_WILDCARD, id);
1087 return 1; 1013 return 1;
1088} 1014}
1089ADD_TO_DEVTABLE("zorro", zorro_device_id, do_zorro_entry);
1090 1015
1091/* looks like: "pnp:dD" */ 1016/* looks like: "pnp:dD" */
1092static int do_isapnp_entry(const char *filename, 1017static int do_isapnp_entry(const char *filename,
@@ -1102,7 +1027,6 @@ static int do_isapnp_entry(const char *filename,
1102 (function >> 12) & 0x0f, (function >> 8) & 0x0f); 1027 (function >> 12) & 0x0f, (function >> 8) & 0x0f);
1103 return 1; 1028 return 1;
1104} 1029}
1105ADD_TO_DEVTABLE("isapnp", isapnp_device_id, do_isapnp_entry);
1106 1030
1107/* Looks like: "ipack:fNvNdN". */ 1031/* Looks like: "ipack:fNvNdN". */
1108static int do_ipack_entry(const char *filename, 1032static int do_ipack_entry(const char *filename,
@@ -1118,7 +1042,6 @@ static int do_ipack_entry(const char *filename,
1118 add_wildcard(alias); 1042 add_wildcard(alias);
1119 return 1; 1043 return 1;
1120} 1044}
1121ADD_TO_DEVTABLE("ipack", ipack_device_id, do_ipack_entry);
1122 1045
1123/* 1046/*
1124 * Append a match expression for a single masked hex digit. 1047 * Append a match expression for a single masked hex digit.
@@ -1189,7 +1112,6 @@ static int do_amba_entry(const char *filename,
1189 1112
1190 return 1; 1113 return 1;
1191} 1114}
1192ADD_TO_DEVTABLE("amba", amba_id, do_amba_entry);
1193 1115
1194/* 1116/*
1195 * looks like: "mipscdmm:tN" 1117 * looks like: "mipscdmm:tN"
@@ -1205,7 +1127,6 @@ static int do_mips_cdmm_entry(const char *filename,
1205 sprintf(alias, "mipscdmm:t%02X*", type); 1127 sprintf(alias, "mipscdmm:t%02X*", type);
1206 return 1; 1128 return 1;
1207} 1129}
1208ADD_TO_DEVTABLE("mipscdmm", mips_cdmm_device_id, do_mips_cdmm_entry);
1209 1130
1210/* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,* 1131/* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
1211 * All fields are numbers. It would be nicer to use strings for vendor 1132 * All fields are numbers. It would be nicer to use strings for vendor
@@ -1230,7 +1151,6 @@ static int do_x86cpu_entry(const char *filename, void *symval,
1230 sprintf(alias + strlen(alias), "%04X*", feature); 1151 sprintf(alias + strlen(alias), "%04X*", feature);
1231 return 1; 1152 return 1;
1232} 1153}
1233ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry);
1234 1154
1235/* LOOKS like cpu:type:*:feature:*FEAT* */ 1155/* LOOKS like cpu:type:*:feature:*FEAT* */
1236static int do_cpu_entry(const char *filename, void *symval, char *alias) 1156static int do_cpu_entry(const char *filename, void *symval, char *alias)
@@ -1240,7 +1160,6 @@ static int do_cpu_entry(const char *filename, void *symval, char *alias)
1240 sprintf(alias, "cpu:type:*:feature:*%04X*", feature); 1160 sprintf(alias, "cpu:type:*:feature:*%04X*", feature);
1241 return 1; 1161 return 1;
1242} 1162}
1243ADD_TO_DEVTABLE("cpu", cpu_feature, do_cpu_entry);
1244 1163
1245/* Looks like: mei:S:uuid:N:* */ 1164/* Looks like: mei:S:uuid:N:* */
1246static int do_mei_entry(const char *filename, void *symval, 1165static int do_mei_entry(const char *filename, void *symval,
@@ -1259,7 +1178,6 @@ static int do_mei_entry(const char *filename, void *symval,
1259 1178
1260 return 1; 1179 return 1;
1261} 1180}
1262ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
1263 1181
1264/* Looks like: rapidio:vNdNavNadN */ 1182/* Looks like: rapidio:vNdNavNadN */
1265static int do_rio_entry(const char *filename, 1183static int do_rio_entry(const char *filename,
@@ -1279,7 +1197,6 @@ static int do_rio_entry(const char *filename,
1279 add_wildcard(alias); 1197 add_wildcard(alias);
1280 return 1; 1198 return 1;
1281} 1199}
1282ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
1283 1200
1284/* Looks like: ulpi:vNpN */ 1201/* Looks like: ulpi:vNpN */
1285static int do_ulpi_entry(const char *filename, void *symval, 1202static int do_ulpi_entry(const char *filename, void *symval,
@@ -1292,7 +1209,6 @@ static int do_ulpi_entry(const char *filename, void *symval,
1292 1209
1293 return 1; 1210 return 1;
1294} 1211}
1295ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry);
1296 1212
1297/* Looks like: hdaudio:vNrNaN */ 1213/* Looks like: hdaudio:vNrNaN */
1298static int do_hda_entry(const char *filename, void *symval, char *alias) 1214static int do_hda_entry(const char *filename, void *symval, char *alias)
@@ -1309,7 +1225,6 @@ static int do_hda_entry(const char *filename, void *symval, char *alias)
1309 add_wildcard(alias); 1225 add_wildcard(alias);
1310 return 1; 1226 return 1;
1311} 1227}
1312ADD_TO_DEVTABLE("hdaudio", hda_device_id, do_hda_entry);
1313 1228
1314/* Looks like: sdw:mNpN */ 1229/* Looks like: sdw:mNpN */
1315static int do_sdw_entry(const char *filename, void *symval, char *alias) 1230static int do_sdw_entry(const char *filename, void *symval, char *alias)
@@ -1324,7 +1239,6 @@ static int do_sdw_entry(const char *filename, void *symval, char *alias)
1324 add_wildcard(alias); 1239 add_wildcard(alias);
1325 return 1; 1240 return 1;
1326} 1241}
1327ADD_TO_DEVTABLE("sdw", sdw_device_id, do_sdw_entry);
1328 1242
1329/* Looks like: fsl-mc:vNdN */ 1243/* Looks like: fsl-mc:vNdN */
1330static int do_fsl_mc_entry(const char *filename, void *symval, 1244static int do_fsl_mc_entry(const char *filename, void *symval,
@@ -1336,7 +1250,6 @@ static int do_fsl_mc_entry(const char *filename, void *symval,
1336 sprintf(alias, "fsl-mc:v%08Xd%s", vendor, *obj_type); 1250 sprintf(alias, "fsl-mc:v%08Xd%s", vendor, *obj_type);
1337 return 1; 1251 return 1;
1338} 1252}
1339ADD_TO_DEVTABLE("fslmc", fsl_mc_device_id, do_fsl_mc_entry);
1340 1253
1341/* Looks like: tbsvc:kSpNvNrN */ 1254/* Looks like: tbsvc:kSpNvNrN */
1342static int do_tbsvc_entry(const char *filename, void *symval, char *alias) 1255static int do_tbsvc_entry(const char *filename, void *symval, char *alias)
@@ -1361,7 +1274,6 @@ static int do_tbsvc_entry(const char *filename, void *symval, char *alias)
1361 add_wildcard(alias); 1274 add_wildcard(alias);
1362 return 1; 1275 return 1;
1363} 1276}
1364ADD_TO_DEVTABLE("tbsvc", tb_service_id, do_tbsvc_entry);
1365 1277
1366/* Looks like: typec:idNmN */ 1278/* Looks like: typec:idNmN */
1367static int do_typec_entry(const char *filename, void *symval, char *alias) 1279static int do_typec_entry(const char *filename, void *symval, char *alias)
@@ -1374,7 +1286,6 @@ static int do_typec_entry(const char *filename, void *symval, char *alias)
1374 1286
1375 return 1; 1287 return 1;
1376} 1288}
1377ADD_TO_DEVTABLE("typec", typec_device_id, do_typec_entry);
1378 1289
1379/* Does namelen bytes of name exactly match the symbol? */ 1290/* Does namelen bytes of name exactly match the symbol? */
1380static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1291static bool sym_is(const char *name, unsigned namelen, const char *symbol)
@@ -1388,12 +1299,11 @@ static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1388static void do_table(void *symval, unsigned long size, 1299static void do_table(void *symval, unsigned long size,
1389 unsigned long id_size, 1300 unsigned long id_size,
1390 const char *device_id, 1301 const char *device_id,
1391 void *function, 1302 int (*do_entry)(const char *filename, void *symval, char *alias),
1392 struct module *mod) 1303 struct module *mod)
1393{ 1304{
1394 unsigned int i; 1305 unsigned int i;
1395 char alias[500]; 1306 char alias[500];
1396 int (*do_entry)(const char *, void *entry, char *alias) = function;
1397 1307
1398 device_id_check(mod->name, device_id, size, id_size, symval); 1308 device_id_check(mod->name, device_id, size, id_size, symval);
1399 /* Leave last one: it's the terminator. */ 1309 /* Leave last one: it's the terminator. */
@@ -1407,6 +1317,48 @@ static void do_table(void *symval, unsigned long size,
1407 } 1317 }
1408} 1318}
1409 1319
1320static const struct devtable devtable[] = {
1321 {"hid", SIZE_hid_device_id, do_hid_entry},
1322 {"ieee1394", SIZE_ieee1394_device_id, do_ieee1394_entry},
1323 {"pci", SIZE_pci_device_id, do_pci_entry},
1324 {"ccw", SIZE_ccw_device_id, do_ccw_entry},
1325 {"ap", SIZE_ap_device_id, do_ap_entry},
1326 {"css", SIZE_css_device_id, do_css_entry},
1327 {"serio", SIZE_serio_device_id, do_serio_entry},
1328 {"acpi", SIZE_acpi_device_id, do_acpi_entry},
1329 {"pcmcia", SIZE_pcmcia_device_id, do_pcmcia_entry},
1330 {"vio", SIZE_vio_device_id, do_vio_entry},
1331 {"input", SIZE_input_device_id, do_input_entry},
1332 {"eisa", SIZE_eisa_device_id, do_eisa_entry},
1333 {"parisc", SIZE_parisc_device_id, do_parisc_entry},
1334 {"sdio", SIZE_sdio_device_id, do_sdio_entry},
1335 {"ssb", SIZE_ssb_device_id, do_ssb_entry},
1336 {"bcma", SIZE_bcma_device_id, do_bcma_entry},
1337 {"virtio", SIZE_virtio_device_id, do_virtio_entry},
1338 {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
1339 {"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry},
1340 {"i2c", SIZE_i2c_device_id, do_i2c_entry},
1341 {"spi", SIZE_spi_device_id, do_spi_entry},
1342 {"dmi", SIZE_dmi_system_id, do_dmi_entry},
1343 {"platform", SIZE_platform_device_id, do_platform_entry},
1344 {"mdio", SIZE_mdio_device_id, do_mdio_entry},
1345 {"zorro", SIZE_zorro_device_id, do_zorro_entry},
1346 {"isapnp", SIZE_isapnp_device_id, do_isapnp_entry},
1347 {"ipack", SIZE_ipack_device_id, do_ipack_entry},
1348 {"amba", SIZE_amba_id, do_amba_entry},
1349 {"mipscdmm", SIZE_mips_cdmm_device_id, do_mips_cdmm_entry},
1350 {"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry},
1351 {"cpu", SIZE_cpu_feature, do_cpu_entry},
1352 {"mei", SIZE_mei_cl_device_id, do_mei_entry},
1353 {"rapidio", SIZE_rio_device_id, do_rio_entry},
1354 {"ulpi", SIZE_ulpi_device_id, do_ulpi_entry},
1355 {"hdaudio", SIZE_hda_device_id, do_hda_entry},
1356 {"sdw", SIZE_sdw_device_id, do_sdw_entry},
1357 {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry},
1358 {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry},
1359 {"typec", SIZE_typec_device_id, do_typec_entry},
1360};
1361
1410/* Create MODULE_ALIAS() statements. 1362/* Create MODULE_ALIAS() statements.
1411 * At this time, we cannot write the actual output C source yet, 1363 * At this time, we cannot write the actual output C source yet,
1412 * so we write into the mod->dev_table_buf buffer. */ 1364 * so we write into the mod->dev_table_buf buffer. */
@@ -1460,13 +1412,14 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
1460 else if (sym_is(name, namelen, "pnp_card")) 1412 else if (sym_is(name, namelen, "pnp_card"))
1461 do_pnp_card_entries(symval, sym->st_size, mod); 1413 do_pnp_card_entries(symval, sym->st_size, mod);
1462 else { 1414 else {
1463 struct devtable **p; 1415 int i;
1464 INIT_SECTION(__devtable); 1416
1417 for (i = 0; i < ARRAY_SIZE(devtable); i++) {
1418 const struct devtable *p = &devtable[i];
1465 1419
1466 for (p = __start___devtable; p < __stop___devtable; p++) { 1420 if (sym_is(name, namelen, p->device_id)) {
1467 if (sym_is(name, namelen, (*p)->device_id)) { 1421 do_table(symval, sym->st_size, p->id_size,
1468 do_table(symval, sym->st_size, (*p)->id_size, 1422 p->device_id, p->do_entry, mod);
1469 (*p)->device_id, (*p)->function, mod);
1470 break; 1423 break;
1471 } 1424 }
1472 } 1425 }
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 0d998c54564d..26bf886bd168 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1163,6 +1163,14 @@ static const struct sectioncheck *section_mismatch(
1163 * fromsec = text section 1163 * fromsec = text section
1164 * refsymname = *.constprop.* 1164 * refsymname = *.constprop.*
1165 * 1165 *
1166 * Pattern 6:
1167 * Hide section mismatch warnings for ELF local symbols. The goal
1168 * is to eliminate false positive modpost warnings caused by
1169 * compiler-generated ELF local symbol names such as ".LANCHOR1".
1170 * Autogenerated symbol names bypass modpost's "Pattern 2"
1171 * whitelisting, which relies on pattern-matching against symbol
1172 * names to work. (One situation where gcc can autogenerate ELF
1173 * local symbols is when "-fsection-anchors" is used.)
1166 **/ 1174 **/
1167static int secref_whitelist(const struct sectioncheck *mismatch, 1175static int secref_whitelist(const struct sectioncheck *mismatch,
1168 const char *fromsec, const char *fromsym, 1176 const char *fromsec, const char *fromsym,
@@ -1201,9 +1209,37 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
1201 match(fromsym, optim_symbols)) 1209 match(fromsym, optim_symbols))
1202 return 0; 1210 return 0;
1203 1211
1212 /* Check for pattern 6 */
1213 if (strstarts(fromsym, ".L"))
1214 return 0;
1215
1204 return 1; 1216 return 1;
1205} 1217}
1206 1218
1219static inline int is_arm_mapping_symbol(const char *str)
1220{
1221 return str[0] == '$' && strchr("axtd", str[1])
1222 && (str[2] == '\0' || str[2] == '.');
1223}
1224
1225/*
1226 * If there's no name there, ignore it; likewise, ignore it if it's
1227 * one of the magic symbols emitted used by current ARM tools.
1228 *
1229 * Otherwise if find_symbols_between() returns those symbols, they'll
1230 * fail the whitelist tests and cause lots of false alarms ... fixable
1231 * only by merging __exit and __init sections into __text, bloating
1232 * the kernel (which is especially evil on embedded platforms).
1233 */
1234static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1235{
1236 const char *name = elf->strtab + sym->st_name;
1237
1238 if (!name || !strlen(name))
1239 return 0;
1240 return !is_arm_mapping_symbol(name);
1241}
1242
1207/** 1243/**
1208 * Find symbol based on relocation record info. 1244 * Find symbol based on relocation record info.
1209 * In some cases the symbol supplied is a valid symbol so 1245 * In some cases the symbol supplied is a valid symbol so
@@ -1229,6 +1265,8 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1229 continue; 1265 continue;
1230 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) 1266 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1231 continue; 1267 continue;
1268 if (!is_valid_name(elf, sym))
1269 continue;
1232 if (sym->st_value == addr) 1270 if (sym->st_value == addr)
1233 return sym; 1271 return sym;
1234 /* Find a symbol nearby - addr are maybe negative */ 1272 /* Find a symbol nearby - addr are maybe negative */
@@ -1247,30 +1285,6 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1247 return NULL; 1285 return NULL;
1248} 1286}
1249 1287
1250static inline int is_arm_mapping_symbol(const char *str)
1251{
1252 return str[0] == '$' && strchr("axtd", str[1])
1253 && (str[2] == '\0' || str[2] == '.');
1254}
1255
1256/*
1257 * If there's no name there, ignore it; likewise, ignore it if it's
1258 * one of the magic symbols emitted used by current ARM tools.
1259 *
1260 * Otherwise if find_symbols_between() returns those symbols, they'll
1261 * fail the whitelist tests and cause lots of false alarms ... fixable
1262 * only by merging __exit and __init sections into __text, bloating
1263 * the kernel (which is especially evil on embedded platforms).
1264 */
1265static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1266{
1267 const char *name = elf->strtab + sym->st_name;
1268
1269 if (!name || !strlen(name))
1270 return 0;
1271 return !is_arm_mapping_symbol(name);
1272}
1273
1274/* 1288/*
1275 * Find symbols before or equal addr and after addr - in the section sec. 1289 * Find symbols before or equal addr and after addr - in the section sec.
1276 * If we find two symbols with equal offset prefer one with a valid name. 1290 * If we find two symbols with equal offset prefer one with a valid name.
@@ -2083,15 +2097,27 @@ static void check_for_unused(enum export exp, const char *m, const char *s)
2083 } 2097 }
2084} 2098}
2085 2099
2086static void check_exports(struct module *mod) 2100static int check_exports(struct module *mod)
2087{ 2101{
2088 struct symbol *s, *exp; 2102 struct symbol *s, *exp;
2103 int err = 0;
2089 2104
2090 for (s = mod->unres; s; s = s->next) { 2105 for (s = mod->unres; s; s = s->next) {
2091 const char *basename; 2106 const char *basename;
2092 exp = find_symbol(s->name); 2107 exp = find_symbol(s->name);
2093 if (!exp || exp->module == mod) 2108 if (!exp || exp->module == mod) {
2109 if (have_vmlinux && !s->weak) {
2110 if (warn_unresolved) {
2111 warn("\"%s\" [%s.ko] undefined!\n",
2112 s->name, mod->name);
2113 } else {
2114 merror("\"%s\" [%s.ko] undefined!\n",
2115 s->name, mod->name);
2116 err = 1;
2117 }
2118 }
2094 continue; 2119 continue;
2120 }
2095 basename = strrchr(mod->name, '/'); 2121 basename = strrchr(mod->name, '/');
2096 if (basename) 2122 if (basename)
2097 basename++; 2123 basename++;
@@ -2101,6 +2127,8 @@ static void check_exports(struct module *mod)
2101 check_for_gpl_usage(exp->export, basename, exp->name); 2127 check_for_gpl_usage(exp->export, basename, exp->name);
2102 check_for_unused(exp->export, basename, exp->name); 2128 check_for_unused(exp->export, basename, exp->name);
2103 } 2129 }
2130
2131 return err;
2104} 2132}
2105 2133
2106static int check_modname_len(struct module *mod) 2134static int check_modname_len(struct module *mod)
@@ -2157,7 +2185,7 @@ static void add_intree_flag(struct buffer *b, int is_intree)
2157/* Cannot check for assembler */ 2185/* Cannot check for assembler */
2158static void add_retpoline(struct buffer *b) 2186static void add_retpoline(struct buffer *b)
2159{ 2187{
2160 buf_printf(b, "\n#ifdef RETPOLINE\n"); 2188 buf_printf(b, "\n#ifdef CONFIG_RETPOLINE\n");
2161 buf_printf(b, "MODULE_INFO(retpoline, \"Y\");\n"); 2189 buf_printf(b, "MODULE_INFO(retpoline, \"Y\");\n");
2162 buf_printf(b, "#endif\n"); 2190 buf_printf(b, "#endif\n");
2163} 2191}
@@ -2178,19 +2206,8 @@ static int add_versions(struct buffer *b, struct module *mod)
2178 2206
2179 for (s = mod->unres; s; s = s->next) { 2207 for (s = mod->unres; s; s = s->next) {
2180 exp = find_symbol(s->name); 2208 exp = find_symbol(s->name);
2181 if (!exp || exp->module == mod) { 2209 if (!exp || exp->module == mod)
2182 if (have_vmlinux && !s->weak) {
2183 if (warn_unresolved) {
2184 warn("\"%s\" [%s.ko] undefined!\n",
2185 s->name, mod->name);
2186 } else {
2187 merror("\"%s\" [%s.ko] undefined!\n",
2188 s->name, mod->name);
2189 err = 1;
2190 }
2191 }
2192 continue; 2210 continue;
2193 }
2194 s->module = exp->module; 2211 s->module = exp->module;
2195 s->crc_valid = exp->crc_valid; 2212 s->crc_valid = exp->crc_valid;
2196 s->crc = exp->crc; 2213 s->crc = exp->crc;
@@ -2227,15 +2244,15 @@ static int add_versions(struct buffer *b, struct module *mod)
2227 return err; 2244 return err;
2228} 2245}
2229 2246
2230static void add_depends(struct buffer *b, struct module *mod, 2247static void add_depends(struct buffer *b, struct module *mod)
2231 struct module *modules)
2232{ 2248{
2233 struct symbol *s; 2249 struct symbol *s;
2234 struct module *m;
2235 int first = 1; 2250 int first = 1;
2236 2251
2237 for (m = modules; m; m = m->next) 2252 /* Clear ->seen flag of modules that own symbols needed by this. */
2238 m->seen = is_vmlinux(m->name); 2253 for (s = mod->unres; s; s = s->next)
2254 if (s->module)
2255 s->module->seen = is_vmlinux(s->module->name);
2239 2256
2240 buf_printf(b, "\n"); 2257 buf_printf(b, "\n");
2241 buf_printf(b, "static const char __module_depends[]\n"); 2258 buf_printf(b, "static const char __module_depends[]\n");
@@ -2416,7 +2433,7 @@ int main(int argc, char **argv)
2416 struct ext_sym_list *extsym_iter; 2433 struct ext_sym_list *extsym_iter;
2417 struct ext_sym_list *extsym_start = NULL; 2434 struct ext_sym_list *extsym_start = NULL;
2418 2435
2419 while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) { 2436 while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awE")) != -1) {
2420 switch (opt) { 2437 switch (opt) {
2421 case 'i': 2438 case 'i':
2422 kernel_read = optarg; 2439 kernel_read = optarg;
@@ -2482,12 +2499,6 @@ int main(int argc, char **argv)
2482 if (files_source) 2499 if (files_source)
2483 read_symbols_from_files(files_source); 2500 read_symbols_from_files(files_source);
2484 2501
2485 for (mod = modules; mod; mod = mod->next) {
2486 if (mod->skip)
2487 continue;
2488 check_exports(mod);
2489 }
2490
2491 err = 0; 2502 err = 0;
2492 2503
2493 for (mod = modules; mod; mod = mod->next) { 2504 for (mod = modules; mod; mod = mod->next) {
@@ -2499,12 +2510,13 @@ int main(int argc, char **argv)
2499 buf.pos = 0; 2510 buf.pos = 0;
2500 2511
2501 err |= check_modname_len(mod); 2512 err |= check_modname_len(mod);
2513 err |= check_exports(mod);
2502 add_header(&buf, mod); 2514 add_header(&buf, mod);
2503 add_intree_flag(&buf, !external_module); 2515 add_intree_flag(&buf, !external_module);
2504 add_retpoline(&buf); 2516 add_retpoline(&buf);
2505 add_staging_flag(&buf, mod->name); 2517 add_staging_flag(&buf, mod->name);
2506 err |= add_versions(&buf, mod); 2518 err |= add_versions(&buf, mod);
2507 add_depends(&buf, mod, modules); 2519 add_depends(&buf, mod);
2508 add_moddevtable(&buf, mod); 2520 add_moddevtable(&buf, mod);
2509 add_srcversion(&buf, mod); 2521 add_srcversion(&buf, mod);
2510 2522
diff --git a/scripts/package/Makefile b/scripts/package/Makefile
index 73503ebce632..453fecee62f0 100644
--- a/scripts/package/Makefile
+++ b/scripts/package/Makefile
@@ -33,7 +33,6 @@ MKSPEC := $(srctree)/scripts/package/mkspec
33 33
34quiet_cmd_src_tar = TAR $(2).tar.gz 34quiet_cmd_src_tar = TAR $(2).tar.gz
35 cmd_src_tar = \ 35 cmd_src_tar = \
36set -e; \
37if test "$(objtree)" != "$(srctree)"; then \ 36if test "$(objtree)" != "$(srctree)"; then \
38 echo >&2; \ 37 echo >&2; \
39 echo >&2 " ERROR:"; \ 38 echo >&2 " ERROR:"; \
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index 895c40e8679f..a50a2aa963ad 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -397,7 +397,7 @@ static uint32_t (*w2)(uint16_t);
397static int 397static int
398is_mcounted_section_name(char const *const txtname) 398is_mcounted_section_name(char const *const txtname)
399{ 399{
400 return strcmp(".text", txtname) == 0 || 400 return strncmp(".text", txtname, 5) == 0 ||
401 strcmp(".init.text", txtname) == 0 || 401 strcmp(".init.text", txtname) == 0 ||
402 strcmp(".ref.text", txtname) == 0 || 402 strcmp(".ref.text", txtname) == 0 ||
403 strcmp(".sched.text", txtname) == 0 || 403 strcmp(".sched.text", txtname) == 0 ||
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index f599031260d5..68841d01162c 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -142,6 +142,11 @@ my %text_sections = (
142 ".text.unlikely" => 1, 142 ".text.unlikely" => 1,
143); 143);
144 144
145# Acceptable section-prefixes to record.
146my %text_section_prefixes = (
147 ".text." => 1,
148);
149
145# Note: we are nice to C-programmers here, thus we skip the '||='-idiom. 150# Note: we are nice to C-programmers here, thus we skip the '||='-idiom.
146$objdump = 'objdump' if (!$objdump); 151$objdump = 'objdump' if (!$objdump);
147$objcopy = 'objcopy' if (!$objcopy); 152$objcopy = 'objcopy' if (!$objcopy);
@@ -519,6 +524,14 @@ while (<IN>) {
519 524
520 # Only record text sections that we know are safe 525 # Only record text sections that we know are safe
521 $read_function = defined($text_sections{$1}); 526 $read_function = defined($text_sections{$1});
527 if (!$read_function) {
528 foreach my $prefix (keys %text_section_prefixes) {
529 if (substr($1, 0, length $prefix) eq $prefix) {
530 $read_function = 1;
531 last;
532 }
533 }
534 }
522 # print out any recorded offsets 535 # print out any recorded offsets
523 update_funcs(); 536 update_funcs();
524 537
diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/genheaders/genheaders.c
index fa48fabcb330..1ceedea847dd 100644
--- a/scripts/selinux/genheaders/genheaders.c
+++ b/scripts/selinux/genheaders/genheaders.c
@@ -19,8 +19,6 @@ struct security_class_mapping {
19#include "classmap.h" 19#include "classmap.h"
20#include "initial_sid_to_string.h" 20#include "initial_sid_to_string.h"
21 21
22#define max(x, y) (((int)(x) > (int)(y)) ? x : y)
23
24const char *progname; 22const char *progname;
25 23
26static void usage(void) 24static void usage(void)
@@ -46,11 +44,9 @@ static char *stoupperx(const char *s)
46 44
47int main(int argc, char *argv[]) 45int main(int argc, char *argv[])
48{ 46{
49 int i, j, k; 47 int i, j;
50 int isids_len; 48 int isids_len;
51 FILE *fout; 49 FILE *fout;
52 const char *needle = "SOCKET";
53 char *substr;
54 50
55 progname = argv[0]; 51 progname = argv[0];
56 52
@@ -80,20 +76,14 @@ int main(int argc, char *argv[])
80 76
81 for (i = 0; secclass_map[i].name; i++) { 77 for (i = 0; secclass_map[i].name; i++) {
82 struct security_class_mapping *map = &secclass_map[i]; 78 struct security_class_mapping *map = &secclass_map[i];
83 fprintf(fout, "#define SECCLASS_%s", map->name); 79 fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1);
84 for (j = 0; j < max(1, 40 - strlen(map->name)); j++)
85 fprintf(fout, " ");
86 fprintf(fout, "%2d\n", i+1);
87 } 80 }
88 81
89 fprintf(fout, "\n"); 82 fprintf(fout, "\n");
90 83
91 for (i = 1; i < isids_len; i++) { 84 for (i = 1; i < isids_len; i++) {
92 const char *s = initial_sid_to_string[i]; 85 const char *s = initial_sid_to_string[i];
93 fprintf(fout, "#define SECINITSID_%s", s); 86 fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i);
94 for (j = 0; j < max(1, 40 - strlen(s)); j++)
95 fprintf(fout, " ");
96 fprintf(fout, "%2d\n", i);
97 } 87 }
98 fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); 88 fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
99 fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n"); 89 fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
@@ -101,9 +91,10 @@ int main(int argc, char *argv[])
101 fprintf(fout, "\tbool sock = false;\n\n"); 91 fprintf(fout, "\tbool sock = false;\n\n");
102 fprintf(fout, "\tswitch (kern_tclass) {\n"); 92 fprintf(fout, "\tswitch (kern_tclass) {\n");
103 for (i = 0; secclass_map[i].name; i++) { 93 for (i = 0; secclass_map[i].name; i++) {
94 static char s[] = "SOCKET";
104 struct security_class_mapping *map = &secclass_map[i]; 95 struct security_class_mapping *map = &secclass_map[i];
105 substr = strstr(map->name, needle); 96 int len = strlen(map->name), l = sizeof(s) - 1;
106 if (substr && strcmp(substr, needle) == 0) 97 if (len >= l && memcmp(map->name + len - l, s, l) == 0)
107 fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); 98 fprintf(fout, "\tcase SECCLASS_%s:\n", map->name);
108 } 99 }
109 fprintf(fout, "\t\tsock = true;\n"); 100 fprintf(fout, "\t\tsock = true;\n");
@@ -129,17 +120,15 @@ int main(int argc, char *argv[])
129 120
130 for (i = 0; secclass_map[i].name; i++) { 121 for (i = 0; secclass_map[i].name; i++) {
131 struct security_class_mapping *map = &secclass_map[i]; 122 struct security_class_mapping *map = &secclass_map[i];
123 int len = strlen(map->name);
132 for (j = 0; map->perms[j]; j++) { 124 for (j = 0; map->perms[j]; j++) {
133 if (j >= 32) { 125 if (j >= 32) {
134 fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", 126 fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n",
135 map->name, map->perms[j]); 127 map->name, map->perms[j]);
136 exit(5); 128 exit(5);
137 } 129 }
138 fprintf(fout, "#define %s__%s", map->name, 130 fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name,
139 map->perms[j]); 131 39-len, map->perms[j], 1U<<j);
140 for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++)
141 fprintf(fout, " ");
142 fprintf(fout, "0x%08xU\n", (1<<j));
143 } 132 }
144 } 133 }
145 134
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 71f39410691b..365b3c2b8f43 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -73,8 +73,16 @@ scm_version()
73 printf -- '-svn%s' "`git svn find-rev $head`" 73 printf -- '-svn%s' "`git svn find-rev $head`"
74 fi 74 fi
75 75
76 # Check for uncommitted changes 76 # Check for uncommitted changes.
77 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then 77 # First, with git-status, but --no-optional-locks is only
78 # supported in git >= 2.14, so fall back to git-diff-index if
79 # it fails. Note that git-diff-index does not refresh the
80 # index, so it may give misleading results. See
81 # git-update-index(1), git-diff-index(1), and git-status(1).
82 if {
83 git --no-optional-locks status -uno --porcelain 2>/dev/null ||
84 git diff-index --name-only HEAD
85 } | grep -qvE '^(.. )?scripts/package'; then
78 printf '%s' -dirty 86 printf '%s' -dirty
79 fi 87 fi
80 88
diff --git a/scripts/spdxcheck-test.sh b/scripts/spdxcheck-test.sh
new file mode 100644
index 000000000000..cfea6a0d1cc0
--- /dev/null
+++ b/scripts/spdxcheck-test.sh
@@ -0,0 +1,12 @@
1#!/bin/sh
2
3for PYTHON in python2 python3; do
4 # run check on a text and a binary file
5 for FILE in Makefile Documentation/logo.gif; do
6 $PYTHON scripts/spdxcheck.py $FILE
7 $PYTHON scripts/spdxcheck.py - < $FILE
8 done
9
10 # run check on complete tree to catch any other issues
11 $PYTHON scripts/spdxcheck.py > /dev/null
12done
diff --git a/scripts/spdxcheck.py b/scripts/spdxcheck.py
index 5056fb3b897d..e559c6294c39 100755
--- a/scripts/spdxcheck.py
+++ b/scripts/spdxcheck.py
@@ -168,6 +168,7 @@ class id_parser(object):
168 self.curline = 0 168 self.curline = 0
169 try: 169 try:
170 for line in fd: 170 for line in fd:
171 line = line.decode(locale.getpreferredencoding(False), errors='ignore')
171 self.curline += 1 172 self.curline += 1
172 if self.curline > maxlines: 173 if self.curline > maxlines:
173 break 174 break
@@ -249,12 +250,13 @@ if __name__ == '__main__':
249 250
250 try: 251 try:
251 if len(args.path) and args.path[0] == '-': 252 if len(args.path) and args.path[0] == '-':
252 parser.parse_lines(sys.stdin, args.maxlines, '-') 253 stdin = os.fdopen(sys.stdin.fileno(), 'rb')
254 parser.parse_lines(stdin, args.maxlines, '-')
253 else: 255 else:
254 if args.path: 256 if args.path:
255 for p in args.path: 257 for p in args.path:
256 if os.path.isfile(p): 258 if os.path.isfile(p):
257 parser.parse_lines(open(p), args.maxlines, p) 259 parser.parse_lines(open(p, 'rb'), args.maxlines, p)
258 elif os.path.isdir(p): 260 elif os.path.isdir(p):
259 scan_git_subtree(repo.head.reference.commit.tree, p) 261 scan_git_subtree(repo.head.reference.commit.tree, p)
260 else: 262 else:
diff --git a/scripts/tags.sh b/scripts/tags.sh
index 4fa070f9231a..f470d9919ed7 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -191,7 +191,7 @@ regex_c=(
191 '/^DEF_PCI_AC_\(\|NO\)RET(\([[:alnum:]_]*\).*/\2/' 191 '/^DEF_PCI_AC_\(\|NO\)RET(\([[:alnum:]_]*\).*/\2/'
192 '/^PCI_OP_READ(\(\w*\).*[1-4])/pci_bus_read_config_\1/' 192 '/^PCI_OP_READ(\(\w*\).*[1-4])/pci_bus_read_config_\1/'
193 '/^PCI_OP_WRITE(\(\w*\).*[1-4])/pci_bus_write_config_\1/' 193 '/^PCI_OP_WRITE(\(\w*\).*[1-4])/pci_bus_write_config_\1/'
194 '/\<DEFINE_\(MUTEX\|SEMAPHORE\|SPINLOCK\)(\([[:alnum:]_]*\)/\2/v/' 194 '/\<DEFINE_\(RT_MUTEX\|MUTEX\|SEMAPHORE\|SPINLOCK\)(\([[:alnum:]_]*\)/\2/v/'
195 '/\<DEFINE_\(RAW_SPINLOCK\|RWLOCK\|SEQLOCK\)(\([[:alnum:]_]*\)/\2/v/' 195 '/\<DEFINE_\(RAW_SPINLOCK\|RWLOCK\|SEQLOCK\)(\([[:alnum:]_]*\)/\2/v/'
196 '/\<DECLARE_\(RWSEM\|COMPLETION\)(\([[:alnum:]_]\+\)/\2/v/' 196 '/\<DECLARE_\(RWSEM\|COMPLETION\)(\([[:alnum:]_]\+\)/\2/v/'
197 '/\<DECLARE_BITMAP(\([[:alnum:]_]*\)/\1/v/' 197 '/\<DECLARE_BITMAP(\([[:alnum:]_]*\)/\1/v/'
@@ -204,6 +204,15 @@ regex_c=(
204 '/\(^\s\)OFFSET(\([[:alnum:]_]*\)/\2/v/' 204 '/\(^\s\)OFFSET(\([[:alnum:]_]*\)/\2/v/'
205 '/\(^\s\)DEFINE(\([[:alnum:]_]*\)/\2/v/' 205 '/\(^\s\)DEFINE(\([[:alnum:]_]*\)/\2/v/'
206 '/\<\(DEFINE\|DECLARE\)_HASHTABLE(\([[:alnum:]_]*\)/\2/v/' 206 '/\<\(DEFINE\|DECLARE\)_HASHTABLE(\([[:alnum:]_]*\)/\2/v/'
207 '/\<DEFINE_ID\(R\|A\)(\([[:alnum:]_]\+\)/\2/'
208 '/\<DEFINE_WD_CLASS(\([[:alnum:]_]\+\)/\1/'
209 '/\<ATOMIC_NOTIFIER_HEAD(\([[:alnum:]_]\+\)/\1/'
210 '/\<RAW_NOTIFIER_HEAD(\([[:alnum:]_]\+\)/\1/'
211 '/\<DECLARE_FAULT_ATTR(\([[:alnum:]_]\+\)/\1/'
212 '/\<BLOCKING_NOTIFIER_HEAD(\([[:alnum:]_]\+\)/\1/'
213 '/\<DEVICE_ATTR_\(RW\|RO\|WO\)(\([[:alnum:]_]\+\)/dev_attr_\2/'
214 '/\<DRIVER_ATTR_\(RW\|RO\|WO\)(\([[:alnum:]_]\+\)/driver_attr_\2/'
215 '/\<\(DEFINE\|DECLARE\)_STATIC_KEY_\(TRUE\|FALSE\)\(\|_RO\)(\([[:alnum:]_]\+\)/\4/'
207) 216)
208regex_kconfig=( 217regex_kconfig=(
209 '/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/\2/' 218 '/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/\2/'
@@ -249,7 +258,7 @@ exuberant()
249 -I __initdata,__exitdata,__initconst,__ro_after_init \ 258 -I __initdata,__exitdata,__initconst,__ro_after_init \
250 -I __initdata_memblock \ 259 -I __initdata_memblock \
251 -I __refdata,__attribute,__maybe_unused,__always_unused \ 260 -I __refdata,__attribute,__maybe_unused,__always_unused \
252 -I __acquires,__releases,__deprecated \ 261 -I __acquires,__releases,__deprecated,__always_inline \
253 -I __read_mostly,__aligned,____cacheline_aligned \ 262 -I __read_mostly,__aligned,____cacheline_aligned \
254 -I ____cacheline_aligned_in_smp \ 263 -I ____cacheline_aligned_in_smp \
255 -I __cacheline_aligned,__cacheline_aligned_in_smp \ 264 -I __cacheline_aligned,__cacheline_aligned_in_smp \
diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index 7493c0ee51cc..db00e3e30a59 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -395,7 +395,7 @@ usage(void)
395 * When we have processed a group that starts off with a known-false 395 * When we have processed a group that starts off with a known-false
396 * #if/#elif sequence (which has therefore been deleted) followed by a 396 * #if/#elif sequence (which has therefore been deleted) followed by a
397 * #elif that we don't understand and therefore must keep, we edit the 397 * #elif that we don't understand and therefore must keep, we edit the
398 * latter into a #if to keep the nesting correct. We use strncpy() to 398 * latter into a #if to keep the nesting correct. We use memcpy() to
399 * overwrite the 4 byte token "elif" with "if " without a '\0' byte. 399 * overwrite the 4 byte token "elif" with "if " without a '\0' byte.
400 * 400 *
401 * When we find a true #elif in a group, the following block will 401 * When we find a true #elif in a group, the following block will
@@ -450,7 +450,7 @@ static void Idrop (void) { Fdrop(); ignoreon(); }
450static void Itrue (void) { Ftrue(); ignoreon(); } 450static void Itrue (void) { Ftrue(); ignoreon(); }
451static void Ifalse(void) { Ffalse(); ignoreon(); } 451static void Ifalse(void) { Ffalse(); ignoreon(); }
452/* modify this line */ 452/* modify this line */
453static void Mpass (void) { strncpy(keyword, "if ", 4); Pelif(); } 453static void Mpass (void) { memcpy(keyword, "if ", 4); Pelif(); }
454static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); } 454static void Mtrue (void) { keywordedit("else"); state(IS_TRUE_MIDDLE); }
455static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); } 455static void Melif (void) { keywordedit("endif"); state(IS_FALSE_TRAILER); }
456static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); } 456static void Melse (void) { keywordedit("endif"); state(IS_FALSE_ELSE); }