Skip to content

Commit a6a9a5d

Browse files
Yuuoniyjoergroedel
authored andcommitted
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: 89395cc ("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>
1 parent 32ea2c5 commit a6a9a5d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/iommu/iommu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,14 +3185,16 @@ EXPORT_SYMBOL_GPL(iommu_group_claim_dma_owner);
31853185
*/
31863186
int iommu_device_claim_dma_owner(struct device *dev, void *owner)
31873187
{
3188-
struct iommu_group *group = iommu_group_get(dev);
3188+
struct iommu_group *group;
31893189
int ret = 0;
31903190

3191-
if (!group)
3192-
return -ENODEV;
31933191
if (WARN_ON(!owner))
31943192
return -EINVAL;
31953193

3194+
group = iommu_group_get(dev);
3195+
if (!group)
3196+
return -ENODEV;
3197+
31963198
mutex_lock(&group->mutex);
31973199
if (group->owner_cnt) {
31983200
if (group->owner != owner) {

0 commit comments

Comments
 (0)