]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] swim* switched to alloc_disk()
authorAlexander Viro <viro@math.psu.edu>
Sat, 5 Oct 2002 11:22:31 +0000 (04:22 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Sat, 5 Oct 2002 11:22:31 +0000 (04:22 -0700)
drivers/block/swim3.c
drivers/block/swim_iop.c

index e7bd23ef64d9d5c7161a2d1c384fc159ef0d7771..b1cb36f3ca5c3844208e37c5acc8e510de41f4ca 100644 (file)
@@ -38,7 +38,7 @@
 #include <linux/blk.h>
 #include <linux/devfs_fs_kernel.h>
 
-static struct gendisk disks[2];
+static struct gendisk *disks[2];
 
 #define MAX_FLOPPIES   2
 
@@ -1014,6 +1014,7 @@ static devfs_handle_t floppy_devfs_handle;
 int swim3_init(void)
 {
        struct device_node *swim;
+       int err = -ENOMEM;
        int i;
 
        floppy_devfs_handle = devfs_mk_dir(NULL, "floppy", NULL);
@@ -1032,26 +1033,37 @@ int swim3_init(void)
                swim = swim->next;
        }
 
-       if (floppy_count > 0)
-       {
-               if (register_blkdev(MAJOR_NR, "fd", &floppy_fops)) {
-                       printk(KERN_ERR "Unable to get major %d for floppy\n",
-                              MAJOR_NR);
-                       return -EBUSY;
-               }
-               blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), do_fd_request, &swim3_lock);
-               for (i = 0; i < floppy_count; i++) {
-                       struct gendisk *disk = disks + i;
-                       disk->major = MAJOR_NR;
-                       disk->first_minor = i;
-                       disk->fops = &floppy_fops;
-                       sprintf(disk->disk_name, "fd%d", i);
-                       set_capacity(disk, 2880);
-                       add_disk(disk);
-               }
+       if (!floppy_count)
+               return -ENODEV;
+
+       for (i = 0; i < floppy_count; i++) {
+               disks[i] = alloc_disk();
+               if (!disks[i])
+                       goto out;
        }
 
+       if (register_blkdev(MAJOR_NR, "fd", &floppy_fops)) {
+               printk(KERN_ERR"Unable to get major %d for floppy\n", MAJOR_NR);
+               err = -EBUSY;
+               goto out;
+       }
+       blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), do_fd_request, &swim3_lock);
+       for (i = 0; i < floppy_count; i++) {
+               struct gendisk *disk = disks[i];
+               disk->major = MAJOR_NR;
+               disk->first_minor = i;
+               disk->fops = &floppy_fops;
+               sprintf(disk->disk_name, "fd%d", i);
+               set_capacity(disk, 2880);
+               add_disk(disk);
+       }
        return 0;
+
+out:
+       while (i--)
+               put_disk(disks[i]);
+       /* shouldn't we do something with results of swim_add_device()? */
+       return err;
 }
 
 static int swim3_add_device(struct device_node *swim)
@@ -1118,8 +1130,6 @@ static int swim3_add_device(struct device_node *swim)
 
        init_timer(&fs->timeout);
 
-       do_floppy = NULL;
-
        printk(KERN_INFO "fd%d: SWIM3 floppy controller %s\n", floppy_count,
                mediabay ? "in media bay" : "");
        sprintf(floppy_name, "%s%d", floppy_devfs_handle ? "" : "floppy",
index 99687652bf1017f102cca81b5450c2b5b1bc37f4..29c2f16960636d3c436258c497412e84083846c5 100644 (file)
@@ -82,9 +82,6 @@ static struct swim_iop_req *current_req;
 static int floppy_count;
 
 static struct floppy_state floppy_states[MAX_FLOPPIES];
-
-static struct gendisk disks[2];
-
 static spinlock_t swim_iop_lock = SPIN_LOCK_UNLOCKED;
 
 static char *drive_names[7] = {
@@ -190,9 +187,10 @@ int swimiop_init(void)
        }
        printk("SWIM-IOP: detected %d installed drives.\n", floppy_count);
 
-       do_floppy = NULL;
        for (i = 0; i < floppy_count; i++) {
-               struct gendisk *disk = disks + i;
+               struct gendisk *disk = alloc_disk();
+               if (!disk)
+                       continue;
                disk->major = MAJOR_NR;
                disk->first_minor = i;
                disk->fops = &floppy_fops;