perf: arm_cspmu: fix device leak in arm_cspmu_impl_unregister
Subsystems (2)
PATCH 1/1 perf: arm_cspmu: fix device leak in arm_cspmu_impl_unregister
arm_cspmu_impl_unregister() utilizes driver_find_device() to locate matching devices. driver_find_device() increments the ref count of the found device by calling get_device(), but arm_cspmu_impl_unregister() fails to call put_device() to decrement the reference count after processing each device. This results in a reference count leak of the device objects, which prevents devices from being properly released and causes a memory leak. Fix the leak by adding put_device() after device_release_driver() in the while loop.
Found by code review.
Fixes bfc653aa89cb ("perf: arm_cspmu: Separate Arm and vendor module")
Signed-off-by Ma Ke <[email protected]>
--- drivers/perf/arm_cspmu/arm_cspmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/arm_cspmu.c +3 -1
@@ -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);
Signature · 1 line
2.17.1