Commit e7b3533c authored by Robin Murphy's avatar Robin Murphy Committed by Joerg Roedel

iommu/iova: Tidy up iova_cache_get() failure

Failure handling in iova_cache_get() is a little messy, and we'd like
to add some more to it, so let's tidy up a bit first. By leaving the
hotplug handler until last we can take advantage of kmem_cache_destroy()
being NULL-safe to have a single cleanup label. We can also improve the
error reporting, noting that kmem_cache_create() already screams if it
fails, so that one is redundant.
Signed-off-by: default avatarRobin Murphy <robin.murphy@arm.com>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Reviewed-by: default avatarPasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Link: https://lore.kernel.org/r/ae4a3bda2d6a9b738221553c838d30473bd624e7.1707144953.git.robin.murphy@arm.comSigned-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 54be6c6c
...@@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova) ...@@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova)
int iova_cache_get(void) int iova_cache_get(void)
{ {
int err = -ENOMEM;
mutex_lock(&iova_cache_mutex); mutex_lock(&iova_cache_mutex);
if (!iova_cache_users) { if (!iova_cache_users) {
int ret; iova_cache = kmem_cache_create("iommu_iova", sizeof(struct iova), 0,
SLAB_HWCACHE_ALIGN, NULL);
ret = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD, "iommu/iova:dead", NULL, if (!iova_cache)
iova_cpuhp_dead); goto out_err;
if (ret) {
mutex_unlock(&iova_cache_mutex);
pr_err("Couldn't register cpuhp handler\n");
return ret;
}
iova_cache = kmem_cache_create( err = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD, "iommu/iova:dead",
"iommu_iova", sizeof(struct iova), 0, NULL, iova_cpuhp_dead);
SLAB_HWCACHE_ALIGN, NULL); if (err) {
if (!iova_cache) { pr_err("IOVA: Couldn't register cpuhp handler: %pe\n", ERR_PTR(err));
cpuhp_remove_multi_state(CPUHP_IOMMU_IOVA_DEAD); goto out_err;
mutex_unlock(&iova_cache_mutex);
pr_err("Couldn't create iova cache\n");
return -ENOMEM;
} }
} }
...@@ -281,6 +275,11 @@ int iova_cache_get(void) ...@@ -281,6 +275,11 @@ int iova_cache_get(void)
mutex_unlock(&iova_cache_mutex); mutex_unlock(&iova_cache_mutex);
return 0; return 0;
out_err:
kmem_cache_destroy(iova_cache);
mutex_unlock(&iova_cache_mutex);
return err;
} }
EXPORT_SYMBOL_GPL(iova_cache_get); EXPORT_SYMBOL_GPL(iova_cache_get);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment