Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e49e0605 authored by Patrick Daly's avatar Patrick Daly Committed by Liam Mark
Browse files

iommu: iommu-debug: Fix duplicate iommu_attachment entries



iommu_attach() and iommu_detach() may be called multiple times for the
same group/domain pair. Ensure that only a single entry is put on the
attachment list.

Change-Id: I9c6c106647fab4b63a3332b7a7181f70b75ba18f
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 793842d0
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -102,20 +102,25 @@ void iommu_debug_attach_device(struct iommu_domain *domain,
	struct iommu_debug_attachment *attach;
	struct iommu_group *group;

	group = iommu_group_get(dev);
	group = dev->iommu_group;
	if (!group)
		return;

	mutex_lock(&iommu_debug_attachments_lock);
	list_for_each_entry(attach, &iommu_debug_attachments, list)
		if ((attach->domain == domain) && (attach->group == group))
			goto out;

	attach = kzalloc(sizeof(*attach), GFP_KERNEL);
	if (!attach)
		return;
		goto out;

	attach->domain = domain;
	attach->group = group;
	INIT_LIST_HEAD(&attach->list);

	mutex_lock(&iommu_debug_attachments_lock);
	list_add(&attach->list, &iommu_debug_attachments);
out:
	mutex_unlock(&iommu_debug_attachments_lock);
}

@@ -128,7 +133,6 @@ void iommu_debug_domain_remove(struct iommu_domain *domain)
		if (it->domain != domain)
			continue;
		list_del(&it->list);
		iommu_group_put(it->group);
		kfree(it);
	}