Skip to content

Commit d03f133

Browse files
committed
iommufd: Move putting a hwpt to a helper function
Next patch will need to call this from two places. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 1d149ab commit d03f133

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,7 @@ void iommufd_device_detach(struct iommufd_device *idev)
526526
struct iommufd_hw_pagetable *hwpt;
527527

528528
hwpt = iommufd_hw_pagetable_detach(idev);
529-
if (hwpt->auto_domain)
530-
iommufd_object_destroy_user(idev->ictx, &hwpt->obj);
531-
else
532-
refcount_dec(&hwpt->obj.users);
533-
529+
iommufd_hw_pagetable_put(idev->ictx, hwpt);
534530
refcount_dec(&idev->obj.users);
535531
}
536532
EXPORT_SYMBOL_NS_GPL(iommufd_device_detach, IOMMUFD);

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ struct iommufd_hw_pagetable *
260260
iommufd_hw_pagetable_detach(struct iommufd_device *idev);
261261
void iommufd_hw_pagetable_destroy(struct iommufd_object *obj);
262262

263+
static inline void iommufd_hw_pagetable_put(struct iommufd_ctx *ictx,
264+
struct iommufd_hw_pagetable *hwpt)
265+
{
266+
lockdep_assert_not_held(&hwpt->ioas->mutex);
267+
if (hwpt->auto_domain)
268+
iommufd_object_destroy_user(ictx, &hwpt->obj);
269+
else
270+
refcount_dec(&hwpt->obj.users);
271+
}
272+
263273
struct iommufd_group {
264274
struct kref ref;
265275
struct mutex lock;

0 commit comments

Comments
 (0)