]> err.no Git - linux-2.6/blobdiff - drivers/scsi/ch.c
[SCSI] ch: handle class_device_create failure properly
[linux-2.6] / drivers / scsi / ch.c
index 2311019304c00ef22ec4a8b63167a7c65c7dc488..765f2fc001aab1c68f2104b0356077208f885a66 100644 (file)
@@ -92,8 +92,7 @@ static int  ch_probe(struct device *);
 static int  ch_remove(struct device *);
 static int  ch_open(struct inode * inode, struct file * filp);
 static int  ch_release(struct inode * inode, struct file * filp);
-static int  ch_ioctl(struct inode * inode, struct file * filp,
-                    unsigned int cmd, unsigned long arg);
+static long ch_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
 #ifdef CONFIG_COMPAT
 static long ch_ioctl_compat(struct file * filp,
                            unsigned int cmd, unsigned long arg);
@@ -130,12 +129,12 @@ static struct scsi_driver ch_template =
 
 static const struct file_operations changer_fops =
 {
-       .owner        = THIS_MODULE,
-       .open         = ch_open,
-       .release      = ch_release,
-       .ioctl        = ch_ioctl,
+       .owner          = THIS_MODULE,
+       .open           = ch_open,
+       .release        = ch_release,
+       .unlocked_ioctl = ch_ioctl,
 #ifdef CONFIG_COMPAT
-       .compat_ioctl = ch_ioctl_compat,
+       .compat_ioctl   = ch_ioctl_compat,
 #endif
 };
 
@@ -626,7 +625,7 @@ ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit)
        return 0;
 }
 
-static int ch_ioctl(struct inode * inode, struct file * file,
+static long ch_ioctl(struct file *file,
                    unsigned int cmd, unsigned long arg)
 {
        scsi_changer *ch = file->private_data;
@@ -887,8 +886,7 @@ static long ch_ioctl_compat(struct file * file,
        case CHIOINITELEM:
        case CHIOSVOLTAG:
                /* compatible */
-               return ch_ioctl(NULL /* inode, unused */,
-                               file, cmd, arg);
+               return ch_ioctl(file, cmd, arg);
        case CHIOGSTATUS32:
        {
                struct changer_element_status32 ces32;
@@ -915,29 +913,37 @@ static long ch_ioctl_compat(struct file * file,
 static int ch_probe(struct device *dev)
 {
        struct scsi_device *sd = to_scsi_device(dev);
+       struct class_device *class_dev;
        scsi_changer *ch;
-       
+
        if (sd->type != TYPE_MEDIUM_CHANGER)
                return -ENODEV;
-    
+
        ch = kzalloc(sizeof(*ch), GFP_KERNEL);
        if (NULL == ch)
                return -ENOMEM;
 
        ch->minor = ch_devcount;
        sprintf(ch->name,"ch%d",ch->minor);
+
+       class_dev = class_device_create(ch_sysfs_class, NULL,
+                                       MKDEV(SCSI_CHANGER_MAJOR, ch->minor),
+                                       dev, "s%s", ch->name);
+       if (IS_ERR(class_dev)) {
+               printk(KERN_WARNING "ch%d: class_device_create failed\n",
+                      ch->minor);
+               kfree(ch);
+               return PTR_ERR(class_dev);
+       }
+
        mutex_init(&ch->lock);
        ch->device = sd;
        ch_readconfig(ch);
        if (init)
                ch_init_elem(ch);
 
-       class_device_create(ch_sysfs_class, NULL,
-                           MKDEV(SCSI_CHANGER_MAJOR,ch->minor),
-                           dev, "s%s", ch->name);
-
        sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name);
-       
+
        spin_lock(&ch_devlist_lock);
        list_add_tail(&ch->list,&ch_devlist);
        ch_devcount++;