Commit 8d3ab4eb authored by Herton Ronaldo Krzesinski's avatar Herton Ronaldo Krzesinski Committed by Jens Axboe

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: 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 d60e7ec1
...@@ -4109,12 +4109,19 @@ static struct platform_driver floppy_driver = { ...@@ -4109,12 +4109,19 @@ static struct platform_driver floppy_driver = {
static struct platform_device floppy_device[N_DRIVE]; static struct platform_device floppy_device[N_DRIVE];
static bool floppy_available(int drive)
{
if (!(allowed_drive_mask & (1 << drive)))
return false;
if (fdc_state[FDC(drive)].version == FDC_NONE)
return false;
return true;
}
static struct kobject *floppy_find(dev_t dev, int *part, void *data) static struct kobject *floppy_find(dev_t dev, int *part, void *data)
{ {
int drive = (*part & 3) | ((*part & 0x80) >> 5); int drive = (*part & 3) | ((*part & 0x80) >> 5);
if (drive >= N_DRIVE || if (drive >= N_DRIVE || !floppy_available(drive))
!(allowed_drive_mask & (1 << drive)) ||
fdc_state[FDC(drive)].version == FDC_NONE)
return NULL; return NULL;
if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type)) if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type))
return NULL; return NULL;
...@@ -4281,9 +4288,7 @@ static int __init do_floppy_init(void) ...@@ -4281,9 +4288,7 @@ static int __init do_floppy_init(void)
} }
for (drive = 0; drive < N_DRIVE; drive++) { for (drive = 0; drive < N_DRIVE; drive++) {
if (!(allowed_drive_mask & (1 << drive))) if (!floppy_available(drive))
continue;
if (fdc_state[FDC(drive)].version == FDC_NONE)
continue; continue;
floppy_device[drive].name = floppy_device_name; floppy_device[drive].name = floppy_device_name;
...@@ -4312,8 +4317,7 @@ static int __init do_floppy_init(void) ...@@ -4312,8 +4317,7 @@ static int __init do_floppy_init(void)
platform_device_unregister(&floppy_device[drive]); platform_device_unregister(&floppy_device[drive]);
out_remove_drives: out_remove_drives:
while (drive--) { while (drive--) {
if ((allowed_drive_mask & (1 << drive)) && if (floppy_available(drive)) {
fdc_state[FDC(drive)].version != FDC_NONE) {
del_gendisk(disks[drive]); del_gendisk(disks[drive]);
device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos);
platform_device_unregister(&floppy_device[drive]); platform_device_unregister(&floppy_device[drive]);
...@@ -4558,8 +4562,7 @@ static void __exit floppy_module_exit(void) ...@@ -4558,8 +4562,7 @@ static void __exit floppy_module_exit(void)
for (drive = 0; drive < N_DRIVE; drive++) { for (drive = 0; drive < N_DRIVE; drive++) {
del_timer_sync(&motor_off_timer[drive]); del_timer_sync(&motor_off_timer[drive]);
if ((allowed_drive_mask & (1 << drive)) && if (floppy_available(drive)) {
fdc_state[FDC(drive)].version != FDC_NONE) {
del_gendisk(disks[drive]); del_gendisk(disks[drive]);
device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos);
platform_device_unregister(&floppy_device[drive]); platform_device_unregister(&floppy_device[drive]);
......
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