mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator
@ 2022-03-27  5:57 Xiaomeng Tong
  2022-04-04 10:10 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaomeng Tong @ 2022-03-27  5:57 UTC (permalink / raw)
  To: agross
  Cc: bjorn.andersson, will, mark.rutland, nleeder, linux-arm-msm,
	linux-arm-kernel, linux-kernel, Xiaomeng Tong, stable

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: 21bdbb7102ede ("perf: add qcom l2 cache perf events driver")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
 drivers/perf/qcom_l2_pmu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/perf/qcom_l2_pmu.c b/drivers/perf/qcom_l2_pmu.c
index 7640491aab12..30234c261b05 100644
--- a/drivers/perf/qcom_l2_pmu.c
+++ b/drivers/perf/qcom_l2_pmu.c
@@ -736,7 +736,7 @@ static struct cluster_pmu *l2_cache_associate_cpu_with_cluster(
 {
 	u64 mpidr;
 	int cpu_cluster_id;
-	struct cluster_pmu *cluster = NULL;
+	struct cluster_pmu *cluster;
 
 	/*
 	 * This assumes that the cluster_id is in MPIDR[aff1] for
@@ -758,10 +758,10 @@ static struct cluster_pmu *l2_cache_associate_cpu_with_cluster(
 			 cluster->cluster_id);
 		cpumask_set_cpu(cpu, &cluster->cluster_cpus);
 		*per_cpu_ptr(l2cache_pmu->pmu_cluster, cpu) = cluster;
-		break;
+		return cluster;
 	}
 
-	return cluster;
+	return NULL;
 }
 
 static int l2cache_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator
  2022-03-27  5:57 [PATCH] perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator Xiaomeng Tong
@ 2022-04-04 10:10 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2022-04-04 10:10 UTC (permalink / raw)
  To: Xiaomeng Tong, agross
  Cc: catalin.marinas, kernel-team, Will Deacon, linux-arm-msm,
	linux-arm-kernel, nleeder, mark.rutland, bjorn.andersson,
	linux-kernel, stable

On Sun, 27 Mar 2022 13:57:33 +0800, Xiaomeng Tong wrote:
> 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.
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator
      https://git.kernel.org/arm64/c/2012a9e27901

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-04 10:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27  5:57 [PATCH] perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator Xiaomeng Tong
2022-04-04 10:10 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®