Commit feccf398 authored by Heiner Kallweit's avatar Heiner Kallweit Committed by Joerg Roedel

iommu: Simplify and fix ida handling

Ida handling can be much simplified by using the ida_simple_.. functions.

This change also fixes the bug that previously checking for errors
returned by ida_get_new() was incomplete.
ida_get_new() can return errors other than EAGAIN, e.g. ENOSPC.
This case wasn't handled.
Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent e38d1f13
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
static struct kset *iommu_group_kset; static struct kset *iommu_group_kset;
static DEFINE_IDA(iommu_group_ida); static DEFINE_IDA(iommu_group_ida);
static DEFINE_MUTEX(iommu_group_mutex);
struct iommu_callback_data { struct iommu_callback_data {
const struct iommu_ops *ops; const struct iommu_ops *ops;
...@@ -144,9 +143,7 @@ static void iommu_group_release(struct kobject *kobj) ...@@ -144,9 +143,7 @@ static void iommu_group_release(struct kobject *kobj)
if (group->iommu_data_release) if (group->iommu_data_release)
group->iommu_data_release(group->iommu_data); group->iommu_data_release(group->iommu_data);
mutex_lock(&iommu_group_mutex); ida_simple_remove(&iommu_group_ida, group->id);
ida_remove(&iommu_group_ida, group->id);
mutex_unlock(&iommu_group_mutex);
if (group->default_domain) if (group->default_domain)
iommu_domain_free(group->default_domain); iommu_domain_free(group->default_domain);
...@@ -186,26 +183,17 @@ struct iommu_group *iommu_group_alloc(void) ...@@ -186,26 +183,17 @@ struct iommu_group *iommu_group_alloc(void)
INIT_LIST_HEAD(&group->devices); INIT_LIST_HEAD(&group->devices);
BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier); BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier);
mutex_lock(&iommu_group_mutex); ret = ida_simple_get(&iommu_group_ida, 0, 0, GFP_KERNEL);
if (ret < 0) {
again:
if (unlikely(0 == ida_pre_get(&iommu_group_ida, GFP_KERNEL))) {
kfree(group); kfree(group);
mutex_unlock(&iommu_group_mutex); return ERR_PTR(ret);
return ERR_PTR(-ENOMEM);
} }
group->id = ret;
if (-EAGAIN == ida_get_new(&iommu_group_ida, &group->id))
goto again;
mutex_unlock(&iommu_group_mutex);
ret = kobject_init_and_add(&group->kobj, &iommu_group_ktype, ret = kobject_init_and_add(&group->kobj, &iommu_group_ktype,
NULL, "%d", group->id); NULL, "%d", group->id);
if (ret) { if (ret) {
mutex_lock(&iommu_group_mutex); ida_simple_remove(&iommu_group_ida, group->id);
ida_remove(&iommu_group_ida, group->id);
mutex_unlock(&iommu_group_mutex);
kfree(group); kfree(group);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
......
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