From: Tejun Heo <tj@kernel.org>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, rusty@rustcorp.com.au,
bfields@fieldses.org, skinsbursky@parallels.com,
ebiederm@xmission.com, jmorris@namei.org, axboe@kernel.dk,
Tejun Heo <tj@kernel.org>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
linux-scsi@vger.kernel.org
Subject: [PATCH 45/62] scsi: convert to idr_alloc()
Date: Sat, 2 Feb 2013 17:20:46 -0800 [thread overview]
Message-ID: <1359854463-2538-46-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1359854463-2538-1-git-send-email-tj@kernel.org>
Convert to the much saner new idr interface.
Only compile tested.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org
---
This patch depends on an earlier idr changes and I think it would be
best to route these together through -mm. Please holler if there's
any objection. Thanks.
drivers/scsi/ch.c | 21 +++++++++------------
drivers/scsi/sg.c | 43 +++++++++++++++++--------------------------
drivers/scsi/st.c | 27 ++++++++-------------------
3 files changed, 34 insertions(+), 57 deletions(-)
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index a15474e..2a32374 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -895,7 +895,7 @@ static int ch_probe(struct device *dev)
{
struct scsi_device *sd = to_scsi_device(dev);
struct device *class_dev;
- int minor, ret = -ENOMEM;
+ int ret;
scsi_changer *ch;
if (sd->type != TYPE_MEDIUM_CHANGER)
@@ -905,22 +905,19 @@ static int ch_probe(struct device *dev)
if (NULL == ch)
return -ENOMEM;
- if (!idr_pre_get(&ch_index_idr, GFP_KERNEL))
- goto free_ch;
-
+ idr_preload(GFP_KERNEL);
spin_lock(&ch_index_lock);
- ret = idr_get_new(&ch_index_idr, ch, &minor);
+ ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
spin_unlock(&ch_index_lock);
+ idr_preload_end();
- if (ret)
+ if (ret < 0) {
+ if (ret == -ENOSPC)
+ ret = -ENODEV;
goto free_ch;
-
- if (minor > CH_MAX_DEVS) {
- ret = -ENODEV;
- goto remove_idr;
}
- ch->minor = minor;
+ ch->minor = ret;
sprintf(ch->name,"ch%d",ch->minor);
class_dev = device_create(ch_sysfs_class, dev,
@@ -944,7 +941,7 @@ static int ch_probe(struct device *dev)
return 0;
remove_idr:
- idr_remove(&ch_index_idr, minor);
+ idr_remove(&ch_index_idr, ch->minor);
free_ch:
kfree(ch);
return ret;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index be2c9a6..9f0c465 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1391,24 +1391,23 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
return ERR_PTR(-ENOMEM);
}
- if (!idr_pre_get(&sg_index_idr, GFP_KERNEL)) {
- printk(KERN_WARNING "idr expansion Sg_device failure\n");
- error = -ENOMEM;
- goto out;
- }
-
+ idr_preload(GFP_KERNEL);
write_lock_irqsave(&sg_index_lock, iflags);
- error = idr_get_new(&sg_index_idr, sdp, &k);
- if (error) {
- write_unlock_irqrestore(&sg_index_lock, iflags);
- printk(KERN_WARNING "idr allocation Sg_device failure: %d\n",
- error);
- goto out;
+ error = idr_alloc(&sg_index_idr, sdp, 0, SG_MAX_DEVS, GFP_NOWAIT);
+ if (error < 0) {
+ if (error == -ENOSPC) {
+ sdev_printk(KERN_WARNING, scsidp,
+ "Unable to attach sg device type=%d, minor number exceeds %d\n",
+ scsidp->type, SG_MAX_DEVS - 1);
+ error = -ENODEV;
+ } else {
+ printk(KERN_WARNING
+ "idr allocation Sg_device failure: %d\n", error);
+ }
+ goto out_unlock;
}
-
- if (unlikely(k >= SG_MAX_DEVS))
- goto overflow;
+ k = error;
SCSI_LOG_TIMEOUT(3, printk("sg_alloc: dev=%d \n", k));
sprintf(disk->disk_name, "sg%d", k);
@@ -1420,25 +1419,17 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
sdp->sg_tablesize = queue_max_segments(q);
sdp->index = k;
kref_init(&sdp->d_ref);
+ error = 0;
+out_unlock:
write_unlock_irqrestore(&sg_index_lock, iflags);
+ idr_preload_end();
- error = 0;
- out:
if (error) {
kfree(sdp);
return ERR_PTR(error);
}
return sdp;
-
- overflow:
- idr_remove(&sg_index_idr, k);
- write_unlock_irqrestore(&sg_index_lock, iflags);
- sdev_printk(KERN_WARNING, scsidp,
- "Unable to attach sg device type=%d, minor "
- "number exceeds %d\n", scsidp->type, SG_MAX_DEVS - 1);
- error = -ENODEV;
- goto out;
}
static int
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 98156a9..7c6edca 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4076,7 +4076,7 @@ static int st_probe(struct device *dev)
struct st_modedef *STm;
struct st_partstat *STps;
struct st_buffer *buffer;
- int i, dev_num, error;
+ int i, error;
char *stp;
if (SDp->type != TYPE_TAPE)
@@ -4178,27 +4178,17 @@ static int st_probe(struct device *dev)
tpnt->blksize_changed = 0;
mutex_init(&tpnt->lock);
- if (!idr_pre_get(&st_index_idr, GFP_KERNEL)) {
- pr_warn("st: idr expansion failed\n");
- error = -ENOMEM;
- goto out_put_disk;
- }
-
+ idr_preload(GFP_KERNEL);
spin_lock(&st_index_lock);
- error = idr_get_new(&st_index_idr, tpnt, &dev_num);
+ error = idr_alloc(&st_index_idr, tpnt, 0, ST_MAX_TAPES + 1, GFP_NOWAIT);
spin_unlock(&st_index_lock);
- if (error) {
+ idr_preload_end();
+ if (error < 0) {
pr_warn("st: idr allocation failed: %d\n", error);
goto out_put_disk;
}
-
- if (dev_num > ST_MAX_TAPES) {
- pr_err("st: Too many tape devices (max. %d).\n", ST_MAX_TAPES);
- goto out_put_index;
- }
-
- tpnt->index = dev_num;
- sprintf(disk->disk_name, "st%d", dev_num);
+ tpnt->index = error;
+ sprintf(disk->disk_name, "st%d", tpnt->index);
dev_set_drvdata(dev, tpnt);
@@ -4218,9 +4208,8 @@ static int st_probe(struct device *dev)
out_remove_devs:
remove_cdevs(tpnt);
-out_put_index:
spin_lock(&st_index_lock);
- idr_remove(&st_index_idr, dev_num);
+ idr_remove(&st_index_idr, tpnt->index);
spin_unlock(&st_index_lock);
out_put_disk:
put_disk(disk);
--
1.8.1
next prev parent reply other threads:[~2013-02-03 1:22 UTC|newest]
Thread overview: 128+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-03 1:20 [PATCHSET] idr: implement idr_alloc() and convert existing users Tejun Heo
2013-02-03 1:20 ` [PATCH 01/62] idr: cosmetic updates to struct / initializer definitions Tejun Heo
2013-02-03 1:20 ` [PATCH 02/62] idr: relocate idr_for_each_entry() and reorganize id[r|a]_get_new() Tejun Heo
2013-02-03 1:20 ` [PATCH 03/62] idr: remove _idr_rc_to_errno() hack Tejun Heo
2013-02-03 1:20 ` [PATCH 04/62] idr: refactor idr_get_new_above() Tejun Heo
2013-02-03 1:20 ` [PATCH 05/62] idr: implement idr_preload[_end]() and idr_alloc() Tejun Heo
2013-02-04 18:32 ` [PATCH v2 " Tejun Heo
2013-02-03 1:20 ` [PATCH 06/62] block: fix synchronization and limit check in blk_alloc_devt() Tejun Heo
2013-02-06 11:00 ` Jens Axboe
2013-02-03 1:20 ` [PATCH 07/62] block: convert to idr_alloc() Tejun Heo
2013-02-04 13:10 ` Jens Axboe
2013-02-03 1:20 ` [PATCH 08/62] block/loop: " Tejun Heo
2013-02-04 13:11 ` Jens Axboe
2013-02-03 1:20 ` [PATCH 09/62] atm/nicstar: " Tejun Heo
2013-02-04 14:04 ` chas williams - CONTRACTOR
2013-02-04 17:06 ` Tejun Heo
2013-02-04 18:06 ` chas williams - CONTRACTOR
2013-02-04 18:37 ` [PATCH v3 " Tejun Heo
2013-02-03 1:20 ` [PATCH 10/62] drbd: " Tejun Heo
2013-02-03 1:20 ` [PATCH 11/62] dca: " Tejun Heo
2013-02-03 1:20 ` [PATCH 12/62] dmaengine: " Tejun Heo
2013-02-03 1:20 ` [PATCH 13/62] firewire: " Tejun Heo
2013-02-03 11:03 ` Stefan Richter
2013-02-03 11:18 ` Stefan Richter
2013-02-04 16:57 ` [PATCH 12.5/62] firewire: add minor number range check to fw_device_init() Tejun Heo
2013-02-04 18:15 ` Stefan Richter
2013-02-04 16:58 ` [PATCH v2 13/62] firewire: convert to idr_alloc() Tejun Heo
2013-02-04 18:16 ` Stefan Richter
2013-02-03 1:20 ` [PATCH 14/62] gpio: " Tejun Heo
2013-02-04 20:40 ` Linus Walleij
2013-02-03 1:20 ` [PATCH 15/62] drm: " Tejun Heo
2013-02-03 1:20 ` [PATCH 16/62] drm/exynos: " Tejun Heo
2013-02-03 1:20 ` [PATCH 17/62] drm/i915: " Tejun Heo
2013-02-04 14:53 ` Daniel Vetter
2013-02-03 1:20 ` [PATCH 18/62] drm/sis: " Tejun Heo
2013-02-03 1:20 ` [PATCH 19/62] drm/via: " Tejun Heo
2013-02-03 1:20 ` [PATCH 20/62] drm/vmwgfx: " Tejun Heo
2013-02-03 1:20 ` [PATCH 21/62] i2c: " Tejun Heo
2013-02-03 1:20 ` [PATCH 22/62] infiniband/core: " Tejun Heo
2013-02-04 16:43 ` [PATCH v2 " Tejun Heo
2013-02-05 0:07 ` Hefty, Sean
2013-02-03 1:20 ` [PATCH 23/62] infiniband/amso1100: " Tejun Heo
2013-02-03 14:36 ` Steve Wise
2013-02-03 1:20 ` [PATCH 24/62] infiniband/cxgb3: " Tejun Heo
2013-02-03 14:37 ` Steve Wise
2013-02-03 1:20 ` [PATCH 25/62] infiniband/cxgb4: " Tejun Heo
2013-02-03 14:18 ` Steve Wise
2013-02-03 14:28 ` Tejun Heo
2013-02-04 15:32 ` Steve Wise
2013-02-03 1:20 ` [PATCH 26/62] infiniband/ehca: " Tejun Heo
2013-02-03 1:20 ` [PATCH 27/62] infiniband/ipath: " Tejun Heo
2013-02-04 16:15 ` Marciniszyn, Mike
2013-02-04 16:18 ` Tejun Heo
2013-02-03 1:20 ` [PATCH 28/62] infiniband/mlx4: " Tejun Heo
2013-02-03 1:20 ` [PATCH 29/62] infiniband/ocrdma: " Tejun Heo
2013-02-03 1:20 ` [PATCH 30/62] infiniband/qib: " Tejun Heo
2013-02-03 1:20 ` [PATCH 31/62] dm: " Tejun Heo
2013-02-03 1:20 ` [PATCH 32/62] memstick: " Tejun Heo
2013-02-03 1:20 ` [PATCH 33/62] mfd: " Tejun Heo
2013-02-03 22:32 ` Samuel Ortiz
2013-02-03 1:20 ` [PATCH 34/62] misc/c2port: " Tejun Heo
2013-02-03 1:20 ` [PATCH 35/62] misc/tifm_core: " Tejun Heo
2013-02-03 1:20 ` [PATCH 36/62] mmc: " Tejun Heo
2013-02-03 1:20 ` [PATCH 37/62] mtd: " Tejun Heo
2013-02-04 13:09 ` Ezequiel Garcia
2013-02-03 1:20 ` [PATCH 38/62] i2c: " Tejun Heo
2013-02-03 1:25 ` [PATCH UPDATED 38/62] macvtap: " Tejun Heo
2013-02-03 1:20 ` [PATCH 39/62] ppp: " Tejun Heo
2013-02-03 1:20 ` [PATCH 40/62] power: " Tejun Heo
2013-02-03 3:46 ` Anton Vorontsov
2013-02-03 1:20 ` [PATCH 41/62] pps: " Tejun Heo
2013-02-03 1:20 ` [PATCH 42/62] remoteproc: " Tejun Heo
2013-02-03 1:20 ` [PATCH 43/62] rpmsg: " Tejun Heo
2013-02-03 1:20 ` [PATCH 44/62] scsi/bfa: " Tejun Heo
2013-02-03 1:20 ` Tejun Heo [this message]
2013-02-03 1:20 ` [PATCH 46/62] target/iscsi: " Tejun Heo
2013-02-03 1:20 ` [PATCH 47/62] scsi/lpfc: " Tejun Heo
2013-02-11 22:46 ` James Smart
2013-02-03 1:20 ` [PATCH 48/62] thermal: " Tejun Heo
2013-02-03 1:20 ` [PATCH 49/62] uio: " Tejun Heo
2013-02-03 7:05 ` Greg Kroah-Hartman
2013-02-03 1:20 ` [PATCH 50/62] vfio: " Tejun Heo
2013-02-04 16:06 ` Alex Williamson
2013-02-04 16:48 ` [PATCH v2 " Tejun Heo
2013-02-03 1:20 ` [PATCH 51/62] dlm: " Tejun Heo
2013-02-03 1:20 ` [PATCH 52/62] inotify: " Tejun Heo
2013-02-03 1:20 ` [PATCH 53/62] ocfs2: " Tejun Heo
2013-02-03 1:20 ` [PATCH 54/62] ipc: " Tejun Heo
2013-02-03 1:20 ` [PATCH 55/62] cgroup: " Tejun Heo
2013-02-04 2:49 ` Li Zefan
2013-02-03 1:20 ` [PATCH 56/62] events: " Tejun Heo
2013-02-03 1:20 ` [PATCH 57/62] posix-timers: " Tejun Heo
2013-02-03 1:20 ` [PATCH 58/62] net/9p: " Tejun Heo
2013-02-03 1:21 ` [PATCH 59/62] mac80211: " Tejun Heo
2013-02-04 17:40 ` Johannes Berg
2013-02-04 17:42 ` Tejun Heo
2013-02-03 1:21 ` [PATCH 60/62] sctp: " Tejun Heo
2013-02-03 16:55 ` Neil Horman
2013-02-04 16:22 ` Vlad Yasevich
2013-02-04 16:37 ` Tejun Heo
2013-02-04 16:42 ` [PATCH v2 " Tejun Heo
2013-02-05 15:22 ` Neil Horman
2013-02-03 1:21 ` [PATCH 61/62] nfs4client: " Tejun Heo
2013-02-03 1:21 ` [PATCH 62/62] idr: deprecate idr_pre_get() and idr_get_new[_above]() Tejun Heo
2013-02-03 13:41 ` [PATCHSET] idr: implement idr_alloc() and convert existing users Eric W. Biederman
2013-02-03 14:13 ` Tejun Heo
2013-02-03 15:24 ` Eric W. Biederman
2013-02-03 15:47 ` Tejun Heo
2013-02-03 17:02 ` J. Bruce Fields
2013-02-04 0:15 ` J. Bruce Fields
2013-02-04 17:10 ` Tejun Heo
2013-02-04 17:11 ` Tejun Heo
2013-02-04 18:15 ` J. Bruce Fields
2013-03-21 14:06 ` J. Bruce Fields
2013-03-21 18:35 ` Tejun Heo
2013-03-26 15:19 ` Jeff Layton
2013-03-26 15:26 ` Tejun Heo
2013-03-26 16:30 ` J. Bruce Fields
2013-03-26 16:33 ` Tejun Heo
2013-03-26 16:36 ` Tejun Heo
2013-03-26 16:52 ` Jeff Layton
2013-02-04 17:16 ` J. Bruce Fields
2013-02-04 19:17 ` Tejun Heo
2013-02-04 19:54 ` Marciniszyn, Mike
2013-02-04 21:42 ` Tejun Heo
2013-02-04 22:25 ` Marciniszyn, Mike
2013-02-04 20:08 ` Marciniszyn, Mike
2013-02-04 21:43 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359854463-2538-46-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bfields@fieldses.org \
--cc=ebiederm@xmission.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=skinsbursky@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).