diff options
author | Kent Overstreet <koverstreet@google.com> | 2013-06-14 01:05:55 -0700 |
---|---|---|
committer | Kent Overstreet <koverstreet@google.com> | 2013-06-14 15:55:32 -0700 |
commit | c39e425262418e54739d0a4899d521fcd087210b (patch) | |
tree | 01caf765165ca11229b322ea4a6cd6fe87cc0b0b | |
parent | d683b96b072dc4680fc74964eca77e6a23d1fa6e (diff) |
convert code to ida_get()
42 files changed, 139 insertions, 378 deletions
diff --git a/arch/powerpc/mm/icswx_pid.c b/arch/powerpc/mm/icswx_pid.c index 91e30eb7d054..b80f877e644a 100644 --- a/arch/powerpc/mm/icswx_pid.c +++ b/arch/powerpc/mm/icswx_pid.c @@ -23,36 +23,11 @@ #define COP_PID_MIN (COP_PID_NONE + 1) #define COP_PID_MAX (0xFFFF) -static DEFINE_SPINLOCK(mmu_context_acop_lock); static DEFINE_IDA(cop_ida); -static int new_cop_pid(struct ida *ida, int min_id, int max_id, - spinlock_t *lock) +static int new_cop_pid(struct ida *ida) { - int index; - int err; - -again: - if (!ida_pre_get(ida, GFP_KERNEL)) - return -ENOMEM; - - spin_lock(lock); - err = ida_get_new_above(ida, min_id, &index); - spin_unlock(lock); - - if (err == -EAGAIN) - goto again; - else if (err) - return err; - - if (index > max_id) { - spin_lock(lock); - ida_remove(ida, index); - spin_unlock(lock); - return -ENOMEM; - } - - return index; + return ida_simple_get(ida, COP_PID_MIN, COP_PID_MAX, GFP_KERNEL); } int get_cop_pid(struct mm_struct *mm) @@ -60,8 +35,7 @@ int get_cop_pid(struct mm_struct *mm) int pid; if (mm->context.cop_pid == COP_PID_NONE) { - pid = new_cop_pid(&cop_ida, COP_PID_MIN, COP_PID_MAX, - &mmu_context_acop_lock); + pid = new_cop_pid(&cop_ida); if (pid >= 0) mm->context.cop_pid = pid; } @@ -81,7 +55,5 @@ int disable_cop_pid(struct mm_struct *mm) void free_cop_pid(int free_pid) { - spin_lock(&mmu_context_acop_lock); ida_remove(&cop_ida, free_pid); - spin_unlock(&mmu_context_acop_lock); } diff --git a/arch/powerpc/mm/mmu_context_hash64.c b/arch/powerpc/mm/mmu_context_hash64.c index 178876aef40f..2a544152e4fb 100644 --- a/arch/powerpc/mm/mmu_context_hash64.c +++ b/arch/powerpc/mm/mmu_context_hash64.c @@ -27,35 +27,11 @@ #include "icswx.h" -static DEFINE_SPINLOCK(mmu_context_lock); static DEFINE_IDA(mmu_context_ida); int __init_new_context(void) { - int index; - int err; - -again: - if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL)) - return -ENOMEM; - - spin_lock(&mmu_context_lock); - err = ida_get_new_above(&mmu_context_ida, 1, &index); - spin_unlock(&mmu_context_lock); - - if (err == -EAGAIN) - goto again; - else if (err) - return err; - - if (index > MAX_USER_CONTEXT) { - spin_lock(&mmu_context_lock); - ida_remove(&mmu_context_ida, index); - spin_unlock(&mmu_context_lock); - return -ENOMEM; - } - - return index; + return ida_simple_get(ida, 1, MAX_USER_CONTEXT, GFP_KERNEL); } EXPORT_SYMBOL_GPL(__init_new_context); @@ -94,9 +70,7 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm) void __destroy_context(int context_id) { - spin_lock(&mmu_context_lock); ida_remove(&mmu_context_ida, context_id); - spin_unlock(&mmu_context_lock); } EXPORT_SYMBOL_GPL(__destroy_context); diff --git a/block/blk-core.c b/block/blk-core.c index 33c33bc99ddd..470e34a31a6b 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -595,7 +595,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id) if (!q) return NULL; - q->id = ida_simple_get(&blk_queue_ida, 0, 0, gfp_mask); + q->id = ida_get(&blk_queue_ida, gfp_mask); if (q->id < 0) goto fail_q; @@ -650,7 +650,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id) return q; fail_id: - ida_simple_remove(&blk_queue_ida, q->id); + ida_remove(&blk_queue_ida, q->id); fail_q: kmem_cache_free(blk_requestq_cachep, q); return NULL; diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 5efc5a647183..8f6129f18c66 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -546,7 +546,7 @@ static void blk_release_queue(struct kobject *kobj) bdi_destroy(&q->backing_dev_info); - ida_simple_remove(&blk_queue_ida, q->id); + ida_remove(&blk_queue_ida, q->id); call_rcu(&q->rcu_head, blk_free_queue_rcu); } diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9eda84246ffd..684980908966 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -302,7 +302,7 @@ int platform_device_add(struct platform_device *pdev) * that we remember it must be freed, and we append a suffix * to avoid namespace collision with explicit IDs. */ - ret = ida_simple_get(&platform_devid_ida, 0, 0, GFP_KERNEL); + ret = ida_get(&platform_devid_ida, GFP_KERNEL); if (ret < 0) goto err_out; pdev->id = ret; @@ -341,7 +341,7 @@ int platform_device_add(struct platform_device *pdev) failed: if (pdev->id_auto) { - ida_simple_remove(&platform_devid_ida, pdev->id); + ida_remove(&platform_devid_ida, pdev->id); pdev->id = PLATFORM_DEVID_AUTO; } @@ -374,7 +374,7 @@ void platform_device_del(struct platform_device *pdev) device_del(&pdev->dev); if (pdev->id_auto) { - ida_simple_remove(&platform_devid_ida, pdev->id); + ida_remove(&platform_devid_ida, pdev->id); pdev->id = PLATFORM_DEVID_AUTO; } diff --git a/drivers/base/soc.c b/drivers/base/soc.c index 72b5e7280d14..4d10267ca0ac 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -16,7 +16,6 @@ #include <linux/err.h> static DEFINE_IDA(soc_ida); -static DEFINE_SPINLOCK(soc_lock); static ssize_t soc_info_get(struct device *dev, struct device_attribute *attr, @@ -121,22 +120,11 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr goto out1; } - /* Fetch a unique (reclaimable) SOC ID. */ - do { - if (!ida_pre_get(&soc_ida, GFP_KERNEL)) { - ret = -ENOMEM; - goto out2; - } - - spin_lock(&soc_lock); - ret = ida_get_new(&soc_ida, &soc_dev->soc_dev_num); - spin_unlock(&soc_lock); - - } while (ret == -EAGAIN); - + ret = ida_get(&soc_ida, GFP_KERNEL); if (ret) goto out2; + soc->dev->soc_dev_num = ret; soc_dev->attr = soc_dev_attr; soc_dev->dev.bus = &soc_bus_type; soc_dev->dev.groups = soc_attr_groups; diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c index 847107ef0cce..ef904afaf0e3 100644 --- a/drivers/block/mtip32xx/mtip32xx.c +++ b/drivers/block/mtip32xx/mtip32xx.c @@ -95,7 +95,6 @@ static struct dentry *dfs_device_status; static u32 cpu_use[NR_CPUS]; -static DEFINE_SPINLOCK(rssd_index_lock); static DEFINE_IDA(rssd_index_ida); static int mtip_block_initialize(struct driver_data *dd); @@ -3981,19 +3980,12 @@ static int mtip_block_initialize(struct driver_data *dd) goto alloc_disk_error; } - /* Generate the disk name, implemented same as in sd.c */ - do { - if (!ida_pre_get(&rssd_index_ida, GFP_KERNEL)) - goto ida_get_error; - - spin_lock(&rssd_index_lock); - rv = ida_get_new(&rssd_index_ida, &index); - spin_unlock(&rssd_index_lock); - } while (rv == -EAGAIN); - - if (rv) + rv = ida_get(&rssd_index_ida, GFP_KERNEL); + if (rv < 0) goto ida_get_error; + index = rv; + rv = rssd_disk_name_format("rssd", index, dd->disk->disk_name, @@ -4110,9 +4102,7 @@ read_capacity_error: block_queue_alloc_init_error: disk_index_error: - spin_lock(&rssd_index_lock); ida_remove(&rssd_index_ida, index); - spin_unlock(&rssd_index_lock); ida_get_error: put_disk(dd->disk); @@ -4165,9 +4155,7 @@ static int mtip_block_remove(struct driver_data *dd) put_disk(dd->disk); } - spin_lock(&rssd_index_lock); ida_remove(&rssd_index_ida, dd->index); - spin_unlock(&rssd_index_lock); blk_cleanup_queue(dd->queue); dd->disk = NULL; @@ -4207,9 +4195,7 @@ static int mtip_block_shutdown(struct driver_data *dd) dd->queue = NULL; } - spin_lock(&rssd_index_lock); ida_remove(&rssd_index_ida, dd->index); - spin_unlock(&rssd_index_lock); mtip_hw_shutdown(dd); return 0; diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c index 8efdfaa44a59..4f063d6d9423 100644 --- a/drivers/block/nvme-core.c +++ b/drivers/block/nvme-core.c @@ -1519,27 +1519,12 @@ static DEFINE_IDA(nvme_index_ida); static int nvme_get_ns_idx(void) { - int index, error; - - do { - if (!ida_pre_get(&nvme_index_ida, GFP_KERNEL)) - return -1; - - spin_lock(&dev_list_lock); - error = ida_get_new(&nvme_index_ida, &index); - spin_unlock(&dev_list_lock); - } while (error == -EAGAIN); - - if (error) - index = -1; - return index; + return ida_get(&nvme_index_ida, GFP_KERNEL); } static void nvme_put_ns_idx(int index) { - spin_lock(&dev_list_lock); ida_remove(&nvme_index_ida, index); - spin_unlock(&dev_list_lock); } static void nvme_config_discard(struct nvme_ns *ns) @@ -1821,18 +1806,10 @@ static DEFINE_IDA(nvme_instance_ida); static int nvme_set_instance(struct nvme_dev *dev) { - int instance, error; + int instance; - do { - if (!ida_pre_get(&nvme_instance_ida, GFP_KERNEL)) - return -ENODEV; - - spin_lock(&dev_list_lock); - error = ida_get_new(&nvme_instance_ida, &instance); - spin_unlock(&dev_list_lock); - } while (error == -EAGAIN); - - if (error) + instance = ida_get(&nvme_index_ida, GFP_KERNEL); + if (instance < 0) return -ENODEV; dev->instance = instance; @@ -1841,9 +1818,7 @@ static int nvme_set_instance(struct nvme_dev *dev) static void nvme_release_instance(struct nvme_dev *dev) { - spin_lock(&dev_list_lock); ida_remove(&nvme_instance_ida, dev->instance); - spin_unlock(&dev_list_lock); } static void nvme_free_dev(struct kref *kref) diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c index 5af21f2db29c..83af01989728 100644 --- a/drivers/block/rsxx/core.c +++ b/drivers/block/rsxx/core.c @@ -50,7 +50,6 @@ module_param(force_legacy, uint, 0444); MODULE_PARM_DESC(force_legacy, "Force the use of legacy type PCI interrupts"); static DEFINE_IDA(rsxx_disk_ida); -static DEFINE_SPINLOCK(rsxx_ida_lock); /*----------------- Interrupt Control & Handling -------------------*/ @@ -538,20 +537,12 @@ static int rsxx_pci_probe(struct pci_dev *dev, card->dev = dev; pci_set_drvdata(dev, card); - do { - if (!ida_pre_get(&rsxx_disk_ida, GFP_KERNEL)) { - st = -ENOMEM; - goto failed_ida_get; - } - - spin_lock(&rsxx_ida_lock); - st = ida_get_new(&rsxx_disk_ida, &card->disk_id); - spin_unlock(&rsxx_ida_lock); - } while (st == -EAGAIN); - - if (st) + st = ida_get(&rsxx_disk_ida, GFP_KERNEL); + if (st < 0) goto failed_ida_get; + card->disk_id = st; + st = pci_enable_device(dev); if (st) goto failed_enable; @@ -705,9 +696,7 @@ failed_request_regions: failed_dma_mask: pci_disable_device(dev); failed_enable: - spin_lock(&rsxx_ida_lock); ida_remove(&rsxx_disk_ida, card->disk_id); - spin_unlock(&rsxx_ida_lock); failed_ida_get: kfree(card); diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 64723953e1c9..5dbd5389ca85 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -864,7 +864,7 @@ out_free_vq: out_free_vblk: kfree(vblk); out_free_index: - ida_simple_remove(&vd_index_ida, index); + ida_remove(&vd_index_ida, index); out: return err; } @@ -896,7 +896,7 @@ static void virtblk_remove(struct virtio_device *vdev) /* Only free device id if we don't have any users */ if (refc == 1) - ida_simple_remove(&vd_index_ida, index); + ida_remove(&vd_index_ida, index); } #ifdef CONFIG_PM diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c index c5c054ae9056..aa6ef6f548f3 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c @@ -52,7 +52,6 @@ static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man, struct vmwgfx_gmrid_man *gman = (struct vmwgfx_gmrid_man *)man->priv; int ret = 0; - int id; mem->mm_node = NULL; @@ -64,34 +63,20 @@ static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man, goto out_err_locked; } - do { - spin_unlock(&gman->lock); - if (unlikely(ida_pre_get(&gman->gmr_ida, GFP_KERNEL) == 0)) { - ret = -ENOMEM; - goto out_err; - } - spin_lock(&gman->lock); + spin_unlock(&gman->lock); + ret = ida_simple_get(&gman->gmr_ida, 0, gman->max_gmr_ids, GFP_KERNEL); + spin_lock(&gman->lock); - ret = ida_get_new(&gman->gmr_ida, &id); - if (unlikely(ret == 0 && id >= gman->max_gmr_ids)) { - ida_remove(&gman->gmr_ida, id); - ret = 0; - goto out_err_locked; - } - } while (ret == -EAGAIN); - - if (likely(ret == 0)) { - mem->mm_node = gman; - mem->start = id; - mem->num_pages = bo->num_pages; - } else + if (ret < 0) goto out_err_locked; + mem->mm_node = gman; + mem->start = ret; + mem->num_pages = bo->num_pages; + spin_unlock(&gman->lock); return 0; -out_err: - spin_lock(&gman->lock); out_err_locked: gman->used_gmr_pages -= bo->num_pages; spin_unlock(&gman->lock); diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 646314f7c839..e4d032186319 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -43,7 +43,7 @@ struct device *hwmon_device_register(struct device *dev) struct device *hwdev; int id; - id = ida_simple_get(&hwmon_ida, 0, 0, GFP_KERNEL); + id = ida_get(&hwmon_ida, GFP_KERNEL); if (id < 0) return ERR_PTR(id); @@ -51,7 +51,7 @@ struct device *hwmon_device_register(struct device *dev) HWMON_ID_FORMAT, id); if (IS_ERR(hwdev)) - ida_simple_remove(&hwmon_ida, id); + ida_remove(&hwmon_ida, id); return hwdev; } @@ -68,7 +68,7 @@ void hwmon_device_unregister(struct device *dev) if (likely(sscanf(dev_name(dev), HWMON_ID_FORMAT, &id) == 1)) { device_unregister(dev); - ida_simple_remove(&hwmon_ida, id); + ida_remove(&hwmon_ida, id); } else dev_dbg(dev->parent, "hwmon_device_unregister() failed: bad class ID!\n"); diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c index 1429f6e177f4..0522c672b080 100644 --- a/drivers/hwmon/ibmaem.c +++ b/drivers/hwmon/ibmaem.c @@ -495,7 +495,7 @@ static void aem_delete(struct aem_data *data) ipmi_destroy_user(data->ipmi.user); platform_set_drvdata(data->pdev, NULL); platform_device_unregister(data->pdev); - ida_simple_remove(&aem_ida, data->id); + ida_remove(&aem_ida, data->id); kfree(data); } @@ -552,7 +552,7 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle) data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; /* Create sub-device for this fw instance */ - data->id = ida_simple_get(&aem_ida, 0, 0, GFP_KERNEL); + data->id = ida_get(&aem_ida, GFP_KERNEL); if (data->id < 0) goto id_err; @@ -613,7 +613,7 @@ ipmi_err: platform_set_drvdata(data->pdev, NULL); platform_device_unregister(data->pdev); dev_err: - ida_simple_remove(&aem_ida, data->id); + ida_remove(&aem_ida, data->id); id_err: kfree(data); @@ -692,7 +692,7 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe, data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; /* Create sub-device for this fw instance */ - data->id = ida_simple_get(&aem_ida, 0, 0, GFP_KERNEL); + data->id = ida_get(&aem_ida, GFP_KERNEL); if (data->id < 0) goto id_err; @@ -753,7 +753,7 @@ ipmi_err: platform_set_drvdata(data->pdev, NULL); platform_device_unregister(data->pdev); dev_err: - ida_simple_remove(&aem_ida, data->id); + ida_remove(&aem_ida, data->id); id_err: kfree(data); diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index e145931ef1b8..5cb3e618afed 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -856,7 +856,7 @@ static void iio_dev_release(struct device *device) iio_device_unregister_sysfs(indio_dev); iio_device_unregister_debugfs(indio_dev); - ida_simple_remove(&iio_ida, indio_dev->id); + ida_remove(&iio_ida, indio_dev->id); kfree(indio_dev); } @@ -890,7 +890,7 @@ struct iio_dev *iio_device_alloc(int sizeof_priv) mutex_init(&dev->info_exist_lock); INIT_LIST_HEAD(&dev->channel_attr_list); - dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL); + dev->id = ida_get(&iio_ida, GFP_KERNEL); if (dev->id < 0) { /* cannot use a dev_err as the name isn't available */ printk(KERN_ERR "Failed to get id\n"); diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 4d6c7d84e155..5a4e9eec0963 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -69,7 +69,7 @@ int iio_trigger_register(struct iio_trigger *trig_info) { int ret; - trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL); + trig_info->id = ida_get(&iio_trigger_ida, GFP_KERNEL); if (trig_info->id < 0) { ret = trig_info->id; goto error_ret; @@ -90,7 +90,7 @@ int iio_trigger_register(struct iio_trigger *trig_info) return 0; error_unregister_id: - ida_simple_remove(&iio_trigger_ida, trig_info->id); + ida_remove(&iio_trigger_ida, trig_info->id); error_ret: return ret; } @@ -102,7 +102,7 @@ void iio_trigger_unregister(struct iio_trigger *trig_info) list_del(&trig_info->list); mutex_unlock(&iio_trigger_list_lock); - ida_simple_remove(&iio_trigger_ida, trig_info->id); + ida_remove(&iio_trigger_ida, trig_info->id); /* Possible issue in here */ device_unregister(&trig_info->dev); } diff --git a/drivers/input/input.c b/drivers/input/input.c index c04469928925..982a82b72059 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -2352,7 +2352,7 @@ EXPORT_SYMBOL(input_get_new_minor); */ void input_free_minor(unsigned int minor) { - ida_simple_remove(&input_ida, minor); + ida_remove(&input_ida, minor); } EXPORT_SYMBOL(input_free_minor); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d8f98b14e2fe..e71153a5953b 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -32,7 +32,6 @@ static struct kset *iommu_group_kset; static struct ida iommu_group_ida; -static struct mutex iommu_group_mutex; struct iommu_group { struct kobject kobj; @@ -124,9 +123,7 @@ static void iommu_group_release(struct kobject *kobj) if (group->iommu_data_release) group->iommu_data_release(group->iommu_data); - mutex_lock(&iommu_group_mutex); ida_remove(&iommu_group_ida, group->id); - mutex_unlock(&iommu_group_mutex); kfree(group->name); kfree(group); @@ -163,26 +160,18 @@ struct iommu_group *iommu_group_alloc(void) INIT_LIST_HEAD(&group->devices); BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier); - mutex_lock(&iommu_group_mutex); - -again: - if (unlikely(0 == ida_pre_get(&iommu_group_ida, GFP_KERNEL))) { + ret = ida_get(&iommu_group_ida, GFP_KERNEL); + if (ret < 0) { kfree(group); - mutex_unlock(&iommu_group_mutex); return ERR_PTR(-ENOMEM); } - if (-EAGAIN == ida_get_new(&iommu_group_ida, &group->id)) - goto again; - - mutex_unlock(&iommu_group_mutex); + group->id = ret; ret = kobject_init_and_add(&group->kobj, &iommu_group_ktype, NULL, "%d", group->id); if (ret) { - mutex_lock(&iommu_group_mutex); ida_remove(&iommu_group_ida, group->id); - mutex_unlock(&iommu_group_mutex); kfree(group); return ERR_PTR(ret); } @@ -906,7 +895,6 @@ static int __init iommu_init(void) iommu_group_kset = kset_create_and_add("iommu_groups", NULL, kernel_kobj); ida_init(&iommu_group_ida); - mutex_init(&iommu_group_mutex); BUG_ON(!iommu_group_kset); diff --git a/drivers/ipack/ipack.c b/drivers/ipack/ipack.c index 6e066c53acce..3ac220323d1e 100644 --- a/drivers/ipack/ipack.c +++ b/drivers/ipack/ipack.c @@ -207,7 +207,7 @@ struct ipack_bus_device *ipack_bus_register(struct device *parent, int slots, if (!bus) return NULL; - bus_nr = ida_simple_get(&ipack_ida, 0, 0, GFP_KERNEL); + bus_nr = ida_get(&ipack_ida, GFP_KERNEL); if (bus_nr < 0) { kfree(bus); return NULL; @@ -236,7 +236,7 @@ int ipack_bus_unregister(struct ipack_bus_device *bus) { bus_for_each_dev(&ipack_bus_type, NULL, bus, ipack_unregister_bus_member); - ida_simple_remove(&ipack_ida, bus->bus_nr); + ida_remove(&ipack_ida, bus->bus_nr); kfree(bus); return 0; } diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c index 2e50f811ff59..cbaba07837e4 100644 --- a/drivers/misc/cb710/core.c +++ b/drivers/misc/cb710/core.c @@ -16,7 +16,6 @@ #include <linux/gfp.h> static DEFINE_IDA(cb710_ida); -static DEFINE_SPINLOCK(cb710_ida_lock); void cb710_pci_update_config_reg(struct pci_dev *pdev, int reg, uint32_t mask, uint32_t xor) @@ -205,7 +204,6 @@ static int cb710_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct cb710_chip *chip; - unsigned long flags; u32 val; int err; int n = 0; @@ -256,18 +254,11 @@ static int cb710_probe(struct pci_dev *pdev, if (err) return err; - do { - if (!ida_pre_get(&cb710_ida, GFP_KERNEL)) - return -ENOMEM; - - spin_lock_irqsave(&cb710_ida_lock, flags); - err = ida_get_new(&cb710_ida, &chip->platform_id); - spin_unlock_irqrestore(&cb710_ida_lock, flags); - - if (err && err != -EAGAIN) - return err; - } while (err); + err = ida_get(&cb710_ida, GFP_KERNEL); + if (err < 0) + return err; + chip->platform_id = err; dev_info(&pdev->dev, "id %d, IO 0x%p, IRQ %d\n", chip->platform_id, chip->iobase, pdev->irq); @@ -317,9 +308,7 @@ static void cb710_remove_one(struct pci_dev *pdev) BUG_ON(atomic_read(&chip->slot_refs_count) != 0); #endif - spin_lock_irqsave(&cb710_ida_lock, flags); ida_remove(&cb710_ida, chip->platform_id); - spin_unlock_irqrestore(&cb710_ida_lock, flags); } static const struct pci_device_id cb710_pci_tbl[] = { diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 4a8c388364ca..e5cf7b6c6d65 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -169,7 +169,7 @@ static void delete_ptp_clock(struct posix_clock *pc) struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); mutex_destroy(&ptp->tsevq_mux); - ida_simple_remove(&ptp_clocks_map, ptp->index); + ida_remove(&ptp_clocks_map, ptp->index); kfree(ptp); } diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 022dc635d01e..87740bbeb12a 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1223,7 +1223,7 @@ static void rproc_type_release(struct device *dev) idr_destroy(&rproc->notifyids); if (rproc->index >= 0) - ida_simple_remove(&rproc_dev_index, rproc->index); + ida_remove(&rproc_dev_index, rproc->index); kfree(rproc); } @@ -1301,9 +1301,9 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, rproc->dev.type = &rproc_type; /* Assign a unique device index and name */ - rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL); + rproc->index = ida_get(&rproc_dev_index, GFP_KERNEL); if (rproc->index < 0) { - dev_err(dev, "ida_simple_get failed: %d\n", rproc->index); + dev_err(dev, "ida_get failed: %d\n", rproc->index); put_device(&rproc->dev); return NULL; } diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 66385402d20e..632603d1a1e4 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -29,7 +29,7 @@ struct class *rtc_class; static void rtc_device_release(struct device *dev) { struct rtc_device *rtc = to_rtc_device(dev); - ida_simple_remove(&rtc_ida, rtc->id); + ida_remove(&rtc_ida, rtc->id); kfree(rtc); } @@ -158,7 +158,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, struct rtc_wkalrm alrm; int id, err; - id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); + id = ida_get(&rtc_ida, GFP_KERNEL); if (id < 0) { err = id; goto exit; @@ -226,7 +226,7 @@ exit_kfree: kfree(rtc); exit_ida: - ida_simple_remove(&rtc_ida, id); + ida_remove(&rtc_ida, id); exit: dev_err(dev, "rtc core: unable to register %s, err = %d\n", diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c index 0fab6b5c7b82..c9acbb263213 100644 --- a/drivers/scsi/osd/osd_uld.c +++ b/drivers/scsi/osd/osd_uld.c @@ -423,12 +423,9 @@ static int osd_probe(struct device *dev) if (scsi_device->type != TYPE_OSD) return -ENODEV; - do { - if (!ida_pre_get(&osd_minor_ida, GFP_KERNEL)) - return -ENODEV; - - error = ida_get_new(&osd_minor_ida, &minor); - } while (error == -EAGAIN); + minor = ida_get(&osd_minor_ida, GFP_KERNEL); + if (minor < 0) + return -ENODEV; if (error) return error; diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 133926b1bb78..857b1eb5d3b6 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -1686,7 +1686,7 @@ static void __iscsi_unbind_session(struct work_struct *work) mutex_unlock(&ihost->mutex); if (session->ida_used) - ida_simple_remove(&iscsi_sess_ida, target_id); + ida_remove(&iscsi_sess_ida, target_id); scsi_remove_target(&session->dev); iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION); @@ -1741,7 +1741,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) session->sid = atomic_add_return(1, &iscsi_session_nr); if (target_id == ISCSI_MAX_TARGET) { - id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL); + id = ida_get(&iscsi_sess_ida, GFP_KERNEL); if (id < 0) { iscsi_cls_session_printk(KERN_ERR, session, @@ -1772,7 +1772,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) release_ida: if (session->ida_used) - ida_simple_remove(&iscsi_sess_ida, session->target_id); + ida_remove(&iscsi_sess_ida, session->target_id); return err; } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c1c555242d0d..d86de093de7e 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -115,7 +115,6 @@ static void scsi_disk_release(struct device *cdev); static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); static void sd_print_result(struct scsi_disk *, int); -static DEFINE_SPINLOCK(sd_index_lock); static DEFINE_IDA(sd_index_ida); /* This semaphore is used to mediate the 0->1 reference get in the @@ -2893,17 +2892,9 @@ static int sd_probe(struct device *dev) if (!gd) goto out_free; - do { - if (!ida_pre_get(&sd_index_ida, GFP_KERNEL)) - goto out_put; - - spin_lock(&sd_index_lock); - error = ida_get_new(&sd_index_ida, &index); - spin_unlock(&sd_index_lock); - } while (error == -EAGAIN); - - if (error) { - sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n"); + index = ida_get(&sd_index_ida, GFP_KERNEL); + if (index < 0) { + error = index; goto out_put; } @@ -2945,9 +2936,7 @@ static int sd_probe(struct device *dev) return 0; out_free_index: - spin_lock(&sd_index_lock); ida_remove(&sd_index_ida, index); - spin_unlock(&sd_index_lock); out_put: put_disk(gd); out_free: @@ -3003,9 +2992,7 @@ static void scsi_disk_release(struct device *dev) struct scsi_disk *sdkp = to_scsi_disk(dev); struct gendisk *disk = sdkp->disk; - spin_lock(&sd_index_lock); ida_remove(&sd_index_ida, sdkp->index); - spin_unlock(&sd_index_lock); disk->private_data = NULL; put_disk(disk); diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 49b098bedf9b..0e0337d6d388 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -311,7 +311,7 @@ struct platform_device *ci13xxx_add_device(struct device *dev, struct platform_device *pdev; int id, ret; - id = ida_simple_get(&ci_ida, 0, 0, GFP_KERNEL); + id = ida_get(&ci_ida, GFP_KERNEL); if (id < 0) return ERR_PTR(id); @@ -343,7 +343,7 @@ struct platform_device *ci13xxx_add_device(struct device *dev, err: platform_device_put(pdev); put_id: - ida_simple_remove(&ci_ida, id); + ida_remove(&ci_ida, id); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(ci13xxx_add_device); @@ -352,7 +352,7 @@ void ci13xxx_remove_device(struct platform_device *pdev) { int id = pdev->id; platform_device_unregister(pdev); - ida_simple_remove(&ci_ida, id); + ida_remove(&ci_ida, id); } EXPORT_SYMBOL_GPL(ci13xxx_remove_device); diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index ee59b74768d9..96688f82ab23 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -193,7 +193,7 @@ int register_virtio_device(struct virtio_device *dev) dev->dev.bus = &virtio_bus; /* Assign a unique device index and hence name. */ - err = ida_simple_get(&virtio_index_ida, 0, 0, GFP_KERNEL); + err = ida_get(&virtio_index_ida, GFP_KERNEL); if (err < 0) goto out; @@ -224,7 +224,7 @@ void unregister_virtio_device(struct virtio_device *dev) int index = dev->index; /* save for after device release */ device_unregister(&dev->dev); - ida_simple_remove(&virtio_index_ida, index); + ida_remove(&virtio_index_ida, index); } EXPORT_SYMBOL_GPL(unregister_virtio_device); diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c index e86a69dc411e..964fd9c09839 100644 --- a/drivers/w1/slaves/w1_ds2760.c +++ b/drivers/w1/slaves/w1_ds2760.c @@ -122,7 +122,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) int id; struct platform_device *pdev; - id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); + id = ida_get(&bat_ida, GFP_KERNEL); if (id < 0) { ret = id; goto noid; @@ -152,7 +152,7 @@ bin_attr_failed: pdev_add_failed: platform_device_put(pdev); pdev_alloc_failed: - ida_simple_remove(&bat_ida, id); + ida_remove(&bat_ida, id); noid: success: return ret; @@ -164,7 +164,7 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl) int id = pdev->id; platform_device_unregister(pdev); - ida_simple_remove(&bat_ida, id); + ida_remove(&bat_ida, id); sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr); } diff --git a/drivers/w1/slaves/w1_ds2780.c b/drivers/w1/slaves/w1_ds2780.c index 98ed9c49cf50..abc520944faa 100644 --- a/drivers/w1/slaves/w1_ds2780.c +++ b/drivers/w1/slaves/w1_ds2780.c @@ -115,7 +115,7 @@ static int w1_ds2780_add_slave(struct w1_slave *sl) int id; struct platform_device *pdev; - id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); + id = ida_get(&bat_ida, GFP_KERNEL); if (id < 0) { ret = id; goto noid; @@ -145,7 +145,7 @@ bin_attr_failed: pdev_add_failed: platform_device_put(pdev); pdev_alloc_failed: - ida_simple_remove(&bat_ida, id); + ida_remove(&bat_ida, id); noid: return ret; } @@ -156,7 +156,7 @@ static void w1_ds2780_remove_slave(struct w1_slave *sl) int id = pdev->id; platform_device_unregister(pdev); - ida_simple_remove(&bat_ida, id); + ida_remove(&bat_ida, id); sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr); } diff --git a/drivers/w1/slaves/w1_ds2781.c b/drivers/w1/slaves/w1_ds2781.c index 5140d7be67ab..62088e80b22a 100644 --- a/drivers/w1/slaves/w1_ds2781.c +++ b/drivers/w1/slaves/w1_ds2781.c @@ -113,7 +113,7 @@ static int w1_ds2781_add_slave(struct w1_slave *sl) int id; struct platform_device *pdev; - id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); + id = ida_get(&bat_ida, GFP_KERNEL); if (id < 0) { ret = id; goto noid; @@ -143,7 +143,7 @@ bin_attr_failed: pdev_add_failed: platform_device_put(pdev); pdev_alloc_failed: - ida_simple_remove(&bat_ida, id); + ida_remove(&bat_ida, id); noid: return ret; } @@ -154,7 +154,7 @@ static void w1_ds2781_remove_slave(struct w1_slave *sl) int id = pdev->id; platform_device_unregister(pdev); - ida_simple_remove(&bat_ida, id); + ida_remove(&bat_ida, id); sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2781_bin_attr); } diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c index 05d18b4c661b..66199f271609 100644 --- a/drivers/watchdog/watchdog_core.c +++ b/drivers/watchdog/watchdog_core.c @@ -135,7 +135,7 @@ int watchdog_register_device(struct watchdog_device *wdd) ret = watchdog_dev_register(wdd); if (ret) { - ida_simple_remove(&watchdog_ida, id); + ida_remove(&watchdog_ida, id); if (!(id == 0 && ret == -EBUSY)) return ret; @@ -147,7 +147,7 @@ int watchdog_register_device(struct watchdog_device *wdd) ret = watchdog_dev_register(wdd); if (ret) { - ida_simple_remove(&watchdog_ida, id); + ida_remove(&watchdog_ida, id); return ret; } } @@ -157,7 +157,7 @@ int watchdog_register_device(struct watchdog_device *wdd) NULL, "watchdog%d", wdd->id); if (IS_ERR(wdd->dev)) { watchdog_dev_unregister(wdd); - ida_simple_remove(&watchdog_ida, id); + ida_remove(&watchdog_ida, id); ret = PTR_ERR(wdd->dev); return ret; } @@ -186,7 +186,7 @@ void watchdog_unregister_device(struct watchdog_device *wdd) if (ret) pr_err("error unregistering /dev/watchdog (err=%d)\n", ret); device_destroy(watchdog_class, devno); - ida_simple_remove(&watchdog_ida, wdd->id); + ida_remove(&watchdog_ida, wdd->id); wdd->dev = NULL; } EXPORT_SYMBOL_GPL(watchdog_unregister_device); diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 073d30b9d1ac..c85f365c13af 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -521,32 +521,20 @@ int devpts_new_index(struct inode *ptmx_inode) struct super_block *sb = pts_sb_from_inode(ptmx_inode); struct pts_fs_info *fsi = DEVPTS_SB(sb); int index; - int ida_ret; -retry: - if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL)) - return -ENOMEM; + index = ida_simple_get(&fsi->allocated_ptys, 0, + fsi->mount_opts.max, GFP_KERNEL); + if (index < 0) + return index; mutex_lock(&allocated_ptys_lock); if (pty_count >= pty_limit - (fsi->mount_opts.newinstance ? pty_reserve : 0)) { mutex_unlock(&allocated_ptys_lock); - return -ENOSPC; - } - - ida_ret = ida_get_new(&fsi->allocated_ptys, &index); - if (ida_ret < 0) { - mutex_unlock(&allocated_ptys_lock); - if (ida_ret == -EAGAIN) - goto retry; - return -EIO; - } - - if (index >= fsi->mount_opts.max) { ida_remove(&fsi->allocated_ptys, index); - mutex_unlock(&allocated_ptys_lock); return -ENOSPC; } + pty_count++; mutex_unlock(&allocated_ptys_lock); return index; @@ -557,8 +545,8 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx) struct super_block *sb = pts_sb_from_inode(ptmx_inode); struct pts_fs_info *fsi = DEVPTS_SB(sb); - mutex_lock(&allocated_ptys_lock); ida_remove(&fsi->allocated_ptys, idx); + mutex_lock(&allocated_ptys_lock); pty_count--; mutex_unlock(&allocated_ptys_lock); } diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 1fab140764c4..2eee60f85eb3 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -865,7 +865,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f default: goto out_free; } - lsp->ls_seqid.owner_id = ida_simple_get(&server->lockowner_id, 0, 0, GFP_NOFS); + lsp->ls_seqid.owner_id = ida_get(&server->lockowner_id, GFP_NOFS); if (lsp->ls_seqid.owner_id < 0) goto out_free; INIT_LIST_HEAD(&lsp->ls_locks); @@ -877,7 +877,7 @@ out_free: void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp) { - ida_simple_remove(&server->lockowner_id, lsp->ls_seqid.owner_id); + ida_remove(&server->lockowner_id, lsp->ls_seqid.owner_id); nfs4_destroy_seqid_counter(&lsp->ls_seqid); kfree(lsp); } diff --git a/fs/proc/generic.c b/fs/proc/generic.c index a2596afffae6..3d5e78e06f9a 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -120,7 +120,6 @@ static int xlate_proc_name(const char *name, struct proc_dir_entry **ret, } static DEFINE_IDA(proc_inum_ida); -static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */ #define PROC_DYNAMIC_FIRST 0xF0000000U @@ -130,37 +129,19 @@ static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */ */ int proc_alloc_inum(unsigned int *inum) { - unsigned int i; - int error; - -retry: - if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL)) - return -ENOMEM; + int i = ida_simple_get(&proc_inum_ida, 0, + UINT_MAX - PROC_DYNAMIC_FIRST, + GFP_KERNEL); + if (i < 0) + return i; - spin_lock_irq(&proc_inum_lock); - error = ida_get_new(&proc_inum_ida, &i); - spin_unlock_irq(&proc_inum_lock); - if (error == -EAGAIN) - goto retry; - else if (error) - return error; - - if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { - spin_lock_irq(&proc_inum_lock); - ida_remove(&proc_inum_ida, i); - spin_unlock_irq(&proc_inum_lock); - return -ENOSPC; - } *inum = PROC_DYNAMIC_FIRST + i; return 0; } void proc_free_inum(unsigned int inum) { - unsigned long flags; - spin_lock_irqsave(&proc_inum_lock, flags); ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); - spin_unlock_irqrestore(&proc_inum_lock, flags); } static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd) diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index e8e0e71b29d5..4bb747eb2b64 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -30,7 +30,6 @@ DEFINE_SPINLOCK(sysfs_assoc_lock); #define to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb); -static DEFINE_SPINLOCK(sysfs_ino_lock); static DEFINE_IDA(sysfs_ino_ida); /** @@ -234,28 +233,12 @@ static void sysfs_deactivate(struct sysfs_dirent *sd) static int sysfs_alloc_ino(unsigned int *pino) { - int ino, rc; - - retry: - spin_lock(&sysfs_ino_lock); - rc = ida_get_new_above(&sysfs_ino_ida, 2, &ino); - spin_unlock(&sysfs_ino_lock); - - if (rc == -EAGAIN) { - if (ida_pre_get(&sysfs_ino_ida, GFP_KERNEL)) - goto retry; - rc = -ENOMEM; - } - - *pino = ino; - return rc; + return ida_simple_get(&sysfs_ino_ida, 2, 0, GFP_KERNEL); } static void sysfs_free_ino(unsigned int ino) { - spin_lock(&sysfs_ino_lock); ida_remove(&sysfs_ino_ida, ino); - spin_unlock(&sysfs_ino_lock); } void release_sysfs_dirent(struct sysfs_dirent * sd) diff --git a/include/linux/idr.h b/include/linux/idr.h index 871a213a8477..15b0d293c6d7 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -221,13 +221,12 @@ struct ida { int ida_pre_get(struct ida *ida, gfp_t gfp_mask); int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); -void ida_remove(struct ida *ida, int id); +void ida_remove(struct ida *ida, unsigned id); void ida_destroy(struct ida *ida); void ida_init(struct ida *ida); int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, gfp_t gfp_mask); -void ida_simple_remove(struct ida *ida, unsigned int id); /** * ida_get_new - allocate new ID @@ -241,6 +240,11 @@ static inline int ida_get_new(struct ida *ida, int *p_id) return ida_get_new_above(ida, 0, p_id); } +static inline int ida_get(struct ida *ida, gfp_t gfp_mask) +{ + return ida_simple_get(ida, 0, 0, gfp_mask); +} + void __init idr_init_cache(void); #endif /* __IDR_H__ */ diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 2a9926275f80..139bb88efd94 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -191,7 +191,6 @@ static int root_count; static DEFINE_IDA(hierarchy_ida); static int next_hierarchy_id; -static DEFINE_SPINLOCK(hierarchy_id_lock); /* dummytop is a shorthand for the dummy hierarchy's top cgroup */ #define dummytop (&rootnode.top_cgroup) @@ -848,7 +847,7 @@ static void cgroup_free_fn(struct work_struct *work) */ dput(cgrp->parent->dentry); - ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id); + ida_remove(&cgrp->root->cgroup_ida, cgrp->id); /* * Drop the active superblock reference that we took when we @@ -1430,24 +1429,13 @@ static bool init_root_id(struct cgroupfs_root *root) { int ret = 0; - do { - if (!ida_pre_get(&hierarchy_ida, GFP_KERNEL)) - return false; - spin_lock(&hierarchy_id_lock); - /* Try to allocate the next unused ID */ - ret = ida_get_new_above(&hierarchy_ida, next_hierarchy_id, - &root->hierarchy_id); - if (ret == -ENOSPC) - /* Try again starting from 0 */ - ret = ida_get_new(&hierarchy_ida, &root->hierarchy_id); - if (!ret) { - next_hierarchy_id = root->hierarchy_id + 1; - } else if (ret != -EAGAIN) { - /* Can only get here if the 31-bit IDR is full ... */ - BUG_ON(ret); - } - spin_unlock(&hierarchy_id_lock); - } while (ret); + ret = ida_simple_get(&hierarchy_ida, next_hierarchy_id, 0, GFP_KERNEL); + if (ret < 0) + return false; + + root->hierarchy_id = ret; + next_hierarchy_id = root->hierarchy_id + 1; + return true; } @@ -1506,9 +1494,7 @@ static void cgroup_drop_root(struct cgroupfs_root *root) return; BUG_ON(!root->hierarchy_id); - spin_lock(&hierarchy_id_lock); ida_remove(&hierarchy_ida, root->hierarchy_id); - spin_unlock(&hierarchy_id_lock); ida_destroy(&root->cgroup_ida); kfree(root); } @@ -4228,7 +4214,7 @@ err_free_all: /* Release the reference count that we took on the superblock */ deactivate_super(sb); err_free_id: - ida_simple_remove(&root->cgroup_ida, cgrp->id); + ida_remove(&root->cgroup_ida, cgrp->id); err_free_name: kfree(rcu_dereference_raw(cgrp->name)); err_free_cgrp: diff --git a/lib/idr.c b/lib/idr.c index cca4b9302a71..b4e95f793c9f 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -1021,12 +1021,7 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) } EXPORT_SYMBOL(ida_get_new_above); -/** - * ida_remove - remove the given ID - * @ida: ida handle - * @id: ID to free - */ -void ida_remove(struct ida *ida, int id) +static void __ida_remove(struct ida *ida, int id) { struct idr_layer *p = ida->idr.top; int shift = (ida->idr.layers - 1) * IDR_BITS; @@ -1067,7 +1062,6 @@ void ida_remove(struct ida *ida, int id) printk(KERN_WARNING "ida_remove called for id=%d which is not allocated.\n", id); } -EXPORT_SYMBOL(ida_remove); /** * ida_destroy - release all cached layers within an ida tree @@ -1090,7 +1084,7 @@ EXPORT_SYMBOL(ida_destroy); * Allocates an id in the range start <= id < end, or returns -ENOSPC. * On memory allocation failure, returns -ENOMEM. * - * Use ida_simple_remove() to get rid of an id. + * Use ida_remove() to get rid of an id. */ int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, gfp_t gfp_mask) @@ -1117,7 +1111,7 @@ again: ret = ida_get_new_above(ida, start, &id); if (!ret) { if (id > max) { - ida_remove(ida, id); + __ida_remove(ida, id); ret = -ENOSPC; } else { ret = id; @@ -1133,20 +1127,20 @@ again: EXPORT_SYMBOL(ida_simple_get); /** - * ida_simple_remove - remove an allocated id. + * ida_remove - remove an allocated id. * @ida: the (initialized) ida. * @id: the id returned by ida_simple_get. */ -void ida_simple_remove(struct ida *ida, unsigned int id) +void ida_remove(struct ida *ida, unsigned int id) { unsigned long flags; BUG_ON((int)id < 0); spin_lock_irqsave(&simple_ida_lock, flags); - ida_remove(ida, id); + __ida_remove(ida, id); spin_unlock_irqrestore(&simple_ida_lock, flags); } -EXPORT_SYMBOL(ida_simple_remove); +EXPORT_SYMBOL(ida_remove); /** * ida_init - initialize ida handle diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 010d6c14129a..8d8b6658ca08 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -657,7 +657,7 @@ static void disarm_kmem_keys(struct mem_cgroup *memcg) { if (memcg_kmem_is_active(memcg)) { static_key_slow_dec(&memcg_kmem_enabled_key); - ida_simple_remove(&kmem_limited_groups, memcg->kmemcg_id); + ida_remove(&kmem_limited_groups, memcg->kmemcg_id); } /* * This check can't live in kmem destruction function, @@ -3083,7 +3083,7 @@ int memcg_update_cache_sizes(struct mem_cgroup *memcg) ret = memcg_update_all_caches(num+1); if (ret) { - ida_simple_remove(&kmem_limited_groups, num); + ida_remove(&kmem_limited_groups, num); memcg_kmem_clear_activated(memcg); return ret; } diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 33843c5c4939..b96e38f53bda 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2181,7 +2181,7 @@ int hci_register_dev(struct hci_dev *hdev) */ switch (hdev->dev_type) { case HCI_BREDR: - id = ida_simple_get(&hci_index_ida, 0, 0, GFP_KERNEL); + id = ida_get(&hci_index_ida, GFP_KERNEL); break; case HCI_AMP: id = ida_simple_get(&hci_index_ida, 1, 0, GFP_KERNEL); @@ -2248,7 +2248,7 @@ err_wqueue: destroy_workqueue(hdev->workqueue); destroy_workqueue(hdev->req_workqueue); err: - ida_simple_remove(&hci_index_ida, hdev->id); + ida_remove(&hci_index_ida, hdev->id); write_lock(&hci_dev_list_lock); list_del(&hdev->list); write_unlock(&hci_dev_list_lock); @@ -2312,7 +2312,7 @@ void hci_unregister_dev(struct hci_dev *hdev) hci_dev_put(hdev); - ida_simple_remove(&hci_index_ida, id); + ida_remove(&hci_index_ida, id); } EXPORT_SYMBOL(hci_unregister_dev); diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index f97652036754..899a976cafdd 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -500,15 +500,11 @@ static int register_pernet_operations(struct list_head *list, int error; if (ops->id) { -again: - error = ida_get_new_above(&net_generic_ids, 1, ops->id); - if (error < 0) { - if (error == -EAGAIN) { - ida_pre_get(&net_generic_ids, GFP_KERNEL); - goto again; - } - return error; - } + int id = ida_simple_get(&net_generic_ids, 1, 0, GFP_KERNEL); + if (id < 0) + return id; + + *ops->id = id; max_gen_ptrs = max_t(unsigned int, max_gen_ptrs, *ops->id); } error = __register_pernet_operations(list, ops); @@ -523,7 +519,6 @@ again: static void unregister_pernet_operations(struct pernet_operations *ops) { - __unregister_pernet_operations(ops); rcu_barrier(); if (ops->id) diff --git a/net/nfc/core.c b/net/nfc/core.c index 40d2527693da..a8fb4e851125 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c @@ -839,7 +839,7 @@ int nfc_register_device(struct nfc_dev *dev) pr_debug("dev_name=%s\n", dev_name(&dev->dev)); - dev->idx = ida_simple_get(&nfc_index_ida, 0, 0, GFP_KERNEL); + dev->idx = ida_get(&nfc_index_ida, GFP_KERNEL); if (dev->idx < 0) return dev->idx; @@ -915,7 +915,7 @@ void nfc_unregister_device(struct nfc_dev *dev) device_del(&dev->dev); mutex_unlock(&nfc_devlist_mutex); - ida_simple_remove(&nfc_index_ida, id); + ida_remove(&nfc_index_ida, id); } EXPORT_SYMBOL(nfc_unregister_device); |