x86/kernel: remove unneeded dead-store initialization
PATCH 1/1 x86/kernel: remove unneeded dead-store initialization
make clang-analyzer on x86_64 defconfig caught my attention with:
arch/x86/kernel/cpu/cacheinfo.c:880:24: warning: Value stored to 'this_cpu_ci' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); ^
So, simply remove this unneeded dead-store initialization to make clang-analyzer happy.
As compilers will detect this unneeded assignment and optimize this anyway, the resulting object code is identical before and after this change.
No functional change. No change to object code.
--- arch/x86/kernel/cpu/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/cacheinfo.c +1 -1
@@ -877,7 +877,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c)static int __cache_amd_cpumap_setup (unsigned int cpu,int index,struct _cpuid4_info_regs *base) { -struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct cpu_cacheinfo *this_cpu_ci;struct cacheinfo *this_leaf;int i, sibling;
Signature · 1 line
1.8.3.1
Quoted 9 lines · Yang Li
make clang-analyzer on
x86_64defconfig caught my attention with:
arch/x86/kernel/cpu/cacheinfo.c:880:24: warning: Value stored to 'this_cpu_ci' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
structcpu_cacheinfo*this_cpu_ci=get_cpu_cacheinfo(cpu); ^
Quoted 7 lines
So, simply remove this unneeded dead-store initialization to make clang-analyzer happy.
As compilers will detect this unneeded assignment and optimize this anyway, the resulting object code is identical before and after this change.
No functional change. No change to object code.
Looks like this is from when this code was introduced in commit 0d55ba46bfbe ("x86/cacheinfo: Move cacheinfo sysfs code to generic infrastructure")
though this file was moved from arch/x86/kernel/cpu/intel_cacheinfo.c to arch/x86/kernel/cpu/cacheinfo.c in
commit 1d200c078d0e ("x86/CPU: Rename intel_cacheinfo.c to cacheinfo.c") (So I don't think a Fixes tag for 0d55ba46bfbe would be appropriate).
Thanks for the patch!
Quoted 23 lines
Reported-by Abaci Robot <[email protected]>Signed-off-by Yang Li <[email protected]>--- arch/x86/kernel/cpu/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/cpu/cacheinfo.c +1
-2@@ -877,7 +877,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c)static int __cache_amd_cpumap_setup (unsigned int cpu,int index,struct _cpuid4_info_regs *base) { -struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct cpu_cacheinfo *this_cpu_ci;struct cacheinfo *this_leaf;int i, sibling; --1.8.3.1
Signature · 2 lines
Thanks, ~Nick Desaulniers
Borislav Petkov
maintainerQuoted 1 line · Yang Li
make clang-analyzer on
x86_64defconfig caught my attention with:
I can't trigger this here using:
make CC=clang-11 -j16 clang-analyzer
I get all kinds of missing python scripts:
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.9/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/mnt/kernel/kernel/linux/./scripts/clang-tools/run-clang-tools.py", line 54, in run_analysis
p = subprocess.run(["clang-tidy", "-p", args.path, checks, entry["file"]], File "/usr/lib/python3.9/subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy' """
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/mnt/kernel/kernel/linux/./scripts/clang-tools/run-clang-tools.py", line 74, in <module>
main()
File "/mnt/kernel/kernel/linux/./scripts/clang-tools/run-clang-tools.py", line 70, in main
pool.map(run_analysis, datastore)
File "/usr/lib/python3.9/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib/python3.9/multiprocessing/pool.py", line 771, in get
raise self._value
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy'
make: *** [Makefile:1914: clang-analyzer] Error 1
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 9 lines · Borislav Petkov
Quoted 1 line · Yang Li
make clang-analyzer on
x86_64defconfig caught my attention with:I can't trigger this here using:
make CC=clang-11 -j16 clang-analyzer
I get all kinds of missing python scripts:
<snip>
Quoted 1 line
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy'
You do have clang-tidy installed right? which clang-tidy?
Signature · 2 lines
Thanks, ~Nick Desaulniers
Borislav Petkov
maintainerQuoted 1 line · Nick Desaulniers
You do have clang-tidy installed right?
which clang-tidy?
Yah, installed that and was able to repro:
arch/x86/kernel/cpu/cacheinfo.c:880:24: warning: Value stored to 'this_cpu_ci' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
arch/x86/kernel/cpu/cacheinfo.c:880:24: note: Value stored to 'this_cpu_ci' during its initialization is never read
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteBorislav Petkov
maintainerQuoted 2 lines · Borislav Petkov
Quoted 1 line · Nick Desaulniers
You do have clang-tidy installed right?
which clang-tidy?
Btw, for user convenience, that "clang-analyzer" Makefile target could check for the presence of clang-tidy and fail if it is not there, with an informative error message. Methinks.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 8 lines · Borislav Petkov
Quoted 2 lines · Borislav Petkov
Quoted 1 line · Nick Desaulniers
You do have clang-tidy installed right?
which clang-tidy?Btw, for user convenience, that "clang-analyzer"
Makefiletarget could check for the presence of clang-tidy and fail if it is not there, with an informative error message. Methinks.
Yes, that's a good idea; we had a similar discussion recently about what happens if you enable CONFIG_DEBUG_INFO_BTF and don't have pahole installed. This is very much in the same vein. I've filed
https://github.com/ClangBuiltLinux/linux/issues/1342
to follow up on. Should be a good beginner bug for folks looking to get started contributing.
--
Thanks,
~Nick Desaulniers
[tip: x86/cleanups] x86/cacheinfo: Remove unneeded dead-store initialization
In reply to Yang LiThe following commit has been merged into the x86/cleanups branch of tip:
The following commit has been merged into the x86/cleanups branch of tip:
Commit-ID: dda451f391eee5d68db3ca87fd8b2a42c8c2b507 Gitweb: https://git.kernel.org/tip/dda451f391eee5d68db3ca87fd8b2a42c8c2b507 Author: Yang Li <[email protected]> AuthorDate: Wed, 31 Mar 2021 16:00:24 +08:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Wed, 07 Apr 2021 21:12:12 +02:00
x86/cacheinfo: Remove unneeded dead-store initialization
$ make CC=clang clang-analyzer
(needs clang-tidy installed on the system too)
on x86_64 defconfig triggers:
arch/x86/kernel/cpu/cacheinfo.c:880:24: warning: Value stored to 'this_cpu_ci' \
during its initialization is never read [clang-analyzer-deadcode.DeadStores]
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
^ arch/x86/kernel/cpu/cacheinfo.c:880:24: note: Value stored to 'this_cpu_ci' \
during its initialization is never read
So simply remove this unneeded dead-store initialization.
As compilers will detect this unneeded assignment and optimize this anyway the resulting object code is identical before and after this change.
No functional change. No change to object code.
[ bp: Massage commit message. ]
--- arch/x86/kernel/cpu/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/cacheinfo.c +1 -1
@@ -877,7 +877,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c)static int __cache_amd_cpumap_setup (unsigned int cpu,int index,struct _cpuid4_info_regs *base) { -struct cpu_cacheinfo *this_cpu_ci =get_cpu_cacheinfo (cpu); +struct cpu_cacheinfo *this_cpu_ci;struct cacheinfo *this_leaf;int i, sibling;