diff options
Diffstat (limited to 'drivers/block/floppy.c')
-rw-r--r-- | drivers/block/floppy.c | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 17c675c52295..1c49d7173966 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c | |||
@@ -4109,12 +4109,19 @@ static struct platform_driver floppy_driver = { | |||
4109 | 4109 | ||
4110 | static struct platform_device floppy_device[N_DRIVE]; | 4110 | static struct platform_device floppy_device[N_DRIVE]; |
4111 | 4111 | ||
4112 | static bool floppy_available(int drive) | ||
4113 | { | ||
4114 | if (!(allowed_drive_mask & (1 << drive))) | ||
4115 | return false; | ||
4116 | if (fdc_state[FDC(drive)].version == FDC_NONE) | ||
4117 | return false; | ||
4118 | return true; | ||
4119 | } | ||
4120 | |||
4112 | static struct kobject *floppy_find(dev_t dev, int *part, void *data) | 4121 | static struct kobject *floppy_find(dev_t dev, int *part, void *data) |
4113 | { | 4122 | { |
4114 | int drive = (*part & 3) | ((*part & 0x80) >> 5); | 4123 | int drive = (*part & 3) | ((*part & 0x80) >> 5); |
4115 | if (drive >= N_DRIVE || | 4124 | if (drive >= N_DRIVE || !floppy_available(drive)) |
4116 | !(allowed_drive_mask & (1 << drive)) || | ||
4117 | fdc_state[FDC(drive)].version == FDC_NONE) | ||
4118 | return NULL; | 4125 | return NULL; |
4119 | if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type)) | 4126 | if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type)) |
4120 | return NULL; | 4127 | return NULL; |
@@ -4124,8 +4131,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data) | |||
4124 | 4131 | ||
4125 | static int __init do_floppy_init(void) | 4132 | static int __init do_floppy_init(void) |
4126 | { | 4133 | { |
4127 | int i, unit, drive; | 4134 | int i, unit, drive, err; |
4128 | int err, dr; | ||
4129 | 4135 | ||
4130 | set_debugt(); | 4136 | set_debugt(); |
4131 | interruptjiffies = resultjiffies = jiffies; | 4137 | interruptjiffies = resultjiffies = jiffies; |
@@ -4137,34 +4143,32 @@ static int __init do_floppy_init(void) | |||
4137 | 4143 | ||
4138 | raw_cmd = NULL; | 4144 | raw_cmd = NULL; |
4139 | 4145 | ||
4140 | for (dr = 0; dr < N_DRIVE; dr++) { | 4146 | floppy_wq = alloc_ordered_workqueue("floppy", 0); |
4141 | disks[dr] = alloc_disk(1); | 4147 | if (!floppy_wq) |
4142 | if (!disks[dr]) { | 4148 | return -ENOMEM; |
4143 | err = -ENOMEM; | ||
4144 | goto out_put_disk; | ||
4145 | } | ||
4146 | 4149 | ||
4147 | floppy_wq = alloc_ordered_workqueue("floppy", 0); | 4150 | for (drive = 0; drive < N_DRIVE; drive++) { |
4148 | if (!floppy_wq) { | 4151 | disks[drive] = alloc_disk(1); |
4152 | if (!disks[drive]) { | ||
4149 | err = -ENOMEM; | 4153 | err = -ENOMEM; |
4150 | goto out_put_disk; | 4154 | goto out_put_disk; |
4151 | } | 4155 | } |
4152 | 4156 | ||
4153 | disks[dr]->queue = blk_init_queue(do_fd_request, &floppy_lock); | 4157 | disks[drive]->queue = blk_init_queue(do_fd_request, &floppy_lock); |
4154 | if (!disks[dr]->queue) { | 4158 | if (!disks[drive]->queue) { |
4155 | err = -ENOMEM; | 4159 | err = -ENOMEM; |
4156 | goto out_destroy_workq; | 4160 | goto out_put_disk; |
4157 | } | 4161 | } |
4158 | 4162 | ||
4159 | blk_queue_max_hw_sectors(disks[dr]->queue, 64); | 4163 | blk_queue_max_hw_sectors(disks[drive]->queue, 64); |
4160 | disks[dr]->major = FLOPPY_MAJOR; | 4164 | disks[drive]->major = FLOPPY_MAJOR; |
4161 | disks[dr]->first_minor = TOMINOR(dr); | 4165 | disks[drive]->first_minor = TOMINOR(drive); |
4162 | disks[dr]->fops = &floppy_fops; | 4166 | disks[drive]->fops = &floppy_fops; |
4163 | sprintf(disks[dr]->disk_name, "fd%d", dr); | 4167 | sprintf(disks[drive]->disk_name, "fd%d", drive); |
4164 | 4168 | ||
4165 | init_timer(&motor_off_timer[dr]); | 4169 | init_timer(&motor_off_timer[drive]); |
4166 | motor_off_timer[dr].data = dr; | 4170 | motor_off_timer[drive].data = drive; |
4167 | motor_off_timer[dr].function = motor_off_callback; | 4171 | motor_off_timer[drive].function = motor_off_callback; |
4168 | } | 4172 | } |
4169 | 4173 | ||
4170 | err = register_blkdev(FLOPPY_MAJOR, "fd"); | 4174 | err = register_blkdev(FLOPPY_MAJOR, "fd"); |
@@ -4282,9 +4286,7 @@ static int __init do_floppy_init(void) | |||
4282 | } | 4286 | } |
4283 | 4287 | ||
4284 | for (drive = 0; drive < N_DRIVE; drive++) { | 4288 | for (drive = 0; drive < N_DRIVE; drive++) { |
4285 | if (!(allowed_drive_mask & (1 << drive))) | 4289 | if (!floppy_available(drive)) |
4286 | continue; | ||
4287 | if (fdc_state[FDC(drive)].version == FDC_NONE) | ||
4288 | continue; | 4290 | continue; |
4289 | 4291 | ||
4290 | floppy_device[drive].name = floppy_device_name; | 4292 | floppy_device[drive].name = floppy_device_name; |
@@ -4293,7 +4295,7 @@ static int __init do_floppy_init(void) | |||
4293 | 4295 | ||
4294 | err = platform_device_register(&floppy_device[drive]); | 4296 | err = platform_device_register(&floppy_device[drive]); |
4295 | if (err) | 4297 | if (err) |
4296 | goto out_release_dma; | 4298 | goto out_remove_drives; |
4297 | 4299 | ||
4298 | err = device_create_file(&floppy_device[drive].dev, | 4300 | err = device_create_file(&floppy_device[drive].dev, |
4299 | &dev_attr_cmos); | 4301 | &dev_attr_cmos); |
@@ -4311,29 +4313,34 @@ static int __init do_floppy_init(void) | |||
4311 | 4313 | ||
4312 | out_unreg_platform_dev: | 4314 | out_unreg_platform_dev: |
4313 | platform_device_unregister(&floppy_device[drive]); | 4315 | platform_device_unregister(&floppy_device[drive]); |
4316 | out_remove_drives: | ||
4317 | while (drive--) { | ||
4318 | if (floppy_available(drive)) { | ||
4319 | del_gendisk(disks[drive]); | ||
4320 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); | ||
4321 | platform_device_unregister(&floppy_device[drive]); | ||
4322 | } | ||
4323 | } | ||
4314 | out_release_dma: | 4324 | out_release_dma: |
4315 | if (atomic_read(&usage_count)) | 4325 | if (atomic_read(&usage_count)) |
4316 | floppy_release_irq_and_dma(); | 4326 | floppy_release_irq_and_dma(); |
4317 | out_unreg_region: | 4327 | out_unreg_region: |
4318 | blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); | 4328 | blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); |
4319 | platform_driver_unregister(&floppy_driver); | 4329 | platform_driver_unregister(&floppy_driver); |
4320 | out_destroy_workq: | ||
4321 | destroy_workqueue(floppy_wq); | ||
4322 | out_unreg_blkdev: | 4330 | out_unreg_blkdev: |
4323 | unregister_blkdev(FLOPPY_MAJOR, "fd"); | 4331 | unregister_blkdev(FLOPPY_MAJOR, "fd"); |
4324 | out_put_disk: | 4332 | out_put_disk: |
4325 | while (dr--) { | 4333 | for (drive = 0; drive < N_DRIVE; drive++) { |
4326 | del_timer_sync(&motor_off_timer[dr]); | 4334 | if (!disks[drive]) |
4327 | if (disks[dr]->queue) { | 4335 | break; |
4328 | blk_cleanup_queue(disks[dr]->queue); | 4336 | if (disks[drive]->queue) { |
4329 | /* | 4337 | del_timer_sync(&motor_off_timer[drive]); |
4330 | * put_disk() is not paired with add_disk() and | 4338 | blk_cleanup_queue(disks[drive]->queue); |
4331 | * will put queue reference one extra time. fix it. | 4339 | disks[drive]->queue = NULL; |
4332 | */ | ||
4333 | disks[dr]->queue = NULL; | ||
4334 | } | 4340 | } |
4335 | put_disk(disks[dr]); | 4341 | put_disk(disks[drive]); |
4336 | } | 4342 | } |
4343 | destroy_workqueue(floppy_wq); | ||
4337 | return err; | 4344 | return err; |
4338 | } | 4345 | } |
4339 | 4346 | ||
@@ -4551,8 +4558,7 @@ static void __exit floppy_module_exit(void) | |||
4551 | for (drive = 0; drive < N_DRIVE; drive++) { | 4558 | for (drive = 0; drive < N_DRIVE; drive++) { |
4552 | del_timer_sync(&motor_off_timer[drive]); | 4559 | del_timer_sync(&motor_off_timer[drive]); |
4553 | 4560 | ||
4554 | if ((allowed_drive_mask & (1 << drive)) && | 4561 | if (floppy_available(drive)) { |
4555 | fdc_state[FDC(drive)].version != FDC_NONE) { | ||
4556 | del_gendisk(disks[drive]); | 4562 | del_gendisk(disks[drive]); |
4557 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); | 4563 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); |
4558 | platform_device_unregister(&floppy_device[drive]); | 4564 | platform_device_unregister(&floppy_device[drive]); |