iommu/arm-smmu: Fix arm_smmu_device refcount leak when arm_smmu_rpm_get fails
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Thu, 10 Jun 2021 02:54:29 +0000 (10:54 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Jul 2021 14:05:42 +0000 (16:05 +0200)
commitc4007596fbdabc29f858dc2e1990858a146b60b2
tree302cb43d114bb65935ffef7b3ce43a8809043b83
parentf8763ab3fb866330681715259986abbab673805b
iommu/arm-smmu: Fix arm_smmu_device refcount leak when arm_smmu_rpm_get fails

[ Upstream commit 1adf30f198c26539a62d761e45af72cde570413d ]

arm_smmu_rpm_get() invokes pm_runtime_get_sync(), which increases the
refcount of the "smmu" even though the return value is less than 0.

The reference counting issue happens in some error handling paths of
arm_smmu_rpm_get() in its caller functions. When arm_smmu_rpm_get()
fails, the caller functions forget to decrease the refcount of "smmu"
increased by arm_smmu_rpm_get(), causing a refcount leak.

Fix this issue by calling pm_runtime_resume_and_get() instead of
pm_runtime_get_sync() in arm_smmu_rpm_get(), which can keep the refcount
balanced in case of failure.

Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Link: https://lore.kernel.org/r/1623293672-17954-1-git-send-email-xiyuyang19@fudan.edu.cn
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/arm/arm-smmu/arm-smmu.c