x86/kernel: remove unneeded dead-store initialization
diff mbox series

Message ID 1617177624-24670-1-git-send-email-yang.lee@linux.alibaba.com
State Accepted
Commit dda451f391eee5d68db3ca87fd8b2a42c8c2b507
Headers show
Series
  • x86/kernel: remove unneeded dead-store initialization
Related show

Commit Message

Yang Li March 31, 2021, 8 a.m. UTC
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.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 arch/x86/kernel/cpu/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nick Desaulniers March 31, 2021, 5:49 p.m. UTC | #1
On Wed, Mar 31, 2021 at 1:00 AM Yang Li <yang.lee@linux.alibaba.com> wrote:
>
> 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.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

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!

>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> ---
>  arch/x86/kernel/cpu/cacheinfo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
> index 3ca9be4..d66af29 100644
> --- a/arch/x86/kernel/cpu/cacheinfo.c
> +++ b/arch/x86/kernel/cpu/cacheinfo.c
> @@ -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
>
Borislav Petkov April 7, 2021, 12:02 p.m. UTC | #2
On Wed, Mar 31, 2021 at 04:00:24PM +0800, Yang Li wrote:
> make clang-analyzer on x86_64 defconfig 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
Nick Desaulniers April 7, 2021, 5:41 p.m. UTC | #3
On Wed, Apr 7, 2021 at 5:02 AM Borislav Petkov <bp@alien8.de> wrote:
>
> On Wed, Mar 31, 2021 at 04:00:24PM +0800, Yang Li wrote:
> > make clang-analyzer on x86_64 defconfig 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>

> FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy'

You do have clang-tidy installed right? `which clang-tidy`?
Borislav Petkov April 7, 2021, 7:03 p.m. UTC | #4
On Wed, Apr 07, 2021 at 10:41:26AM -0700, Nick Desaulniers wrote:
> 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.
Borislav Petkov April 7, 2021, 7:07 p.m. UTC | #5
On Wed, Apr 07, 2021 at 09:03:28PM +0200, Borislav Petkov wrote:
> On Wed, Apr 07, 2021 at 10:41:26AM -0700, Nick Desaulniers wrote:
> > 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.
Nick Desaulniers April 7, 2021, 9:31 p.m. UTC | #6
On Wed, Apr 7, 2021 at 12:07 PM Borislav Petkov <bp@alien8.de> wrote:
>
> On Wed, Apr 07, 2021 at 09:03:28PM +0200, Borislav Petkov wrote:
> > On Wed, Apr 07, 2021 at 10:41:26AM -0700, Nick Desaulniers wrote:
> > > 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.

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

Patch
diff mbox series

diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
index 3ca9be4..d66af29 100644
--- a/arch/x86/kernel/cpu/cacheinfo.c
+++ b/arch/x86/kernel/cpu/cacheinfo.c
@@ -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;