Commit 1a4ae43e authored by Herton Ronaldo Krzesinski's avatar Herton Ronaldo Krzesinski Committed by Jens Axboe

floppy: remove dr, reuse drive on do_floppy_init

This is a small cleanup, that also may turn error handling of
unitialized disks more readable. We don't need a separate variable to
track allocated disks, remove dr and reuse drive variable instead.
Signed-off-by: default avatarHerton Ronaldo Krzesinski <herton.krzesinski@canonical.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8d3ab4eb
...@@ -4131,8 +4131,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data) ...@@ -4131,8 +4131,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
static int __init do_floppy_init(void) static int __init do_floppy_init(void)
{ {
int i, unit, drive; int i, unit, drive, err;
int err, dr;
set_debugt(); set_debugt();
interruptjiffies = resultjiffies = jiffies; interruptjiffies = resultjiffies = jiffies;
...@@ -4148,29 +4147,28 @@ static int __init do_floppy_init(void) ...@@ -4148,29 +4147,28 @@ static int __init do_floppy_init(void)
if (!floppy_wq) if (!floppy_wq)
return -ENOMEM; return -ENOMEM;
for (dr = 0; dr < N_DRIVE; dr++) { for (drive = 0; drive < N_DRIVE; drive++) {
disks[dr] = alloc_disk(1); disks[drive] = alloc_disk(1);
if (!disks[dr]) { if (!disks[drive]) {
err = -ENOMEM; err = -ENOMEM;
goto out_put_disk; goto out_put_disk;
} }
disks[dr]->queue = blk_init_queue(do_fd_request, &floppy_lock); disks[drive]->queue = blk_init_queue(do_fd_request, &floppy_lock);
if (!disks[dr]->queue) { if (!disks[drive]->queue) {
put_disk(disks[dr]);
err = -ENOMEM; err = -ENOMEM;
goto out_put_disk; goto out_put_disk;
} }
blk_queue_max_hw_sectors(disks[dr]->queue, 64); blk_queue_max_hw_sectors(disks[drive]->queue, 64);
disks[dr]->major = FLOPPY_MAJOR; disks[drive]->major = FLOPPY_MAJOR;
disks[dr]->first_minor = TOMINOR(dr); disks[drive]->first_minor = TOMINOR(drive);
disks[dr]->fops = &floppy_fops; disks[drive]->fops = &floppy_fops;
sprintf(disks[dr]->disk_name, "fd%d", dr); sprintf(disks[drive]->disk_name, "fd%d", drive);
init_timer(&motor_off_timer[dr]); init_timer(&motor_off_timer[drive]);
motor_off_timer[dr].data = dr; motor_off_timer[drive].data = drive;
motor_off_timer[dr].function = motor_off_callback; motor_off_timer[drive].function = motor_off_callback;
} }
err = register_blkdev(FLOPPY_MAJOR, "fd"); err = register_blkdev(FLOPPY_MAJOR, "fd");
...@@ -4332,17 +4330,15 @@ static int __init do_floppy_init(void) ...@@ -4332,17 +4330,15 @@ static int __init do_floppy_init(void)
out_unreg_blkdev: out_unreg_blkdev:
unregister_blkdev(FLOPPY_MAJOR, "fd"); unregister_blkdev(FLOPPY_MAJOR, "fd");
out_put_disk: out_put_disk:
while (dr--) { for (drive = 0; drive < N_DRIVE; drive++) {
del_timer_sync(&motor_off_timer[dr]); if (!disks[drive])
if (disks[dr]->queue) { break;
blk_cleanup_queue(disks[dr]->queue); if (disks[drive]->queue) {
/* del_timer_sync(&motor_off_timer[drive]);
* put_disk() is not paired with add_disk() and blk_cleanup_queue(disks[drive]->queue);
* will put queue reference one extra time. fix it. disks[drive]->queue = NULL;
*/
disks[dr]->queue = NULL;
} }
put_disk(disks[dr]); put_disk(disks[drive]);
} }
destroy_workqueue(floppy_wq); destroy_workqueue(floppy_wq);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment