In case of loadable modules using dma-iommu helpers, it makes sense to drop the reference to the iova cache on module exit. Add a helper called iommu_dma_cleanup() that undoes the effects of iommu_dma_init(), so that modules can be unloaded cleanly.
Signed-off-by: Tomasz Figa <tf...@chromium.org> --- drivers/iommu/dma-iommu.c | 6 ++++++ include/linux/dma-iommu.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 7cdeaf930106..51afa18a5de1 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -82,6 +82,12 @@ int iommu_dma_init(void) } EXPORT_SYMBOL(iommu_dma_init); +void iommu_dma_cleanup(void) +{ + iova_cache_put(); +} +EXPORT_SYMBOL(iommu_dma_cleanup); + /** * iommu_get_dma_cookie - Acquire DMA-API resources for a domain * @domain: IOMMU domain to prepare for DMA-API usage diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index 92f20832fd28..b12d9207a87a 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -24,7 +24,9 @@ #include <linux/iommu.h> #include <linux/msi.h> +/* Framework initialization - reference counted */ int iommu_dma_init(void); +void iommu_dma_cleanup(void); /* Domain management interface for IOMMU drivers */ int iommu_get_dma_cookie(struct iommu_domain *domain); @@ -85,6 +87,10 @@ static inline int iommu_dma_init(void) return 0; } +static inline void iommu_dma_cleanup(void) +{ +} + static inline int iommu_get_dma_cookie(struct iommu_domain *domain) { return -ENODEV; -- 2.13.2.725.g09c95d1e9-goog