* [PATCH 00/17] Create and use ida and idr helper routines
@ 2015-09-15 16:46 Lee Duncan
2015-09-15 16:46 ` [PATCH 01/17] Add " Lee Duncan
` (16 more replies)
0 siblings, 17 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Kai.Makisara, Mike Snitzer, Doug Ledford, Ulf Hansson,
Gerd Hoffmann, Samuel Ortiz, Alex Dubov, Joshua Morris,
Matthew Wilcox
The idr index management library supplies two sets of routines
for managing monotonically increasing index numbers. The "ida"
set of routines manage allocating and freeing simple index
numbers. The "idr" set of routines add the ability to save
an arbitrary pointer with each index.
Both sets of routines are used throughout the kernel, and it
was noted that many of them use the same or similar calling
sequences, making a helper function a useful addition.
This set of patches adds some helper functions, defined
as inline in <linux/idr.h>. In addition, any of the clients
of these idr library functions that could benefit from
using these helper functions where modified to use them.
In addition to cleaning up the code in the clients of these
functions, the SCSI hosts module, which used to use a simple
atomic integer for index management is converted to using
the idr set of routines to manage its index values as
well as to simplify and speed up host number to instance
lookups.
I have functionally tested the SCSI host indexing change,
and I have compile tested all of the other changes. The
maintainers of each driver are cc-ed on the patch series,
where available.
Note: I did not mark this patch series as "v2" since
the scope of the patch set has grown considerably
since my first submissions.
Summary: There is one patch that adds helper functions, 11
patches that use the new "idr" helper functions, and 5 that
use the new "ida" helper functions.
Lee Duncan (17):
1. Add ida and idr helper routines.
2. Update scsi hosts to use idr for host number mgmt
3. Update the st driver to use idr helper functions.
4. Update the ch driver to use idr helper functions.
5. Update the md driver to use idr helper functions.
6. Update the infiniband uverbs driver to use idr helper functions.
7. Update the memstick driver to use idr helper functions.
8. Update the mmc driver to use idr helper functions.
9. Update the virtgpu driver to use idr helper functions.
10. Update the DCA DMA driver to use idr helper functions.
11. Update the rtsx multifunction driver to use idr helper functions.
12. Update the TI Flash Media driver to use idr helper functions.
13. Update the SCSI disk driver to use ida helper functions.
14. Update the rsxx flash adapter driver to use ida helper functions.
15. Update the NVMe SSD driver to use ida helper functions.
16. Update the Micron PCIe SSD driver to use ida helper functions.
17. Update the ARM soc base driver to use ida helper functions.
drivers/base/soc.c | 17 ++----
drivers/block/mtip32xx/mtip32xx.c | 22 ++------
drivers/block/nvme-core.c | 14 +----
drivers/block/rsxx/core.c | 16 +-----
drivers/dca/dca-sysfs.c | 19 ++-----
drivers/gpu/drm/virtio/virtgpu_vq.c | 15 ++----
drivers/infiniband/core/uverbs_cmd.c | 12 +----
drivers/md/dm.c | 22 ++------
drivers/memstick/core/memstick.c | 19 ++-----
drivers/mfd/rtsx_pcr.c | 13 ++---
drivers/misc/tifm_core.c | 17 ++----
drivers/mmc/core/host.c | 14 ++---
drivers/scsi/ch.c | 14 ++---
drivers/scsi/hosts.c | 59 ++++++++++----------
drivers/scsi/sd.c | 20 ++-----
drivers/scsi/st.c | 15 ++----
include/linux/idr.h | 102 +++++++++++++++++++++++++++++++++++
17 files changed, 182 insertions(+), 228 deletions(-)
--
2.1.4
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 01/17] Add ida and idr helper routines.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 18:20 ` James Bottomley
2015-09-15 18:27 ` Tejun Heo
2015-09-15 16:46 ` [PATCH 02/17] Update scsi hosts to use idr for host number mgmt Lee Duncan
` (15 subsequent siblings)
16 siblings, 2 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Clients of the ida and idr index-management routines
tend to use the same calling sequences much of the time,
so this change adds helper functions for allocating and
releasing indexes of either flavor, i.e. with or
without pointer management.
Inline functions added for idr:
idr_get_index_in_range
idr_get_index (in range 0,0)
idr_put_index
And for ida:
ida_get_index
ida_put_index
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
include/linux/idr.h | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 013fd9bc4cb6..341c4f2d9874 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -16,6 +16,8 @@
#include <linux/bitops.h>
#include <linux/init.h>
#include <linux/rcupdate.h>
+#include <linux/spinlock.h>
+#include <linux/gfp.h>
/*
* We want shallower trees and thus more bits covered at each layer. 8
@@ -183,4 +185,104 @@ static inline int ida_get_new(struct ida *ida, int *p_id)
void __init idr_init_cache(void);
+/**
+ * ida_get_index - allocate a ida index value
+ * @ida idr handle
+ * @lock spinlock handle protecting this index
+ * @p_id pointer to allocated index value
+ *
+ * A helper function for safely allocating an index value (id),
+ * returning a negative errno value on failure, else 0.
+ */
+static inline int ida_get_index(struct ida *ida, spinlock_t *lock, int *p_id)
+{
+ int error = -ENOMEM;
+
+ do {
+ if (!ida_pre_get(ida, GFP_KERNEL))
+ break;
+ spin_lock(lock);
+ error = ida_get_new(ida, p_id);
+ spin_unlock(lock);
+ } while (error == -EAGAIN);
+
+ return error;
+}
+
+/**
+ * ida_put_index - free an allocated ida index value
+ * @ida idr handle
+ * @lock spinlock handle protecting this index
+ * @id the value of the allocated index
+ *
+ * A helper function that goes with @ida_get_index, which safely
+ * frees a previously-allocated index value.
+ */
+static inline void ida_put_index(struct ida *ida, spinlock_t *lock, int id)
+{
+ spin_lock(lock);
+ ida_remove(ida, id);
+ spin_unlock(lock);
+}
+
+/**
+ * idr_get_index_in_range - allocate a new index, with locking
+ * within a range
+ * @idr: idr handle
+ * @lock: spin lock handle protecting the index
+ * @ptr: pointer to associate with allocated index
+ * @start: starting index (see idr_alloc)
+ * @end: ending index (0 -> use default max)
+ *
+ * This is a helper routine meant to make the common
+ * calling sequence to allocate an idr index easier.
+ * It uses a spin lock, and allocates a positive index
+ * in the range of [start,end), returning a negative
+ * errno on failure, else 0.
+ */
+static inline int idr_get_index_in_range(struct idr *idr, spinlock_t *lock,
+ void *ptr, int start, int end)
+{
+ int ret;
+
+ idr_preload(GFP_KERNEL);
+ spin_lock(lock);
+ ret = idr_alloc(idr, ptr, start, end, GFP_NOWAIT);
+ spin_unlock(lock);
+ idr_preload_end();
+
+ return ret;
+}
+
+/**
+ * idr_get_index - allocate new index, with locking, using the
+ * default range (zero to max-1)
+ * @idr: idr handle
+ * @lock: spin lock handle protecting the index
+ * @ptr: pointer to associate with allocated index
+ *
+ * Simple wrapper around idr_get_index_in_range() w/ @start and
+ * @end of 0, since this is a common case
+ */
+static inline int idr_get_index(struct idr *idr, spinlock_t *lock, void *ptr)
+{
+ return idr_get_index_in_range(idr, lock, ptr, 0, 0);
+}
+
+/**
+ * idr_put_index - free an allocated idr index value
+ * @idr idr handle
+ * @lock spinlock handle protecting this index
+ * @id the value of the allocated index
+ *
+ * A helper function that goes with @idr_get_index, which safely
+ * frees a previously-allocated index value.
+ */
+static inline void idr_put_index(struct idr *idr, spinlock_t *lock, int id)
+{
+ spin_lock(lock);
+ idr_remove(idr, id);
+ spin_unlock(lock);
+}
+
#endif /* __IDR_H__ */
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 02/17] Update scsi hosts to use idr for host number mgmt
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
2015-09-15 16:46 ` [PATCH 01/17] Add " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 03/17] Update the st driver to use idr helper functions Lee Duncan
` (14 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Each Scsi_Host instance gets a host number starting
at 0, but this was implemented with an atomic integer,
and rollover wasn't considered. Another problem with
this design is that scsi host numbers used by iscsi
are never reused, thereby making rollover more likely.
This patch converts Scsi_Host instances to use idr
to manage their instance numbers and to simplify
instance number to pointer lookups.
This also means that host instance numbers will be
reused, when available.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/hosts.c | 59 ++++++++++++++++++++++++----------------------------
1 file changed, 27 insertions(+), 32 deletions(-)
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 8bb173e01084..61201bc03b98 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -33,7 +33,7 @@
#include <linux/transport_class.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
-
+#include <linux/idr.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_transport.h>
@@ -42,8 +42,6 @@
#include "scsi_logging.h"
-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
-
static void scsi_host_cls_release(struct device *dev)
{
@@ -304,6 +302,19 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
}
EXPORT_SYMBOL(scsi_add_host_with_dma);
+static DEFINE_SPINLOCK(host_index_lock);
+static DEFINE_IDR(host_index_idr);
+
+static inline int host_get_index(void *ptr)
+{
+ return idr_get_index(&host_index_idr, &host_index_lock, ptr);
+}
+
+static inline void host_put_index(int index)
+{
+ idr_put_index(&host_index_idr, &host_index_lock, index);
+}
+
static void scsi_host_dev_release(struct device *dev)
{
struct Scsi_Host *shost = dev_to_shost(dev);
@@ -337,6 +348,8 @@ static void scsi_host_dev_release(struct device *dev)
kfree(shost->shost_data);
+ host_put_index(shost->host_no);
+
if (parent)
put_device(parent);
kfree(shost);
@@ -370,6 +383,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
{
struct Scsi_Host *shost;
gfp_t gfp_mask = GFP_KERNEL;
+ int index;
if (sht->unchecked_isa_dma && privsize)
gfp_mask |= __GFP_DMA;
@@ -388,11 +402,11 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
init_waitqueue_head(&shost->host_wait);
mutex_init(&shost->scan_mutex);
- /*
- * subtract one because we increment first then return, but we need to
- * know what the next host number was before increment
- */
- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
+ index = host_get_index(shost);
+ if (index < 0)
+ goto fail_kfree;
+ shost->host_no = index;
+
shost->dma_channel = 0xff;
/* These three are default values which can be overridden */
@@ -477,7 +491,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
shost_printk(KERN_WARNING, shost,
"error handler thread failed to spawn, error = %ld\n",
PTR_ERR(shost->ehandler));
- goto fail_kfree;
+ goto fail_idr_remove;
}
shost->tmf_work_q = alloc_workqueue("scsi_tmf_%d",
@@ -493,6 +507,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
fail_kthread:
kthread_stop(shost->ehandler);
+ fail_idr_remove:
+ host_put_index(shost->host_no);
fail_kfree:
kfree(shost);
return NULL;
@@ -522,38 +538,16 @@ void scsi_unregister(struct Scsi_Host *shost)
}
EXPORT_SYMBOL(scsi_unregister);
-static int __scsi_host_match(struct device *dev, const void *data)
-{
- struct Scsi_Host *p;
- const unsigned short *hostnum = data;
-
- p = class_to_shost(dev);
- return p->host_no == *hostnum;
-}
-
/**
* scsi_host_lookup - get a reference to a Scsi_Host by host no
* @hostnum: host number to locate
*
* Return value:
* A pointer to located Scsi_Host or NULL.
- *
- * The caller must do a scsi_host_put() to drop the reference
- * that scsi_host_get() took. The put_device() below dropped
- * the reference from class_find_device().
**/
struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
{
- struct device *cdev;
- struct Scsi_Host *shost = NULL;
-
- cdev = class_find_device(&shost_class, NULL, &hostnum,
- __scsi_host_match);
- if (cdev) {
- shost = scsi_host_get(class_to_shost(cdev));
- put_device(cdev);
- }
- return shost;
+ return idr_find(&host_index_idr, hostnum);
}
EXPORT_SYMBOL(scsi_host_lookup);
@@ -588,6 +582,7 @@ int scsi_init_hosts(void)
void scsi_exit_hosts(void)
{
class_unregister(&shost_class);
+ idr_destroy(&host_index_idr);
}
int scsi_is_host_device(const struct device *dev)
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 03/17] Update the st driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
2015-09-15 16:46 ` [PATCH 01/17] Add " Lee Duncan
2015-09-15 16:46 ` [PATCH 02/17] Update scsi hosts to use idr for host number mgmt Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 04/17] Update the ch " Lee Duncan
` (13 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Kai.Makisara
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/st.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index b37b9b00c4b4..51e1ce721d9f 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4265,11 +4265,8 @@ static int st_probe(struct device *dev)
tpnt->blksize_changed = 0;
mutex_init(&tpnt->lock);
- idr_preload(GFP_KERNEL);
- spin_lock(&st_index_lock);
- error = idr_alloc(&st_index_idr, tpnt, 0, ST_MAX_TAPES + 1, GFP_NOWAIT);
- spin_unlock(&st_index_lock);
- idr_preload_end();
+ error = idr_get_index_in_range(&st_index_idr, &st_index_lock, tpnt,
+ 0, ST_MAX_TAPES + 1);
if (error < 0) {
pr_warn("st: idr allocation failed: %d\n", error);
goto out_put_queue;
@@ -4303,9 +4300,7 @@ out_remove_devs:
remove_cdevs(tpnt);
kfree(tpnt->stats);
out_idr_remove:
- spin_lock(&st_index_lock);
- idr_remove(&st_index_idr, tpnt->index);
- spin_unlock(&st_index_lock);
+ idr_put_index(&st_index_idr, &st_index_lock, tpnt->index);
out_put_queue:
blk_put_queue(disk->queue);
out_put_disk:
@@ -4330,9 +4325,7 @@ static int st_remove(struct device *dev)
mutex_lock(&st_ref_mutex);
kref_put(&tpnt->kref, scsi_tape_release);
mutex_unlock(&st_ref_mutex);
- spin_lock(&st_index_lock);
- idr_remove(&st_index_idr, index);
- spin_unlock(&st_index_lock);
+ idr_put_index(&st_index_idr, &st_index_lock, index);
return 0;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 04/17] Update the ch driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (2 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 03/17] Update the st driver to use idr helper functions Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 05/17] Update the md " Lee Duncan
` (12 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Note: when allocating an index, in the error case,
where the just-allocated index has to be released,
the required locking around the index removal was
not present, so this conversion has the side effect
of adding locking for that error condition. This
should close a possible race condition that could
have resulted in duplicate index allocation.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/ch.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index dad959fcf6d8..2edf1f8883f9 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -909,12 +909,8 @@ static int ch_probe(struct device *dev)
if (NULL == ch)
return -ENOMEM;
- idr_preload(GFP_KERNEL);
- spin_lock(&ch_index_lock);
- ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
- spin_unlock(&ch_index_lock);
- idr_preload_end();
-
+ ret = idr_get_index_in_range(&ch_index_idr, &ch_index_lock, ch,
+ 0, CH_MAX_DEVS + 1);
if (ret < 0) {
if (ret == -ENOSPC)
ret = -ENODEV;
@@ -945,7 +941,7 @@ static int ch_probe(struct device *dev)
return 0;
remove_idr:
- idr_remove(&ch_index_idr, ch->minor);
+ idr_put_index(&ch_index_idr, &ch_index_lock, ch->minor);
free_ch:
kfree(ch);
return ret;
@@ -955,9 +951,7 @@ static int ch_remove(struct device *dev)
{
scsi_changer *ch = dev_get_drvdata(dev);
- spin_lock(&ch_index_lock);
- idr_remove(&ch_index_idr, ch->minor);
- spin_unlock(&ch_index_lock);
+ idr_put_index(&ch_index_idr, &ch_index_lock, ch->minor);
device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor));
kfree(ch->dt);
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 05/17] Update the md driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (3 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 04/17] Update the ch " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 18:05 ` Mike Snitzer
2015-09-15 16:46 ` [PATCH 06/17] Update the infiniband uverbs " Lee Duncan
` (11 subsequent siblings)
16 siblings, 1 reply; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Mike Snitzer
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/md/dm.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f331d888e7f5..53d6895eb13d 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2202,9 +2202,7 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
*---------------------------------------------------------------*/
static void free_minor(int minor)
{
- spin_lock(&_minor_lock);
- idr_remove(&_minor_idr, minor);
- spin_unlock(&_minor_lock);
+ idr_put_index(&_minor_idr, &_minor_lock, minor);
}
/*
@@ -2217,13 +2215,8 @@ static int specific_minor(int minor)
if (minor >= (1 << MINORBITS))
return -EINVAL;
- idr_preload(GFP_KERNEL);
- spin_lock(&_minor_lock);
-
- r = idr_alloc(&_minor_idr, MINOR_ALLOCED, minor, minor + 1, GFP_NOWAIT);
-
- spin_unlock(&_minor_lock);
- idr_preload_end();
+ r = idr_get_index_in_range(&_minor_idr, &_minor_lock, MINOR_ALLOCED,
+ minor, minor + 1);
if (r < 0)
return r == -ENOSPC ? -EBUSY : r;
return 0;
@@ -2233,13 +2226,8 @@ static int next_free_minor(int *minor)
{
int r;
- idr_preload(GFP_KERNEL);
- spin_lock(&_minor_lock);
-
- r = idr_alloc(&_minor_idr, MINOR_ALLOCED, 0, 1 << MINORBITS, GFP_NOWAIT);
-
- spin_unlock(&_minor_lock);
- idr_preload_end();
+ r = idr_get_index_in_range(&_minor_idr, &_minor_lock, MINOR_ALLOCED,
+ 0, 1 << MINORBITS);
if (r < 0)
return r;
*minor = r;
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 06/17] Update the infiniband uverbs driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (4 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 05/17] Update the md " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 07/17] Update the memstick " Lee Duncan
` (10 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Doug Ledford
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/infiniband/core/uverbs_cmd.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index bbb02ffe87df..1e5b2a66a501 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -120,24 +120,16 @@ static int idr_add_uobj(struct idr *idr, struct ib_uobject *uobj)
{
int ret;
- idr_preload(GFP_KERNEL);
- spin_lock(&ib_uverbs_idr_lock);
-
- ret = idr_alloc(idr, uobj, 0, 0, GFP_NOWAIT);
+ ret = idr_get_index(idr, &ib_uverbs_idr_lock, uobj);
if (ret >= 0)
uobj->id = ret;
- spin_unlock(&ib_uverbs_idr_lock);
- idr_preload_end();
-
return ret < 0 ? ret : 0;
}
void idr_remove_uobj(struct idr *idr, struct ib_uobject *uobj)
{
- spin_lock(&ib_uverbs_idr_lock);
- idr_remove(idr, uobj->id);
- spin_unlock(&ib_uverbs_idr_lock);
+ idr_put_index(idr, &ib_uverbs_idr_lock, uobj->id);
}
static struct ib_uobject *__idr_get_uobj(struct idr *idr, int id,
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 07/17] Update the memstick driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (5 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 06/17] Update the infiniband uverbs " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 08/17] Update the mmc " Lee Duncan
` (9 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/memstick/core/memstick.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index a0547dbf9806..8f40a3d5108b 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -512,25 +512,16 @@ int memstick_add_host(struct memstick_host *host)
{
int rc;
- idr_preload(GFP_KERNEL);
- spin_lock(&memstick_host_lock);
-
- rc = idr_alloc(&memstick_host_idr, host, 0, 0, GFP_NOWAIT);
- if (rc >= 0)
- host->id = rc;
-
- spin_unlock(&memstick_host_lock);
- idr_preload_end();
+ rc = idr_get_index(&memstick_host_idr, &memstick_host_lock, host);
if (rc < 0)
return rc;
+ host->id = rc;
dev_set_name(&host->dev, "memstick%u", host->id);
rc = device_add(&host->dev);
if (rc) {
- spin_lock(&memstick_host_lock);
- idr_remove(&memstick_host_idr, host->id);
- spin_unlock(&memstick_host_lock);
+ idr_put_index(&memstick_host_idr, &memstick_host_lock, host->id);
return rc;
}
@@ -554,9 +545,7 @@ void memstick_remove_host(struct memstick_host *host)
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
mutex_unlock(&host->lock);
- spin_lock(&memstick_host_lock);
- idr_remove(&memstick_host_idr, host->id);
- spin_unlock(&memstick_host_lock);
+ idr_put_index(&memstick_host_idr, &memstick_host_lock, host->id);
device_del(&host->dev);
}
EXPORT_SYMBOL(memstick_remove_host);
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 08/17] Update the mmc driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (6 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 07/17] Update the memstick " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-16 6:48 ` Ulf Hansson
2015-09-15 16:46 ` [PATCH 09/17] Update the virtgpu " Lee Duncan
` (8 subsequent siblings)
16 siblings, 1 reply; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Ulf Hansson
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/mmc/core/host.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 99a9c9011c50..5aa2330f074c 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -40,9 +40,8 @@ static DEFINE_SPINLOCK(mmc_host_lock);
static void mmc_host_classdev_release(struct device *dev)
{
struct mmc_host *host = cls_dev_to_mmc_host(dev);
- spin_lock(&mmc_host_lock);
- idr_remove(&mmc_host_idr, host->index);
- spin_unlock(&mmc_host_lock);
+
+ idr_put_index(&mmc_host_idr, &mmc_host_lock, host->index);
kfree(host);
}
@@ -559,17 +558,12 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
/* scanning will be enabled when we're ready */
host->rescan_disable = 1;
- idr_preload(GFP_KERNEL);
- spin_lock(&mmc_host_lock);
- err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT);
- if (err >= 0)
- host->index = err;
- spin_unlock(&mmc_host_lock);
- idr_preload_end();
+ err = idr_get_index(&mmc_host_idr, &mmc_host_lock, host);
if (err < 0) {
kfree(host);
return NULL;
}
+ host->index = err;
dev_set_name(&host->class_dev, "mmc%d", host->index);
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 09/17] Update the virtgpu driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (7 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 08/17] Update the mmc " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 10/17] Update the DCA DMA " Lee Duncan
` (7 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Gerd Hoffmann
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/gpu/drm/virtio/virtgpu_vq.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
index 1698669f4185..380947dad306 100644
--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
+++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
@@ -41,21 +41,14 @@
void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
uint32_t *resid)
{
- int handle;
-
- idr_preload(GFP_KERNEL);
- spin_lock(&vgdev->resource_idr_lock);
- handle = idr_alloc(&vgdev->resource_idr, NULL, 1, 0, GFP_NOWAIT);
- spin_unlock(&vgdev->resource_idr_lock);
- idr_preload_end();
- *resid = handle;
+ *resid = idr_get_index_in_range(&vgdev->resource_idr,
+ &vgdev->resource_idr_lock,
+ NULL, 1, 0);
}
void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
{
- spin_lock(&vgdev->resource_idr_lock);
- idr_remove(&vgdev->resource_idr, id);
- spin_unlock(&vgdev->resource_idr_lock);
+ idr_put_index(&vgdev->resource_idr, &vgdev->resource_idr_lock, id);
}
void virtio_gpu_ctrl_ack(struct virtqueue *vq)
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 10/17] Update the DCA DMA driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (8 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 09/17] Update the virtgpu " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 11/17] Update the rtsx multifunction " Lee Duncan
` (6 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/dca/dca-sysfs.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/drivers/dca/dca-sysfs.c b/drivers/dca/dca-sysfs.c
index 126cf295b198..8930707df295 100644
--- a/drivers/dca/dca-sysfs.c
+++ b/drivers/dca/dca-sysfs.c
@@ -55,23 +55,14 @@ int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
struct device *cd;
int ret;
- idr_preload(GFP_KERNEL);
- spin_lock(&dca_idr_lock);
-
- ret = idr_alloc(&dca_idr, dca, 0, 0, GFP_NOWAIT);
- if (ret >= 0)
- dca->id = ret;
-
- spin_unlock(&dca_idr_lock);
- idr_preload_end();
+ ret = idr_get_index(&dca_idr, &dca_idr_lock, dca);
if (ret < 0)
return ret;
+ dca->id = ret;
cd = device_create(dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id);
if (IS_ERR(cd)) {
- spin_lock(&dca_idr_lock);
- idr_remove(&dca_idr, dca->id);
- spin_unlock(&dca_idr_lock);
+ idr_put_index(&dca_idr, &dca_idr_lock, dca->id);
return PTR_ERR(cd);
}
dca->cd = cd;
@@ -82,9 +73,7 @@ void dca_sysfs_remove_provider(struct dca_provider *dca)
{
device_unregister(dca->cd);
dca->cd = NULL;
- spin_lock(&dca_idr_lock);
- idr_remove(&dca_idr, dca->id);
- spin_unlock(&dca_idr_lock);
+ idr_put_index(&dca_idr, &dca_idr_lock, dca->id);
}
int __init dca_sysfs_init(void)
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 11/17] Update the rtsx multifunction driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (9 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 10/17] Update the DCA DMA " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 12/17] Update the TI Flash Media " Lee Duncan
` (5 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Samuel Ortiz
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/mfd/rtsx_pcr.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index a66540a49079..8ddefb8c5e64 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -1191,15 +1191,10 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
}
handle->pcr = pcr;
- idr_preload(GFP_KERNEL);
- spin_lock(&rtsx_pci_lock);
- ret = idr_alloc(&rtsx_pci_idr, pcr, 0, 0, GFP_NOWAIT);
- if (ret >= 0)
- pcr->id = ret;
- spin_unlock(&rtsx_pci_lock);
- idr_preload_end();
+ ret = idr_get_index(&rtsx_pci_idr, &rtsc_pci_lock, pcr);
if (ret < 0)
goto free_handle;
+ pcr->id = ret;
pcr->pci = pcidev;
dev_set_drvdata(&pcidev->dev, handle);
@@ -1311,9 +1306,7 @@ static void rtsx_pci_remove(struct pci_dev *pcidev)
pci_release_regions(pcidev);
pci_disable_device(pcidev);
- spin_lock(&rtsx_pci_lock);
- idr_remove(&rtsx_pci_idr, pcr->id);
- spin_unlock(&rtsx_pci_lock);
+ idr_put_index(&rtsx_pci_idr, &rtsx_pci_lock, pcr->id);
kfree(pcr->slots);
kfree(pcr);
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 12/17] Update the TI Flash Media driver to use idr helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (10 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 11/17] Update the rtsx multifunction " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 13/17] Update the SCSI disk driver to use ida " Lee Duncan
` (4 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Alex Dubov
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/misc/tifm_core.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c
index a511b2a713b3..46385f828a8f 100644
--- a/drivers/misc/tifm_core.c
+++ b/drivers/misc/tifm_core.c
@@ -198,22 +198,15 @@ int tifm_add_adapter(struct tifm_adapter *fm)
{
int rc;
- idr_preload(GFP_KERNEL);
- spin_lock(&tifm_adapter_lock);
- rc = idr_alloc(&tifm_adapter_idr, fm, 0, 0, GFP_NOWAIT);
- if (rc >= 0)
- fm->id = rc;
- spin_unlock(&tifm_adapter_lock);
- idr_preload_end();
+ rc = idr_get_index(&tifm_adapter_idr, &tifm_adapter_lock, fm);
if (rc < 0)
return rc;
+ fm->id = rc;
dev_set_name(&fm->dev, "tifm%u", fm->id);
rc = device_add(&fm->dev);
if (rc) {
- spin_lock(&tifm_adapter_lock);
- idr_remove(&tifm_adapter_idr, fm->id);
- spin_unlock(&tifm_adapter_lock);
+ idr_put_index(&tifm_adapter_idr, &tifm_adapter_lock, fm->id);
}
return rc;
@@ -230,9 +223,7 @@ void tifm_remove_adapter(struct tifm_adapter *fm)
device_unregister(&fm->sockets[cnt]->dev);
}
- spin_lock(&tifm_adapter_lock);
- idr_remove(&tifm_adapter_idr, fm->id);
- spin_unlock(&tifm_adapter_lock);
+ idr_put_index(&tifm_adapter_idr, &tifm_adapter_lock, fm->id);
device_del(&fm->dev);
}
EXPORT_SYMBOL(tifm_remove_adapter);
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 13/17] Update the SCSI disk driver to use ida helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (11 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 12/17] Update the TI Flash Media " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 14/17] Update the rsxx flash adapter " Lee Duncan
` (3 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/scsi/sd.c | 20 ++++----------------
1 file changed, 4 insertions(+), 16 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3b2fcb4fada0..60b2ad918208 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2948,15 +2948,7 @@ 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);
-
+ error = ida_get_index(&sd_index_ida, &sd_index_lock, &index);
if (error) {
sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n");
goto out_put;
@@ -3001,9 +2993,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);
+ ida_put_index(&sd_index_ida, &sd_index_lock, index);
out_put:
put_disk(gd);
out_free:
@@ -3063,10 +3053,8 @@ 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);
+
+ ida_put_index(&sd_index_ida, &sd_index_lock, sdkp->index);
blk_integrity_unregister(disk);
disk->private_data = NULL;
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 14/17] Update the rsxx flash adapter driver to use ida helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (12 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 13/17] Update the SCSI disk driver to use ida " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 15/17] Update the NVMe SSD " Lee Duncan
` (2 subsequent siblings)
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Joshua Morris
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/block/rsxx/core.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index d8b2488aaade..dd23a0e85040 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -774,17 +774,7 @@ 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);
-
+ st = ida_get_index(&rsxx_disk_ida, &rsxx_ida_lock, &card->disk_id);
if (st)
goto failed_ida_get;
@@ -987,9 +977,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);
+ ida_put_index(&rsxx_disk_ida, &rsxx_ida_lock, card->disk_id);
failed_ida_get:
kfree(card);
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 15/17] Update the NVMe SSD driver to use ida helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (13 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 14/17] Update the rsxx flash adapter " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 16/17] Update the Micron PCIe " Lee Duncan
2015-09-15 16:46 ` [PATCH 17/17] Update the ARM soc base " Lee Duncan
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan, Matthew Wilcox
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/block/nvme-core.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index d1d6141920d3..ab13833d4fde 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -2715,15 +2715,7 @@ static int nvme_set_instance(struct nvme_dev *dev)
{
int instance, error;
- 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);
-
+ error = ida_get_index(&nvme_instance_ida, &dev_list_lock, &instance);
if (error)
return -ENODEV;
@@ -2733,9 +2725,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);
+ ida_put_index(&nvme_instance_ida, &dev_list_lock, dev->instance);
}
static void nvme_free_namespaces(struct nvme_dev *dev)
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 16/17] Update the Micron PCIe SSD driver to use ida helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (14 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 15/17] Update the NVMe SSD " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 17/17] Update the ARM soc base " Lee Duncan
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/block/mtip32xx/mtip32xx.c | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 4a2ef09e6704..ccff4119b554 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -3821,15 +3821,7 @@ static int mtip_block_initialize(struct driver_data *dd)
}
/* 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);
-
+ rv = ida_get_index(&rssd_index_ida, &rssd_index_lock, &index);
if (rv)
goto ida_get_error;
@@ -3981,9 +3973,7 @@ init_hw_cmds_error:
block_queue_alloc_init_error:
mtip_hw_debugfs_exit(dd);
disk_index_error:
- spin_lock(&rssd_index_lock);
- ida_remove(&rssd_index_ida, index);
- spin_unlock(&rssd_index_lock);
+ ida_put_index(&rssd_index_ida, &rssd_index_lock, index);
ida_get_error:
put_disk(dd->disk);
@@ -4051,9 +4041,7 @@ static int mtip_block_remove(struct driver_data *dd)
}
dd->disk = NULL;
- spin_lock(&rssd_index_lock);
- ida_remove(&rssd_index_ida, dd->index);
- spin_unlock(&rssd_index_lock);
+ ida_put_index(&rssd_index_ida, &rssd_index_lock, dd->index);
/* De-initialize the protocol layer. */
mtip_hw_exit(dd);
@@ -4092,9 +4080,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);
+ ida_put_index(&rssd_index_ida, &rssd_index_lock, dd->index);
return 0;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 17/17] Update the ARM soc base driver to use ida helper functions.
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
` (15 preceding siblings ...)
2015-09-15 16:46 ` [PATCH 16/17] Update the Micron PCIe " Lee Duncan
@ 2015-09-15 16:46 ` Lee Duncan
16 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-15 16:46 UTC (permalink / raw)
To: linux-scsi, linux-kernel
Cc: Hannes Reinecke, Johannes Thumshirn, Christoph Hellwig,
Lee Duncan
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/base/soc.c | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 39fca01c8fa1..cf70c3246123 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -122,18 +122,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
}
/* 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_index(&soc_ida, &soc_lock, &soc_dev->soc_dev_num);
if (ret)
goto out2;
@@ -151,7 +140,7 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
return soc_dev;
out3:
- ida_remove(&soc_ida, soc_dev->soc_dev_num);
+ ida_put_index(&soc_ida, &soc_lock, soc_dev->soc_dev_num);
out2:
kfree(soc_dev);
out1:
@@ -161,7 +150,7 @@ out1:
/* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
void soc_device_unregister(struct soc_device *soc_dev)
{
- ida_remove(&soc_ida, soc_dev->soc_dev_num);
+ ida_put_index(&soc_ida, &soc_lock, soc_dev->soc_dev_num);
device_unregister(&soc_dev->dev);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 05/17] Update the md driver to use idr helper functions.
2015-09-15 16:46 ` [PATCH 05/17] Update the md " Lee Duncan
@ 2015-09-15 18:05 ` Mike Snitzer
2015-09-17 20:51 ` Lee Duncan
0 siblings, 1 reply; 28+ messages in thread
From: Mike Snitzer @ 2015-09-15 18:05 UTC (permalink / raw)
To: Lee Duncan
Cc: linux-scsi, linux-kernel, Hannes Reinecke, Johannes Thumshirn,
Christoph Hellwig
Subject should really be:
"dm: update to use idr helper functions"
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 01/17] Add ida and idr helper routines.
2015-09-15 16:46 ` [PATCH 01/17] Add " Lee Duncan
@ 2015-09-15 18:20 ` James Bottomley
2015-09-15 18:27 ` Tejun Heo
1 sibling, 0 replies; 28+ messages in thread
From: James Bottomley @ 2015-09-15 18:20 UTC (permalink / raw)
To: Lee Duncan
Cc: linux-scsi, linux-kernel, Hannes Reinecke, Johannes Thumshirn,
Christoph Hellwig, Tejun Heo
On Tue, 2015-09-15 at 09:46 -0700, Lee Duncan wrote:
> Clients of the ida and idr index-management routines
> tend to use the same calling sequences much of the time,
> so this change adds helper functions for allocating and
> releasing indexes of either flavor, i.e. with or
> without pointer management.
>
> Inline functions added for idr:
> idr_get_index_in_range
> idr_get_index (in range 0,0)
> idr_put_index
> And for ida:
> ida_get_index
> ida_put_index
Every consumer of this I've seen seems to have the pattern of allocating
the ida and the protecting spinlock together. If that's the case, why
not move the spinlock into struct ida so it doesn't have to be
separately allocated and passed in to all the helpers?
Also, you need a cc of Tejun (added on this one) because he's the one
who last did significant work in ida/idr.
James
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 01/17] Add ida and idr helper routines.
2015-09-15 16:46 ` [PATCH 01/17] Add " Lee Duncan
2015-09-15 18:20 ` James Bottomley
@ 2015-09-15 18:27 ` Tejun Heo
2015-09-15 18:38 ` James Bottomley
1 sibling, 1 reply; 28+ messages in thread
From: Tejun Heo @ 2015-09-15 18:27 UTC (permalink / raw)
To: Lee Duncan
Cc: linux-scsi, linux-kernel, Hannes Reinecke, Johannes Thumshirn,
Christoph Hellwig
Hello,
On Tue, Sep 15, 2015 at 09:46:01AM -0700, Lee Duncan wrote:
> +/**
> + * ida_get_index - allocate a ida index value
> + * @ida idr handle
> + * @lock spinlock handle protecting this index
> + * @p_id pointer to allocated index value
> + *
> + * A helper function for safely allocating an index value (id),
> + * returning a negative errno value on failure, else 0.
> + */
> +static inline int ida_get_index(struct ida *ida, spinlock_t *lock, int *p_id)
> +{
> + int error = -ENOMEM;
> +
> + do {
> + if (!ida_pre_get(ida, GFP_KERNEL))
> + break;
> + spin_lock(lock);
> + error = ida_get_new(ida, p_id);
> + spin_unlock(lock);
> + } while (error == -EAGAIN);
> +
> + return error;
> +}
Obviously ida allocation doesn't need to be synchronized against
anything else. Why not just use ida_simple_get/remove()?
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 01/17] Add ida and idr helper routines.
2015-09-15 18:27 ` Tejun Heo
@ 2015-09-15 18:38 ` James Bottomley
2015-09-15 18:41 ` Tejun Heo
0 siblings, 1 reply; 28+ messages in thread
From: James Bottomley @ 2015-09-15 18:38 UTC (permalink / raw)
To: Tejun Heo
Cc: Lee Duncan, linux-scsi, linux-kernel, Hannes Reinecke,
Johannes Thumshirn, Christoph Hellwig
On Tue, 2015-09-15 at 14:27 -0400, Tejun Heo wrote:
> Hello,
>
> On Tue, Sep 15, 2015 at 09:46:01AM -0700, Lee Duncan wrote:
> > +/**
> > + * ida_get_index - allocate a ida index value
> > + * @ida idr handle
> > + * @lock spinlock handle protecting this index
> > + * @p_id pointer to allocated index value
> > + *
> > + * A helper function for safely allocating an index value (id),
> > + * returning a negative errno value on failure, else 0.
> > + */
> > +static inline int ida_get_index(struct ida *ida, spinlock_t *lock, int *p_id)
> > +{
> > + int error = -ENOMEM;
> > +
> > + do {
> > + if (!ida_pre_get(ida, GFP_KERNEL))
> > + break;
> > + spin_lock(lock);
> > + error = ida_get_new(ida, p_id);
> > + spin_unlock(lock);
> > + } while (error == -EAGAIN);
> > +
> > + return error;
> > +}
>
> Obviously ida allocation doesn't need to be synchronized against
> anything else. Why not just use ida_simple_get/remove()?
For most of the SCSI stuff, yes. I'm less sure about the sd numbers.
They go up very high and get hammered a lot during system bring up and
hot plug. I think having their own lock rather than wrapping everything
around simple_ida_lock makes more sense here just because the system is
heavily contended on getting indexes at bring up.
To continue the thought, why not move simple_ida_lock into struct ida so
we don't have to worry about the contention and can sue ida_simple_...
everywhere?
James
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 01/17] Add ida and idr helper routines.
2015-09-15 18:38 ` James Bottomley
@ 2015-09-15 18:41 ` Tejun Heo
2015-09-18 15:42 ` Lee Duncan
0 siblings, 1 reply; 28+ messages in thread
From: Tejun Heo @ 2015-09-15 18:41 UTC (permalink / raw)
To: James Bottomley
Cc: Lee Duncan, linux-scsi, linux-kernel, Hannes Reinecke,
Johannes Thumshirn, Christoph Hellwig
Hello,
On Tue, Sep 15, 2015 at 11:38:42AM -0700, James Bottomley wrote:
> For most of the SCSI stuff, yes. I'm less sure about the sd numbers.
> They go up very high and get hammered a lot during system bring up and
> hot plug. I think having their own lock rather than wrapping everything
> around simple_ida_lock makes more sense here just because the system is
> heavily contended on getting indexes at bring up.
>
> To continue the thought, why not move simple_ida_lock into struct ida so
> we don't have to worry about the contention and can sue ida_simple_...
> everywhere?
We sure can do that if necessary but I'm rather doubtful that even
with sd number hammering this is likely to be a problem. Let's
convert the users to the simple interface and make the lock per-ida if
we actually see contention on the lock.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 08/17] Update the mmc driver to use idr helper functions.
2015-09-15 16:46 ` [PATCH 08/17] Update the mmc " Lee Duncan
@ 2015-09-16 6:48 ` Ulf Hansson
0 siblings, 0 replies; 28+ messages in thread
From: Ulf Hansson @ 2015-09-16 6:48 UTC (permalink / raw)
To: Lee Duncan
Cc: linux-scsi, linux-kernel@vger.kernel.org, Hannes Reinecke,
Johannes Thumshirn, Christoph Hellwig
On 15 September 2015 at 18:46, Lee Duncan <lduncan@suse.com> wrote:
> Signed-off-by: Lee Duncan <lduncan@suse.com>
Please change the prefix of the commit message header to "mmc: core"
and resend to linux-mmc.
Kind regards
Uffe
> ---
> drivers/mmc/core/host.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
> index 99a9c9011c50..5aa2330f074c 100644
> --- a/drivers/mmc/core/host.c
> +++ b/drivers/mmc/core/host.c
> @@ -40,9 +40,8 @@ static DEFINE_SPINLOCK(mmc_host_lock);
> static void mmc_host_classdev_release(struct device *dev)
> {
> struct mmc_host *host = cls_dev_to_mmc_host(dev);
> - spin_lock(&mmc_host_lock);
> - idr_remove(&mmc_host_idr, host->index);
> - spin_unlock(&mmc_host_lock);
> +
> + idr_put_index(&mmc_host_idr, &mmc_host_lock, host->index);
> kfree(host);
> }
>
> @@ -559,17 +558,12 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
>
> /* scanning will be enabled when we're ready */
> host->rescan_disable = 1;
> - idr_preload(GFP_KERNEL);
> - spin_lock(&mmc_host_lock);
> - err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT);
> - if (err >= 0)
> - host->index = err;
> - spin_unlock(&mmc_host_lock);
> - idr_preload_end();
> + err = idr_get_index(&mmc_host_idr, &mmc_host_lock, host);
> if (err < 0) {
> kfree(host);
> return NULL;
> }
> + host->index = err;
>
> dev_set_name(&host->class_dev, "mmc%d", host->index);
>
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 05/17] Update the md driver to use idr helper functions.
2015-09-16 17:50 [PATCH 00/17] Create and use ida and idr helper routines [RESEND] Lee Duncan
@ 2015-09-16 17:50 ` Lee Duncan
0 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-16 17:50 UTC (permalink / raw)
To: linux-scsi, James.Bottomley
Cc: linux-kernel, hare, jthumshirn, hch, Lee Duncan, Mike Snitzer
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
drivers/md/dm.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f331d888e7f5..53d6895eb13d 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2202,9 +2202,7 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
*---------------------------------------------------------------*/
static void free_minor(int minor)
{
- spin_lock(&_minor_lock);
- idr_remove(&_minor_idr, minor);
- spin_unlock(&_minor_lock);
+ idr_put_index(&_minor_idr, &_minor_lock, minor);
}
/*
@@ -2217,13 +2215,8 @@ static int specific_minor(int minor)
if (minor >= (1 << MINORBITS))
return -EINVAL;
- idr_preload(GFP_KERNEL);
- spin_lock(&_minor_lock);
-
- r = idr_alloc(&_minor_idr, MINOR_ALLOCED, minor, minor + 1, GFP_NOWAIT);
-
- spin_unlock(&_minor_lock);
- idr_preload_end();
+ r = idr_get_index_in_range(&_minor_idr, &_minor_lock, MINOR_ALLOCED,
+ minor, minor + 1);
if (r < 0)
return r == -ENOSPC ? -EBUSY : r;
return 0;
@@ -2233,13 +2226,8 @@ static int next_free_minor(int *minor)
{
int r;
- idr_preload(GFP_KERNEL);
- spin_lock(&_minor_lock);
-
- r = idr_alloc(&_minor_idr, MINOR_ALLOCED, 0, 1 << MINORBITS, GFP_NOWAIT);
-
- spin_unlock(&_minor_lock);
- idr_preload_end();
+ r = idr_get_index_in_range(&_minor_idr, &_minor_lock, MINOR_ALLOCED,
+ 0, 1 << MINORBITS);
if (r < 0)
return r;
*minor = r;
--
2.1.4
^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 05/17] Update the md driver to use idr helper functions.
2015-09-15 18:05 ` Mike Snitzer
@ 2015-09-17 20:51 ` Lee Duncan
0 siblings, 0 replies; 28+ messages in thread
From: Lee Duncan @ 2015-09-17 20:51 UTC (permalink / raw)
To: Mike Snitzer
Cc: linux-scsi, linux-kernel, Hannes Reinecke, Johannes Thumshirn,
Christoph Hellwig
On 09/15/2015 11:05 AM, Mike Snitzer wrote:
> Subject should really be:
> "dm: update to use idr helper functions"
Yes, I grabbed the wrong part of the driver pathname.
Would it be better to resubmit just this patch, or to resubmit the series?
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 01/17] Add ida and idr helper routines.
2015-09-15 18:41 ` Tejun Heo
@ 2015-09-18 15:42 ` Lee Duncan
2015-09-18 15:49 ` Tejun Heo
0 siblings, 1 reply; 28+ messages in thread
From: Lee Duncan @ 2015-09-18 15:42 UTC (permalink / raw)
To: Tejun Heo, James Bottomley
Cc: linux-scsi, linux-kernel, Hannes Reinecke, Johannes Thumshirn,
Christoph Hellwig
On 09/15/2015 11:41 AM, Tejun Heo wrote:
> Hello,
>
> On Tue, Sep 15, 2015 at 11:38:42AM -0700, James Bottomley wrote:
>> For most of the SCSI stuff, yes. I'm less sure about the sd numbers.
>> They go up very high and get hammered a lot during system bring up and
>> hot plug. I think having their own lock rather than wrapping everything
>> around simple_ida_lock makes more sense here just because the system is
>> heavily contended on getting indexes at bring up.
>>
>> To continue the thought, why not move simple_ida_lock into struct ida so
>> we don't have to worry about the contention and can sue ida_simple_...
>> everywhere?
>
> We sure can do that if necessary but I'm rather doubtful that even
> with sd number hammering this is likely to be a problem. Let's
> convert the users to the simple interface and make the lock per-ida if
> we actually see contention on the lock.
>
> Thanks.
>
To be clear: you would like a patch series that converts the users of
the ida_* routines in my patches to instead use the ida_simple_*
routines, correct? And of course the ida_* helper routines I was adding
in idr.h would not be needed.
If this is correct, I will supply a version 2 patch series that
addresses this issue as well as the two patch-naming issues that were
raised.
--
Lee Duncan
^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 01/17] Add ida and idr helper routines.
2015-09-18 15:42 ` Lee Duncan
@ 2015-09-18 15:49 ` Tejun Heo
0 siblings, 0 replies; 28+ messages in thread
From: Tejun Heo @ 2015-09-18 15:49 UTC (permalink / raw)
To: Lee Duncan
Cc: James Bottomley, linux-scsi, linux-kernel, Hannes Reinecke,
Johannes Thumshirn, Christoph Hellwig
Hello,
On Fri, Sep 18, 2015 at 08:42:26AM -0700, Lee Duncan wrote:
> To be clear: you would like a patch series that converts the users of
> the ida_* routines in my patches to instead use the ida_simple_*
> routines, correct? And of course the ida_* helper routines I was adding
> in idr.h would not be needed.
Yeap.
> If this is correct, I will supply a version 2 patch series that
> addresses this issue as well as the two patch-naming issues that were
> raised.
Sounds good to me. If the shared lock blows up, we can make that
per-ida.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2015-09-18 15:49 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-15 16:46 [PATCH 00/17] Create and use ida and idr helper routines Lee Duncan
2015-09-15 16:46 ` [PATCH 01/17] Add " Lee Duncan
2015-09-15 18:20 ` James Bottomley
2015-09-15 18:27 ` Tejun Heo
2015-09-15 18:38 ` James Bottomley
2015-09-15 18:41 ` Tejun Heo
2015-09-18 15:42 ` Lee Duncan
2015-09-18 15:49 ` Tejun Heo
2015-09-15 16:46 ` [PATCH 02/17] Update scsi hosts to use idr for host number mgmt Lee Duncan
2015-09-15 16:46 ` [PATCH 03/17] Update the st driver to use idr helper functions Lee Duncan
2015-09-15 16:46 ` [PATCH 04/17] Update the ch " Lee Duncan
2015-09-15 16:46 ` [PATCH 05/17] Update the md " Lee Duncan
2015-09-15 18:05 ` Mike Snitzer
2015-09-17 20:51 ` Lee Duncan
2015-09-15 16:46 ` [PATCH 06/17] Update the infiniband uverbs " Lee Duncan
2015-09-15 16:46 ` [PATCH 07/17] Update the memstick " Lee Duncan
2015-09-15 16:46 ` [PATCH 08/17] Update the mmc " Lee Duncan
2015-09-16 6:48 ` Ulf Hansson
2015-09-15 16:46 ` [PATCH 09/17] Update the virtgpu " Lee Duncan
2015-09-15 16:46 ` [PATCH 10/17] Update the DCA DMA " Lee Duncan
2015-09-15 16:46 ` [PATCH 11/17] Update the rtsx multifunction " Lee Duncan
2015-09-15 16:46 ` [PATCH 12/17] Update the TI Flash Media " Lee Duncan
2015-09-15 16:46 ` [PATCH 13/17] Update the SCSI disk driver to use ida " Lee Duncan
2015-09-15 16:46 ` [PATCH 14/17] Update the rsxx flash adapter " Lee Duncan
2015-09-15 16:46 ` [PATCH 15/17] Update the NVMe SSD " Lee Duncan
2015-09-15 16:46 ` [PATCH 16/17] Update the Micron PCIe " Lee Duncan
2015-09-15 16:46 ` [PATCH 17/17] Update the ARM soc base " Lee Duncan
-- strict thread matches above, loose matches on Subject: below --
2015-09-16 17:50 [PATCH 00/17] Create and use ida and idr helper routines [RESEND] Lee Duncan
2015-09-16 17:50 ` [PATCH 05/17] Update the md driver to use idr helper functions Lee Duncan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).