summaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorMiaoqian Lin <linmq006@gmail.com>2022-12-30 12:31:00 +0400
committerJoerg Roedel <jroedel@suse.de>2023-01-13 13:46:22 +0100
commita6a9a5da68084d5eac6ef85ad09df7fc9c971de4 (patch)
treeee15967813b0327b16f051bf9f504036a68138e8 /drivers/iommu
parent32ea2c57dc216b6ad8125fa680d31daa5d421c95 (diff)
downloadlinux-stable-a6a9a5da68084d5eac6ef85ad09df7fc9c971de4.tar.gz
linux-stable-a6a9a5da68084d5eac6ef85ad09df7fc9c971de4.tar.bz2
linux-stable-a6a9a5da68084d5eac6ef85ad09df7fc9c971de4.zip
iommu: Fix refcount leak in iommu_device_claim_dma_owner
iommu_group_get() returns the group with the reference incremented. Move iommu_group_get() after owner check to fix the refcount leak. Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces") Signed-off-by: Miaoqian Lin <linmq006@gmail.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20221230083100.1489569-1-linmq006@gmail.com [ joro: Remove *group = NULL initialization ] Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/iommu.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index de91dd88705b..5f6a85aea501 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3185,14 +3185,16 @@ EXPORT_SYMBOL_GPL(iommu_group_claim_dma_owner);
*/
int iommu_device_claim_dma_owner(struct device *dev, void *owner)
{
- struct iommu_group *group = iommu_group_get(dev);
+ struct iommu_group *group;
int ret = 0;
- if (!group)
- return -ENODEV;
if (WARN_ON(!owner))
return -EINVAL;
+ group = iommu_group_get(dev);
+ if (!group)
+ return -ENODEV;
+
mutex_lock(&group->mutex);
if (group->owner_cnt) {
if (group->owner != owner) {