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>
This commit is contained in:
parent
70a9755d5f
commit
b98c52b572
@ -895,7 +895,7 @@ static int ch_probe(struct device *dev)
|
|||||||
{
|
{
|
||||||
struct scsi_device *sd = to_scsi_device(dev);
|
struct scsi_device *sd = to_scsi_device(dev);
|
||||||
struct device *class_dev;
|
struct device *class_dev;
|
||||||
int minor, ret = -ENOMEM;
|
int ret;
|
||||||
scsi_changer *ch;
|
scsi_changer *ch;
|
||||||
|
|
||||||
if (sd->type != TYPE_MEDIUM_CHANGER)
|
if (sd->type != TYPE_MEDIUM_CHANGER)
|
||||||
@ -905,22 +905,19 @@ static int ch_probe(struct device *dev)
|
|||||||
if (NULL == ch)
|
if (NULL == ch)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!idr_pre_get(&ch_index_idr, GFP_KERNEL))
|
idr_preload(GFP_KERNEL);
|
||||||
goto free_ch;
|
|
||||||
|
|
||||||
spin_lock(&ch_index_lock);
|
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);
|
spin_unlock(&ch_index_lock);
|
||||||
|
idr_preload_end();
|
||||||
|
|
||||||
if (ret)
|
if (ret < 0) {
|
||||||
|
if (ret == -ENOSPC)
|
||||||
|
ret = -ENODEV;
|
||||||
goto free_ch;
|
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);
|
sprintf(ch->name,"ch%d",ch->minor);
|
||||||
|
|
||||||
class_dev = device_create(ch_sysfs_class, dev,
|
class_dev = device_create(ch_sysfs_class, dev,
|
||||||
@ -944,7 +941,7 @@ static int ch_probe(struct device *dev)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
remove_idr:
|
remove_idr:
|
||||||
idr_remove(&ch_index_idr, minor);
|
idr_remove(&ch_index_idr, ch->minor);
|
||||||
free_ch:
|
free_ch:
|
||||||
kfree(ch);
|
kfree(ch);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1391,24 +1391,23 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
|
|||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!idr_pre_get(&sg_index_idr, GFP_KERNEL)) {
|
idr_preload(GFP_KERNEL);
|
||||||
printk(KERN_WARNING "idr expansion Sg_device failure\n");
|
|
||||||
error = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
write_lock_irqsave(&sg_index_lock, iflags);
|
write_lock_irqsave(&sg_index_lock, iflags);
|
||||||
|
|
||||||
error = idr_get_new(&sg_index_idr, sdp, &k);
|
error = idr_alloc(&sg_index_idr, sdp, 0, SG_MAX_DEVS, GFP_NOWAIT);
|
||||||
if (error) {
|
if (error < 0) {
|
||||||
write_unlock_irqrestore(&sg_index_lock, iflags);
|
if (error == -ENOSPC) {
|
||||||
printk(KERN_WARNING "idr allocation Sg_device failure: %d\n",
|
sdev_printk(KERN_WARNING, scsidp,
|
||||||
error);
|
"Unable to attach sg device type=%d, minor number exceeds %d\n",
|
||||||
goto out;
|
scsidp->type, SG_MAX_DEVS - 1);
|
||||||
|
error = -ENODEV;
|
||||||
|
} else {
|
||||||
|
printk(KERN_WARNING
|
||||||
|
"idr allocation Sg_device failure: %d\n", error);
|
||||||
|
}
|
||||||
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
k = error;
|
||||||
if (unlikely(k >= SG_MAX_DEVS))
|
|
||||||
goto overflow;
|
|
||||||
|
|
||||||
SCSI_LOG_TIMEOUT(3, printk("sg_alloc: dev=%d \n", k));
|
SCSI_LOG_TIMEOUT(3, printk("sg_alloc: dev=%d \n", k));
|
||||||
sprintf(disk->disk_name, "sg%d", 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->sg_tablesize = queue_max_segments(q);
|
||||||
sdp->index = k;
|
sdp->index = k;
|
||||||
kref_init(&sdp->d_ref);
|
kref_init(&sdp->d_ref);
|
||||||
|
|
||||||
write_unlock_irqrestore(&sg_index_lock, iflags);
|
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
out:
|
|
||||||
|
out_unlock:
|
||||||
|
write_unlock_irqrestore(&sg_index_lock, iflags);
|
||||||
|
idr_preload_end();
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
kfree(sdp);
|
kfree(sdp);
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
}
|
}
|
||||||
return sdp;
|
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
|
static int
|
||||||
|
@ -4076,7 +4076,7 @@ static int st_probe(struct device *dev)
|
|||||||
struct st_modedef *STm;
|
struct st_modedef *STm;
|
||||||
struct st_partstat *STps;
|
struct st_partstat *STps;
|
||||||
struct st_buffer *buffer;
|
struct st_buffer *buffer;
|
||||||
int i, dev_num, error;
|
int i, error;
|
||||||
char *stp;
|
char *stp;
|
||||||
|
|
||||||
if (SDp->type != TYPE_TAPE)
|
if (SDp->type != TYPE_TAPE)
|
||||||
@ -4178,27 +4178,17 @@ static int st_probe(struct device *dev)
|
|||||||
tpnt->blksize_changed = 0;
|
tpnt->blksize_changed = 0;
|
||||||
mutex_init(&tpnt->lock);
|
mutex_init(&tpnt->lock);
|
||||||
|
|
||||||
if (!idr_pre_get(&st_index_idr, GFP_KERNEL)) {
|
idr_preload(GFP_KERNEL);
|
||||||
pr_warn("st: idr expansion failed\n");
|
|
||||||
error = -ENOMEM;
|
|
||||||
goto out_put_disk;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock(&st_index_lock);
|
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);
|
spin_unlock(&st_index_lock);
|
||||||
if (error) {
|
idr_preload_end();
|
||||||
|
if (error < 0) {
|
||||||
pr_warn("st: idr allocation failed: %d\n", error);
|
pr_warn("st: idr allocation failed: %d\n", error);
|
||||||
goto out_put_disk;
|
goto out_put_disk;
|
||||||
}
|
}
|
||||||
|
tpnt->index = error;
|
||||||
if (dev_num > ST_MAX_TAPES) {
|
sprintf(disk->disk_name, "st%d", tpnt->index);
|
||||||
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);
|
|
||||||
|
|
||||||
dev_set_drvdata(dev, tpnt);
|
dev_set_drvdata(dev, tpnt);
|
||||||
|
|
||||||
@ -4218,9 +4208,8 @@ static int st_probe(struct device *dev)
|
|||||||
|
|
||||||
out_remove_devs:
|
out_remove_devs:
|
||||||
remove_cdevs(tpnt);
|
remove_cdevs(tpnt);
|
||||||
out_put_index:
|
|
||||||
spin_lock(&st_index_lock);
|
spin_lock(&st_index_lock);
|
||||||
idr_remove(&st_index_idr, dev_num);
|
idr_remove(&st_index_idr, tpnt->index);
|
||||||
spin_unlock(&st_index_lock);
|
spin_unlock(&st_index_lock);
|
||||||
out_put_disk:
|
out_put_disk:
|
||||||
put_disk(disk);
|
put_disk(disk);
|
||||||
|
Loading…
Reference in New Issue
Block a user