diff options
author | Herton Ronaldo Krzesinski <herton.krzesinski@canonical.com> | 2012-08-27 19:56:55 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-10-30 03:34:25 -0400 |
commit | 8d3ab4ebfd7435bc248873de47d0ca23076c4973 (patch) | |
tree | 7e042c6419e63f9c4ec19de6bacde87450164976 | |
parent | d60e7ec18c3fb2cbf90969ccd42889eb2d03aef9 (diff) |
floppy: use common function to check if floppies can be registered
The same checks to see if a drive can be or is registered are
repeated through the code, factor out the checks in a common function
and replace the repeated checks with it.
Signed-off-by: Herton Ronaldo Krzesinski <herton.krzesinski@canonical.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | drivers/block/floppy.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 2c7257334b64..d54b234a1a67 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; |
@@ -4281,9 +4288,7 @@ static int __init do_floppy_init(void) | |||
4281 | } | 4288 | } |
4282 | 4289 | ||
4283 | for (drive = 0; drive < N_DRIVE; drive++) { | 4290 | for (drive = 0; drive < N_DRIVE; drive++) { |
4284 | if (!(allowed_drive_mask & (1 << drive))) | 4291 | if (!floppy_available(drive)) |
4285 | continue; | ||
4286 | if (fdc_state[FDC(drive)].version == FDC_NONE) | ||
4287 | continue; | 4292 | continue; |
4288 | 4293 | ||
4289 | floppy_device[drive].name = floppy_device_name; | 4294 | floppy_device[drive].name = floppy_device_name; |
@@ -4312,8 +4317,7 @@ out_unreg_platform_dev: | |||
4312 | platform_device_unregister(&floppy_device[drive]); | 4317 | platform_device_unregister(&floppy_device[drive]); |
4313 | out_remove_drives: | 4318 | out_remove_drives: |
4314 | while (drive--) { | 4319 | while (drive--) { |
4315 | if ((allowed_drive_mask & (1 << drive)) && | 4320 | if (floppy_available(drive)) { |
4316 | fdc_state[FDC(drive)].version != FDC_NONE) { | ||
4317 | del_gendisk(disks[drive]); | 4321 | del_gendisk(disks[drive]); |
4318 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); | 4322 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); |
4319 | platform_device_unregister(&floppy_device[drive]); | 4323 | platform_device_unregister(&floppy_device[drive]); |
@@ -4558,8 +4562,7 @@ static void __exit floppy_module_exit(void) | |||
4558 | for (drive = 0; drive < N_DRIVE; drive++) { | 4562 | for (drive = 0; drive < N_DRIVE; drive++) { |
4559 | del_timer_sync(&motor_off_timer[drive]); | 4563 | del_timer_sync(&motor_off_timer[drive]); |
4560 | 4564 | ||
4561 | if ((allowed_drive_mask & (1 << drive)) && | 4565 | if (floppy_available(drive)) { |
4562 | fdc_state[FDC(drive)].version != FDC_NONE) { | ||
4563 | del_gendisk(disks[drive]); | 4566 | del_gendisk(disks[drive]); |
4564 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); | 4567 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); |
4565 | platform_device_unregister(&floppy_device[drive]); | 4568 | platform_device_unregister(&floppy_device[drive]); |