aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-02-27 20:04:42 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:18 -0500
commitb98c52b5721f5d88cd9b18aaf532049b44f7815a (patch)
treed7e218596f509dab3bf96eedebfc509a1af06b35
parent70a9755d5fe71d9ecf3010c5c345449378fb0898 (diff)
scsi: convert to idr_alloc()
Convert to the much saner new idr interface. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/scsi/ch.c21
-rw-r--r--drivers/scsi/sg.c43
-rw-r--r--drivers/scsi/st.c27
3 files changed, 34 insertions, 57 deletions
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index a15474eef5f7..2a323742ce04 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -895,7 +895,7 @@ static int ch_probe(struct device *dev)
895{ 895{
896 struct scsi_device *sd = to_scsi_device(dev); 896 struct scsi_device *sd = to_scsi_device(dev);
897 struct device *class_dev; 897 struct device *class_dev;
898 int minor, ret = -ENOMEM; 898 int ret;
899 scsi_changer *ch; 899 scsi_changer *ch;
900 900
901 if (sd->type != TYPE_MEDIUM_CHANGER) 901 if (sd->type != TYPE_MEDIUM_CHANGER)
@@ -905,22 +905,19 @@ static int ch_probe(struct device *dev)
905 if (NULL == ch) 905 if (NULL == ch)
906 return -ENOMEM; 906 return -ENOMEM;
907 907
908 if (!idr_pre_get(&ch_index_idr, GFP_KERNEL)) 908 idr_preload(GFP_KERNEL);
909 goto free_ch;
910
911 spin_lock(&ch_index_lock); 909 spin_lock(&ch_index_lock);
912 ret = idr_get_new(&ch_index_idr, ch, &minor); 910 ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
913 spin_unlock(&ch_index_lock); 911 spin_unlock(&ch_index_lock);
912 idr_preload_end();
914 913
915 if (ret) 914 if (ret < 0) {
915 if (ret == -ENOSPC)
916 ret = -ENODEV;
916 goto free_ch; 917 goto free_ch;
917
918 if (minor > CH_MAX_DEVS) {
919 ret = -ENODEV;
920 goto remove_idr;
921 } 918 }
922 919
923 ch->minor = minor; 920 ch->minor = ret;
924 sprintf(ch->name,"ch%d",ch->minor); 921 sprintf(ch->name,"ch%d",ch->minor);
925 922
926 class_dev = device_create(ch_sysfs_class, dev, 923 class_dev = device_create(ch_sysfs_class, dev,
@@ -944,7 +941,7 @@ static int ch_probe(struct device *dev)
944 941
945 return 0; 942 return 0;
946remove_idr: 943remove_idr:
947 idr_remove(&ch_index_idr, minor); 944 idr_remove(&ch_index_idr, ch->minor);
948free_ch: 945free_ch:
949 kfree(ch); 946 kfree(ch);
950 return ret; 947 return ret;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index be2c9a6561ff..9f0c46547459 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)
1391 return ERR_PTR(-ENOMEM); 1391 return ERR_PTR(-ENOMEM);
1392 } 1392 }
1393 1393
1394 if (!idr_pre_get(&sg_index_idr, GFP_KERNEL)) { 1394 idr_preload(GFP_KERNEL);
1395 printk(KERN_WARNING "idr expansion Sg_device failure\n");
1396 error = -ENOMEM;
1397 goto out;
1398 }
1399
1400 write_lock_irqsave(&sg_index_lock, iflags); 1395 write_lock_irqsave(&sg_index_lock, iflags);
1401 1396
1402 error = idr_get_new(&sg_index_idr, sdp, &k); 1397 error = idr_alloc(&sg_index_idr, sdp, 0, SG_MAX_DEVS, GFP_NOWAIT);
1403 if (error) { 1398 if (error < 0) {
1404 write_unlock_irqrestore(&sg_index_lock, iflags); 1399 if (error == -ENOSPC) {
1405 printk(KERN_WARNING "idr allocation Sg_device failure: %d\n", 1400 sdev_printk(KERN_WARNING, scsidp,
1406 error); 1401 "Unable to attach sg device type=%d, minor number exceeds %d\n",
1407 goto out; 1402 scsidp->type, SG_MAX_DEVS - 1);
1403 error = -ENODEV;
1404 } else {
1405 printk(KERN_WARNING
1406 "idr allocation Sg_device failure: %d\n", error);
1407 }
1408 goto out_unlock;
1408 } 1409 }
1409 1410 k = error;
1410 if (unlikely(k >= SG_MAX_DEVS))
1411 goto overflow;
1412 1411
1413 SCSI_LOG_TIMEOUT(3, printk("sg_alloc: dev=%d \n", k)); 1412 SCSI_LOG_TIMEOUT(3, printk("sg_alloc: dev=%d \n", k));
1414 sprintf(disk->disk_name, "sg%d", k); 1413 sprintf(disk->disk_name, "sg%d", k);
@@ -1420,25 +1419,17 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
1420 sdp->sg_tablesize = queue_max_segments(q); 1419 sdp->sg_tablesize = queue_max_segments(q);
1421 sdp->index = k; 1420 sdp->index = k;
1422 kref_init(&sdp->d_ref); 1421 kref_init(&sdp->d_ref);
1422 error = 0;
1423 1423
1424out_unlock:
1424 write_unlock_irqrestore(&sg_index_lock, iflags); 1425 write_unlock_irqrestore(&sg_index_lock, iflags);
1426 idr_preload_end();
1425 1427
1426 error = 0;
1427 out:
1428 if (error) { 1428 if (error) {
1429 kfree(sdp); 1429 kfree(sdp);
1430 return ERR_PTR(error); 1430 return ERR_PTR(error);
1431 } 1431 }
1432 return sdp; 1432 return sdp;
1433
1434 overflow:
1435 idr_remove(&sg_index_idr, k);
1436 write_unlock_irqrestore(&sg_index_lock, iflags);
1437 sdev_printk(KERN_WARNING, scsidp,
1438 "Unable to attach sg device type=%d, minor "
1439 "number exceeds %d\n", scsidp->type, SG_MAX_DEVS - 1);
1440 error = -ENODEV;
1441 goto out;
1442} 1433}
1443 1434
1444static int 1435static int
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 3e2b3717cb5c..86974471af68 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4076,7 +4076,7 @@ static int st_probe(struct device *dev)
4076 struct st_modedef *STm; 4076 struct st_modedef *STm;
4077 struct st_partstat *STps; 4077 struct st_partstat *STps;
4078 struct st_buffer *buffer; 4078 struct st_buffer *buffer;
4079 int i, dev_num, error; 4079 int i, error;
4080 char *stp; 4080 char *stp;
4081 4081
4082 if (SDp->type != TYPE_TAPE) 4082 if (SDp->type != TYPE_TAPE)
@@ -4178,27 +4178,17 @@ static int st_probe(struct device *dev)
4178 tpnt->blksize_changed = 0; 4178 tpnt->blksize_changed = 0;
4179 mutex_init(&tpnt->lock); 4179 mutex_init(&tpnt->lock);
4180 4180
4181 if (!idr_pre_get(&st_index_idr, GFP_KERNEL)) { 4181 idr_preload(GFP_KERNEL);
4182 pr_warn("st: idr expansion failed\n");
4183 error = -ENOMEM;
4184 goto out_put_disk;
4185 }
4186
4187 spin_lock(&st_index_lock); 4182 spin_lock(&st_index_lock);
4188 error = idr_get_new(&st_index_idr, tpnt, &dev_num); 4183 error = idr_alloc(&st_index_idr, tpnt, 0, ST_MAX_TAPES + 1, GFP_NOWAIT);
4189 spin_unlock(&st_index_lock); 4184 spin_unlock(&st_index_lock);
4190 if (error) { 4185 idr_preload_end();
4186 if (error < 0) {
4191 pr_warn("st: idr allocation failed: %d\n", error); 4187 pr_warn("st: idr allocation failed: %d\n", error);
4192 goto out_put_disk; 4188 goto out_put_disk;
4193 } 4189 }
4194 4190 tpnt->index = error;
4195 if (dev_num > ST_MAX_TAPES) { 4191 sprintf(disk->disk_name, "st%d", tpnt->index);
4196 pr_err("st: Too many tape devices (max. %d).\n", ST_MAX_TAPES);
4197 goto out_put_index;
4198 }
4199
4200 tpnt->index = dev_num;
4201 sprintf(disk->disk_name, "st%d", dev_num);
4202 4192
4203 dev_set_drvdata(dev, tpnt); 4193 dev_set_drvdata(dev, tpnt);
4204 4194
@@ -4218,9 +4208,8 @@ static int st_probe(struct device *dev)
4218 4208
4219out_remove_devs: 4209out_remove_devs:
4220 remove_cdevs(tpnt); 4210 remove_cdevs(tpnt);
4221out_put_index:
4222 spin_lock(&st_index_lock); 4211 spin_lock(&st_index_lock);
4223 idr_remove(&st_index_idr, dev_num); 4212 idr_remove(&st_index_idr, tpnt->index);
4224 spin_unlock(&st_index_lock); 4213 spin_unlock(&st_index_lock);
4225out_put_disk: 4214out_put_disk:
4226 put_disk(disk); 4215 put_disk(disk);