Commit 2923c262 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] move media_type checks from ide_scan_devices() to ->reinit

Checks for media type, ->driver_req, etc.  are moved from the
ide_scan_devices() to ->reinit().  ide_scan_devices() had lost first two
arguments (it will completely disappear later).
parent 06330ca4
......@@ -3104,17 +3104,32 @@ int ide_cdrom_reinit (ide_drive_t *drive)
struct cdrom_info *info;
MOD_INC_USE_COUNT;
if (!strstr("ide-cdrom", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_cdrom)
goto failed;
/* skip drives that we were told to ignore */
if (ignore != NULL) {
if (strstr(ignore, drive->name)) {
printk("ide-cd: ignoring drive %s\n", drive->name);
goto failed;
}
}
if (drive->scsi) {
printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
goto failed;
}
info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL);
if (info == NULL) {
printk ("%s: Can't allocate a cdrom structure\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if (ide_register_subdriver (drive, &ide_cdrom_driver, IDE_SUBDRIVER_VERSION)) {
printk ("%s: Failed to register the driver with ide.c\n", drive->name);
kfree (info);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
memset (info, 0, sizeof (struct cdrom_info));
drive->driver_data = info;
......@@ -3123,12 +3138,14 @@ int ide_cdrom_reinit (ide_drive_t *drive)
DRIVER(drive)->busy--;
if (ide_cdrom_cleanup (drive))
printk ("%s: ide_cdrom_cleanup failed in ide_cdrom_init\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
static void __exit ide_cdrom_exit(void)
......@@ -3136,7 +3153,7 @@ static void __exit ide_cdrom_exit(void)
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, &ide_cdrom_driver, failed)) != NULL)
while ((drive = ide_scan_devices (&ide_cdrom_driver, failed)) != NULL)
if (ide_cdrom_cleanup (drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++;
......@@ -3150,18 +3167,7 @@ int ide_cdrom_init(void)
int failed = 0;
MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, NULL, failed++)) != NULL) {
/* skip drives that we were told to ignore */
if (ignore != NULL) {
if (strstr(ignore, drive->name)) {
printk("ide-cd: ignoring drive %s\n", drive->name);
continue;
}
}
if (drive->scsi) {
printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
continue;
}
while ((drive = ide_scan_devices (NULL, failed++)) != NULL) {
if (ide_cdrom_reinit(drive))
continue;
failed--;
......
......@@ -1686,11 +1686,17 @@ MODULE_DESCRIPTION("ATA DISK Driver");
int idedisk_reinit(ide_drive_t *drive)
{
MOD_INC_USE_COUNT;
/* strstr("foo", "") is non-NULL */
if (!strstr("ide-disk", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_disk)
goto failed;
if (ide_register_subdriver (drive, &idedisk_driver, IDE_SUBDRIVER_VERSION)) {
printk (KERN_ERR "ide-disk: %s: Failed to register the driver with ide.c\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
DRIVER(drive)->busy++;
idedisk_setup(drive);
......@@ -1699,12 +1705,14 @@ int idedisk_reinit(ide_drive_t *drive)
drive->name, drive->head);
(void) idedisk_cleanup(drive);
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
static void __exit idedisk_exit (void)
......@@ -1712,7 +1720,7 @@ static void __exit idedisk_exit (void)
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices (ide_disk, idedisk_driver.name, &idedisk_driver, failed)) != NULL) {
while ((drive = ide_scan_devices(&idedisk_driver, failed)) != NULL) {
if (idedisk_cleanup (drive)) {
printk (KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
failed++;
......@@ -1733,7 +1741,7 @@ int idedisk_init (void)
int failed = 0;
MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_disk, idedisk_driver.name, NULL, failed++)) != NULL) {
while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idedisk_reinit(drive))
continue;
failed--;
......
......@@ -2196,32 +2196,37 @@ int idefloppy_reinit (ide_drive_t *drive)
{
idefloppy_floppy_t *floppy;
MOD_INC_USE_COUNT;
if (!strstr("ide-floppy", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_floppy)
goto failed;
if (!idefloppy_identify_device (drive, drive->id)) {
printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if (drive->scsi) {
printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if ((floppy = (idefloppy_floppy_t *) kmalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if (ide_register_subdriver (drive, &idefloppy_driver, IDE_SUBDRIVER_VERSION)) {
printk (KERN_ERR "ide-floppy: %s: Failed to register the driver with ide.c\n", drive->name);
kfree (floppy);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
......@@ -2231,7 +2236,7 @@ static void __exit idefloppy_exit (void)
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, &idefloppy_driver, failed)) != NULL) {
while ((drive = ide_scan_devices(&idefloppy_driver, failed)) != NULL) {
if (idefloppy_cleanup (drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++;
......@@ -2256,7 +2261,7 @@ int idefloppy_init (void)
printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, NULL, failed++)) != NULL) {
while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idefloppy_reinit(drive))
continue;
failed--;
......
......@@ -6372,31 +6372,33 @@ int idetape_reinit (ide_drive_t *drive)
int minor;
MOD_INC_USE_COUNT;
if (!strstr("ide-tape", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_tape)
goto failed;
if (!idetape_identify_device (drive, drive->id)) {
printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if (drive->scsi) {
if (strstr(drive->id->model, "OnStream DI-")) {
printk("ide-tape: ide-scsi emulation is not supported for %s.\n", drive->id->model);
} else {
printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
}
tape = (idetape_tape_t *) kmalloc (sizeof (idetape_tape_t), GFP_KERNEL);
if (tape == NULL) {
printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if (ide_register_subdriver (drive, &idetape_driver, IDE_SUBDRIVER_VERSION)) {
printk(KERN_ERR "ide-tape: %s: Failed to register the driver with ide.c\n", drive->name);
kfree(tape);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
for (minor = 0; idetape_chrdevs[minor].drive != NULL; minor++)
;
......@@ -6415,6 +6417,9 @@ int idetape_reinit (ide_drive_t *drive)
devfs_register_tape(tape->de_r);
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
......@@ -6452,7 +6457,7 @@ int idetape_init (void)
idetape_chrdevs[minor].drive = NULL;
}
while ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++))) {
while ((drive = ide_scan_devices(NULL, failed++))) {
if (idetape_reinit(drive))
continue;
supported++;
......
......@@ -3535,7 +3535,7 @@ static void setup_driver_defaults (ide_drive_t *drive)
if (d->reinit == NULL) d->reinit = default_reinit;
}
ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *driver, int n)
ide_drive_t *ide_scan_devices(ide_driver_t *driver, int n)
{
unsigned int unit, index, i;
......@@ -3545,10 +3545,7 @@ ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *drive
continue;
for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit];
char *req = drive->driver_req;
if (*req && !strstr(name, req))
continue;
if (drive->present && drive->media == media && drive->driver == driver && ++i > n)
if (drive->driver == driver && ++i > n)
return drive;
}
}
......
......@@ -583,23 +583,30 @@ static int idescsi_reinit(ide_drive_t *drive)
int id;
MOD_INC_USE_COUNT;
if (!strstr("ide-scsi", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
/* we accept everything except ide-disk */
if (drive->media == ide_disk)
goto failed;
if ((scsi = (idescsi_scsi_t *) kmalloc (sizeof (idescsi_scsi_t), GFP_KERNEL)) == NULL) {
printk (KERN_ERR "ide-scsi: %s: Can't allocate a scsi structure\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
if (ide_register_subdriver (drive, &idescsi_driver, IDE_SUBDRIVER_VERSION)) {
printk (KERN_ERR "ide-scsi: %s: Failed to register the driver with ide.c\n", drive->name);
kfree (scsi);
MOD_DEC_USE_COUNT;
return 1;
goto failed;
}
for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
;
idescsi_setup (drive, scsi, id);
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
/*
......@@ -608,7 +615,6 @@ static int idescsi_reinit(ide_drive_t *drive)
int idescsi_init (void)
{
ide_drive_t *drive;
byte media[] = {TYPE_DISK, TYPE_TAPE, TYPE_PROCESSOR, TYPE_WORM, TYPE_ROM, TYPE_SCANNER, TYPE_MOD, 255};
int i, failed;
if (idescsi_initialized)
......@@ -617,13 +623,11 @@ int idescsi_init (void)
for (i = 0; i < MAX_HWIFS * MAX_DRIVES; i++)
idescsi_drives[i] = NULL;
MOD_INC_USE_COUNT;
for (i = 0; media[i] != 255; i++) {
failed = 0;
while ((drive = ide_scan_devices (media[i], idescsi_driver.name, NULL, failed++)) != NULL) {
if (idescsi_reinit(drive))
continue;
failed--;
}
failed = 0;
while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idescsi_reinit(drive))
continue;
failed--;
}
ide_register_module(&idescsi_module);
MOD_DEC_USE_COUNT;
......@@ -883,18 +887,15 @@ static int __init init_idescsi_module(void)
static void __exit exit_idescsi_module(void)
{
ide_drive_t *drive;
byte media[] = {TYPE_DISK, TYPE_TAPE, TYPE_PROCESSOR, TYPE_WORM, TYPE_ROM, TYPE_SCANNER, TYPE_MOD, 255};
int i, failed;
int failed;
scsi_unregister_host(&idescsi_template);
for (i = 0; media[i] != 255; i++) {
failed = 0;
while ((drive = ide_scan_devices (media[i], idescsi_driver.name, &idescsi_driver, failed)) != NULL)
if (idescsi_cleanup (drive)) {
printk ("%s: exit_idescsi_module() called while still busy\n", drive->name);
failed++;
}
}
failed = 0;
while ((drive = ide_scan_devices(&idescsi_driver, failed)) != NULL)
if (idescsi_cleanup (drive)) {
printk ("%s: exit_idescsi_module() called while still busy\n", drive->name);
failed++;
}
ide_unregister_module(&idescsi_module);
}
......
......@@ -1242,7 +1242,7 @@ int idescsi_init (void);
int ide_register_module (ide_module_t *module);
void ide_unregister_module (ide_module_t *module);
ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *driver, int n);
ide_drive_t *ide_scan_devices(ide_driver_t *driver, int n);
int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
int ide_unregister_subdriver (ide_drive_t *drive);
int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
......
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