* [PATCH] perf: arm_cspmu: fix error handling in arm_cspmu_impl_unregister()
@ 2025-09-27 7:30 Ma Ke
2025-09-27 8:28 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2025-09-27 7:30 UTC (permalink / raw)
To: will, mark.rutland, ilkka, james.clark, robin.murphy,
u.kleine-koenig, make24, bwicaksono, suzuki.poulose
Cc: linux-arm-kernel, linux-perf-users, linux-kernel, akpm, stable
driver_find_device() calls get_device() to increment the reference
count once a matching device is found. device_release_driver()
releases the driver, but it does not decrease the reference count that
was incremented by driver_find_device(). At the end of the loop, there
is no put_device() to balance the reference count. To avoid reference
count leakage, add put_device() to decrease the reference count.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: bfc653aa89cb ("perf: arm_cspmu: Separate Arm and vendor module")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/perf/arm_cspmu/arm_cspmu.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/perf/arm_cspmu/arm_cspmu.c b/drivers/perf/arm_cspmu/arm_cspmu.c
index efa9b229e701..e0d4293f06f9 100644
--- a/drivers/perf/arm_cspmu/arm_cspmu.c
+++ b/drivers/perf/arm_cspmu/arm_cspmu.c
@@ -1365,8 +1365,10 @@ void arm_cspmu_impl_unregister(const struct arm_cspmu_impl_match *impl_match)
/* Unbind the driver from all matching backend devices. */
while ((dev = driver_find_device(&arm_cspmu_driver.driver, NULL,
- match, arm_cspmu_match_device)))
+ match, arm_cspmu_match_device))) {
device_release_driver(dev);
+ put_device(dev);
+ }
mutex_lock(&arm_cspmu_lock);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] perf: arm_cspmu: fix error handling in arm_cspmu_impl_unregister()
2025-09-27 7:30 [PATCH] perf: arm_cspmu: fix error handling in arm_cspmu_impl_unregister() Ma Ke
@ 2025-09-27 8:28 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-09-27 8:28 UTC (permalink / raw)
To: make24, linux-arm-kernel, linux-perf-users
Cc: stable, LKML, Andrew Morton, Besar Wicaksono, Ilkka Koskinen,
James Clark, Mark Rutland, Robin Murphy, Suzuki Poulouse,
Uwe Kleine-König, Will Deacon
> driver_find_device() calls get_device() to increment the reference
> count once a matching device is found. device_release_driver()
> releases the driver, but it does not decrease the reference count that
> was incremented by driver_find_device(). At the end of the loop, there
> is no put_device() to balance the reference count. To avoid reference
> count leakage, add put_device() to decrease the reference count.
Can a summary phrase like “Prevent reference count leaks in arm_cspmu_impl_unregister()”
be more appropriate?
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-27 8:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-27 7:30 [PATCH] perf: arm_cspmu: fix error handling in arm_cspmu_impl_unregister() Ma Ke
2025-09-27 8:28 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox