perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Sun, 27 Mar 2022 05:57:33 +0000 (13:57 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Apr 2022 18:59:24 +0000 (20:59 +0200)
commit0309f053ce47721aed7987ad8048d7862235a61d
tree1f84d451a028c14704ed4727142b5452d552f344
parent8a05a6952ecd59aaa62cbdcdaf523ae2c8f436e8
perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator

commit 2012a9e279013933885983cbe0a5fe828052563b upstream.

The bug is here:
return cluster;

The list iterator value 'cluster' will *always* be set and non-NULL
by list_for_each_entry(), so it is incorrect to assume that the
iterator value will be NULL if the list is empty or no element
is found.

To fix the bug, return 'cluster' when found, otherwise return NULL.

Cc: stable@vger.kernel.org
Fixes: 21bdbb7102ed ("perf: add qcom l2 cache perf events driver")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Link: https://lore.kernel.org/r/20220327055733.4070-1-xiam0nd.tong@gmail.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/perf/qcom_l2_pmu.c