aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ch.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/ch.c')
-rw-r--r--drivers/scsi/ch.c21
1 files changed, 9 insertions, 12 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;