Skip to content

Commit

Permalink
perf: qcom_l2_pmu: Make l2_cache_pmu_probe_cluster() more robust
Browse files Browse the repository at this point in the history
If an error occurs after calling list_add(), the &l2cache_pmu->clusters
list will reference some memory that will be freed when the managed
resources will be released.

Move the list_add() at the end of the function when everything is in fine.

This is harmless because if l2_cache_pmu_probe_cluster() fails, then
l2_cache_pmu_probe() will fail as well and 'l2cache_pmu' will be released
as well.
But it looks cleaner and could silence static checker warning.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/6a0f5bdb6b7b2ed4ef194fc49693e902ad5b95ea.1684397879.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Will Deacon <will@kernel.org>
  • Loading branch information
Christophe JAILLET authored and Will Deacon committed Jun 5, 2023
1 parent f818947 commit 7bd42f1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/perf/qcom_l2_pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ static int l2_cache_pmu_probe_cluster(struct device *dev, void *data)
return -ENOMEM;

INIT_LIST_HEAD(&cluster->next);
list_add(&cluster->next, &l2cache_pmu->clusters);
cluster->cluster_id = fw_cluster_id;

irq = platform_get_irq(sdev, 0);
Expand All @@ -883,6 +882,7 @@ static int l2_cache_pmu_probe_cluster(struct device *dev, void *data)

spin_lock_init(&cluster->pmu_lock);

list_add(&cluster->next, &l2cache_pmu->clusters);
l2cache_pmu->num_pmus++;

return 0;
Expand Down

0 comments on commit 7bd42f1

Please sign in to comment.