Skip to content

Commit 7bdb996

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Inline iommu_group_get_for_dev() into __iommu_probe_device()
This is the only caller, and it doesn't need the generality of the function. We already know there is no iommu_group, so it is simply two function calls. Moving it here allows the following patches to split the logic in these functions. Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 5665d15 commit 7bdb996

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

drivers/iommu/iommu.c

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static int iommu_setup_default_domain(struct iommu_group *group,
127127
int target_type);
128128
static int iommu_create_device_direct_mappings(struct iommu_domain *domain,
129129
struct device *dev);
130-
static struct iommu_group *iommu_group_get_for_dev(struct device *dev);
131130
static ssize_t iommu_group_store_type(struct iommu_group *group,
132131
const char *buf, size_t count);
133132

@@ -379,12 +378,18 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
379378
if (ops->is_attach_deferred)
380379
dev->iommu->attach_deferred = ops->is_attach_deferred(dev);
381380

382-
group = iommu_group_get_for_dev(dev);
381+
group = ops->device_group(dev);
382+
if (WARN_ON_ONCE(group == NULL))
383+
group = ERR_PTR(-EINVAL);
383384
if (IS_ERR(group)) {
384385
ret = PTR_ERR(group);
385386
goto out_release;
386387
}
387388

389+
ret = iommu_group_add_device(group, dev);
390+
if (ret)
391+
goto err_put_group;
392+
388393
mutex_lock(&group->mutex);
389394
if (group_list && !group->default_domain && list_empty(&group->entry))
390395
list_add_tail(&group->entry, group_list);
@@ -396,6 +401,8 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
396401

397402
return 0;
398403

404+
err_put_group:
405+
iommu_group_put(group);
399406
out_release:
400407
if (ops->release_device)
401408
ops->release_device(dev);
@@ -1670,45 +1677,6 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
16701677
return dom;
16711678
}
16721679

1673-
/**
1674-
* iommu_group_get_for_dev - Find or create the IOMMU group for a device
1675-
* @dev: target device
1676-
*
1677-
* This function is intended to be called by IOMMU drivers and extended to
1678-
* support common, bus-defined algorithms when determining or creating the
1679-
* IOMMU group for a device. On success, the caller will hold a reference
1680-
* to the returned IOMMU group, which will already include the provided
1681-
* device. The reference should be released with iommu_group_put().
1682-
*/
1683-
static struct iommu_group *iommu_group_get_for_dev(struct device *dev)
1684-
{
1685-
const struct iommu_ops *ops = dev_iommu_ops(dev);
1686-
struct iommu_group *group;
1687-
int ret;
1688-
1689-
group = iommu_group_get(dev);
1690-
if (group)
1691-
return group;
1692-
1693-
group = ops->device_group(dev);
1694-
if (WARN_ON_ONCE(group == NULL))
1695-
return ERR_PTR(-EINVAL);
1696-
1697-
if (IS_ERR(group))
1698-
return group;
1699-
1700-
ret = iommu_group_add_device(group, dev);
1701-
if (ret)
1702-
goto out_put_group;
1703-
1704-
return group;
1705-
1706-
out_put_group:
1707-
iommu_group_put(group);
1708-
1709-
return ERR_PTR(ret);
1710-
}
1711-
17121680
struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
17131681
{
17141682
return group->default_domain;

0 commit comments

Comments
 (0)