#include <linux/blk.h>
#include <linux/devfs_fs_kernel.h>
-static struct gendisk disks[2];
+static struct gendisk *disks[2];
#define MAX_FLOPPIES 2
int swim3_init(void)
{
struct device_node *swim;
+ int err = -ENOMEM;
int i;
floppy_devfs_handle = devfs_mk_dir(NULL, "floppy", NULL);
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)
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",
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] = {
}
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;