]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf: arm_cspmu: fix error handling in arm_cspmu_impl_unregister()
authorMa Ke <make24@iscas.ac.cn>
Wed, 22 Oct 2025 11:53:25 +0000 (19:53 +0800)
committerWill Deacon <will@kernel.org>
Mon, 3 Nov 2025 14:20:03 +0000 (14:20 +0000)
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>
drivers/perf/arm_cspmu/arm_cspmu.c

index 33ad2cab5c160c3be38e74dd3f7d201f341c6427..34430b68f60254e9666f230ba42f1f875b20b1b8 100644 (file)
@@ -1407,8 +1407,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);