Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf: arm_cspmu: fix error handling in arm_cspmu_impl_unregister()

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>
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Ma Ke and committed by
Will Deacon
970e1e41 8fa08f88

+3 -1
+3 -1
drivers/perf/arm_cspmu/arm_cspmu.c
··· 1407 1407 1408 1408 /* Unbind the driver from all matching backend devices. */ 1409 1409 while ((dev = driver_find_device(&arm_cspmu_driver.driver, NULL, 1410 - match, arm_cspmu_match_device))) 1410 + match, arm_cspmu_match_device))) { 1411 1411 device_release_driver(dev); 1412 + put_device(dev); 1413 + } 1412 1414 1413 1415 mutex_lock(&arm_cspmu_lock); 1414 1416