Commit 86a995ac authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] finish introduction of ->reinit()

Finish introduction of ->reinit() - Jens had missed MOD_DEC_USE_COUNT on
several exits from ide-cd one and forgot to remove the loop from
ide-floppy ide-tape and ide-scsi ones ;-) (->reinit() is the body of
loop in ->init() - stuff that should be done one drive; in 2.5.32
ide-disk one is OK, ide-cd is OK modulo minor bugs and in the rest it's
a copy of ->init())
parent 65862d88
......@@ -3101,17 +3101,18 @@ MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
int ide_cdrom_reinit (ide_drive_t *drive)
{
struct cdrom_info *info;
int failed = 0;
MOD_INC_USE_COUNT;
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;
}
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;
}
memset (info, 0, sizeof (struct cdrom_info));
......@@ -3121,12 +3122,10 @@ 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;
}
DRIVER(drive)->busy--;
failed--;
ide_register_module(&ide_cdrom_module);
MOD_DEC_USE_COUNT;
return 0;
}
......@@ -3147,7 +3146,6 @@ static void __exit ide_cdrom_exit(void)
int ide_cdrom_init(void)
{
ide_drive_t *drive;
struct cdrom_info *info;
int failed = 0;
MOD_INC_USE_COUNT;
......@@ -3163,26 +3161,8 @@ int ide_cdrom_init(void)
printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
continue;
}
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);
if (ide_cdrom_reinit(drive))
continue;
}
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);
continue;
}
memset (info, 0, sizeof (struct cdrom_info));
drive->driver_data = info;
DRIVER(drive)->busy++;
if (ide_cdrom_setup (drive)) {
DRIVER(drive)->busy--;
if (ide_cdrom_cleanup (drive))
printk ("%s: ide_cdrom_cleanup failed in ide_cdrom_init\n", drive->name);
continue;
}
DRIVER(drive)->busy--;
failed--;
}
ide_register_module(&ide_cdrom_module);
......
......@@ -1682,14 +1682,13 @@ static ide_module_t idedisk_module = {
MODULE_DESCRIPTION("ATA DISK Driver");
int idedisk_reinit (ide_drive_t *drive)
int idedisk_reinit(ide_drive_t *drive)
{
int failed = 0;
MOD_INC_USE_COUNT;
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;
}
DRIVER(drive)->busy++;
......@@ -1699,12 +1698,10 @@ int idedisk_reinit (ide_drive_t *drive)
drive->name, drive->head);
(void) idedisk_cleanup(drive);
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 1;
}
DRIVER(drive)->busy--;
failed--;
ide_register_module(&idedisk_module);
MOD_DEC_USE_COUNT;
return 0;
}
......@@ -1736,19 +1733,8 @@ int idedisk_init (void)
MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_disk, idedisk_driver.name, NULL, failed++)) != NULL) {
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);
if (idedisk_reinit(drive))
continue;
}
DRIVER(drive)->busy++;
idedisk_setup(drive);
if ((!drive->head || drive->head > 16) && !drive->select.b.lba) {
printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", drive->name, drive->head);
(void) idedisk_cleanup(drive);
DRIVER(drive)->busy--;
continue;
}
DRIVER(drive)->busy--;
failed--;
}
ide_register_module(&idedisk_module);
......
......@@ -2194,33 +2194,31 @@ static ide_module_t idefloppy_module = {
int idefloppy_reinit (ide_drive_t *drive)
{
idefloppy_floppy_t *floppy;
int failed = 0;
MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, NULL, failed++)) != NULL) {
if (!idefloppy_identify_device (drive, drive->id)) {
printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
continue;
}
if (drive->scsi) {
printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
continue;
}
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);
continue;
}
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);
continue;
}
DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--;
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;
}
ide_register_module(&idefloppy_module);
if (drive->scsi) {
printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
MOD_DEC_USE_COUNT;
return 1;
}
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;
}
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;
}
DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
}
......@@ -2253,32 +2251,13 @@ static void __exit idefloppy_exit (void)
int idefloppy_init (void)
{
ide_drive_t *drive;
idefloppy_floppy_t *floppy;
int failed = 0;
printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, NULL, failed++)) != NULL) {
if (!idefloppy_identify_device (drive, drive->id)) {
printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
continue;
}
if (drive->scsi) {
printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
continue;
}
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);
continue;
}
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);
if (idefloppy_reinit(drive))
continue;
}
DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--;
failed--;
}
ide_register_module(&idefloppy_module);
......
......@@ -6367,89 +6367,53 @@ static struct file_operations idetape_fops = {
int idetape_reinit (ide_drive_t *drive)
{
#if 0
idetape_tape_t *tape;
int minor, failed = 0, supported = 0;
/* DRIVER(drive)->busy++; */
MOD_INC_USE_COUNT;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_INC_USE_COUNT in idetape_init\n");
#endif
if (!idetape_chrdev_present)
for (minor = 0; minor < MAX_HWIFS * MAX_DRIVES; minor++ )
idetape_chrdevs[minor].drive = NULL;
int minor;
if ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++)) == NULL) {
ide_register_module(&idetape_module);
MOD_INC_USE_COUNT;
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;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
#endif
return 0;
return 1;
}
if (!idetape_chrdev_present &&
register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
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;
}
}
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;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
#endif
return -EBUSY;
return 1;
}
do {
if (!idetape_identify_device(drive, drive->id)) {
printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name);
continue;
}
if (drive->scsi) {
if (strstr(drive->id->model, "OnStream DI-30")) {
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);
continue;
}
}
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);
continue;
}
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);
continue;
}
for (minor = 0; idetape_chrdevs[minor].drive != NULL; minor++);
idetape_setup(drive, tape, minor);
idetape_chrdevs[minor].drive = drive;
tape->de_r =
devfs_register (drive->de, "mt", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
tape->de_n =
devfs_register (drive->de, "mtn", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor + 128,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
devfs_register_tape(tape->de_r);
supported++;
failed--;
} while ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++)) != NULL);
if (!idetape_chrdev_present && !supported) {
devfs_unregister_chrdev(IDETAPE_MAJOR, "ht");
} else
idetape_chrdev_present = 1;
ide_register_module(&idetape_module);
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;
}
for (minor = 0; idetape_chrdevs[minor].drive != NULL; minor++)
;
idetape_setup(drive, tape, minor);
idetape_chrdevs[minor].drive = drive;
tape->de_r =
devfs_register (drive->de, "mt", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
tape->de_n =
devfs_register (drive->de, "mtn", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor + 128,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
devfs_register_tape(tape->de_r);
MOD_DEC_USE_COUNT;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
#endif
return 0;
#else
return 1;
#endif
}
MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
......@@ -6474,83 +6438,31 @@ static void __exit idetape_exit (void)
int idetape_init (void)
{
ide_drive_t *drive;
idetape_tape_t *tape;
int minor, failed = 0, supported = 0;
/* DRIVER(drive)->busy++; */
MOD_INC_USE_COUNT;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_INC_USE_COUNT in idetape_init\n");
#endif
if (!idetape_chrdev_present)
for (minor = 0; minor < MAX_HWIFS * MAX_DRIVES; minor++ )
if (!idetape_chrdev_present) {
if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
MOD_DEC_USE_COUNT;
return -EBUSY;
}
for (minor = 0; minor < MAX_HWIFS * MAX_DRIVES; minor++)
idetape_chrdevs[minor].drive = NULL;
if ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++)) == NULL) {
ide_register_module(&idetape_module);
MOD_DEC_USE_COUNT;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
#endif
return 0;
}
if (!idetape_chrdev_present &&
register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
MOD_DEC_USE_COUNT;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
#endif
return -EBUSY;
}
do {
if (!idetape_identify_device (drive, drive->id)) {
printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name);
continue;
}
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);
continue;
}
}
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);
continue;
}
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);
while ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++))) {
if (idetape_reinit(drive))
continue;
}
for (minor = 0; idetape_chrdevs[minor].drive != NULL; minor++);
idetape_setup(drive, tape, minor);
idetape_chrdevs[minor].drive = drive;
tape->de_r =
devfs_register (drive->de, "mt", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
tape->de_n =
devfs_register (drive->de, "mtn", DEVFS_FL_DEFAULT,
HWIF(drive)->major, minor + 128,
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
devfs_register_tape(tape->de_r);
supported++;
failed--;
} while ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++)) != NULL);
}
if (!idetape_chrdev_present && !supported) {
unregister_chrdev(IDETAPE_MAJOR, "ht");
} else
idetape_chrdev_present = 1;
ide_register_module(&idetape_module);
MOD_DEC_USE_COUNT;
#if ONSTREAM_DEBUG
printk(KERN_INFO "ide-tape: MOD_DEC_USE_COUNT in idetape_init\n");
#endif
return 0;
}
......
......@@ -539,6 +539,8 @@ static int idescsi_cleanup (ide_drive_t *drive)
return 0;
}
static int idescsi_reinit(ide_drive_t *drive);
/*
* IDE subdriver functions, registered with ide.c
*/
......@@ -549,6 +551,7 @@ static ide_driver_t idescsi_driver = {
busy: 0,
supports_dma: 1,
supports_dsc_overlap: 0,
reinit: idescsi_reinit,
cleanup: idescsi_cleanup,
standby: NULL,
flushcache: NULL,
......@@ -573,15 +576,39 @@ static ide_module_t idescsi_module = {
NULL
};
static int idescsi_reinit(ide_drive_t *drive)
{
idescsi_scsi_t *scsi;
int id;
MOD_INC_USE_COUNT;
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;
}
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;
}
for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
;
idescsi_setup (drive, scsi, id);
MOD_DEC_USE_COUNT;
return 0;
}
/*
* idescsi_init will register the driver for each scsi.
*/
int idescsi_init (void)
{
ide_drive_t *drive;
idescsi_scsi_t *scsi;
byte media[] = {TYPE_DISK, TYPE_TAPE, TYPE_PROCESSOR, TYPE_WORM, TYPE_ROM, TYPE_SCANNER, TYPE_MOD, 255};
int i, failed, id;
int i, failed;
if (idescsi_initialized)
return 0;
......@@ -592,18 +619,8 @@ int idescsi_init (void)
for (i = 0; media[i] != 255; i++) {
failed = 0;
while ((drive = ide_scan_devices (media[i], idescsi_driver.name, NULL, failed++)) != NULL) {
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);
if (idescsi_reinit(drive))
continue;
}
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);
continue;
}
for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++);
idescsi_setup (drive, scsi, id);
failed--;
}
}
......
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