Commit ce3058ec authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] Add ->owner to ide_driver_t

->owner added to ide_driver_t.  MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT
taken out of ->reinit().  ide_reinit_drive() turned into "call
->reinit() for all high-level drivers that are registered until somebody
claims the drive" (instead of open-coded variant in 2.5.32; cleaner and
works correctly for modular drivers).
parent 20d346ec
...@@ -3048,9 +3048,10 @@ int ide_cdrom_cleanup(ide_drive_t *drive) ...@@ -3048,9 +3048,10 @@ int ide_cdrom_cleanup(ide_drive_t *drive)
} }
static int ide_cdrom_init(void); static int ide_cdrom_init(void);
int ide_cdrom_reinit (ide_drive_t *drive); static int ide_cdrom_reinit (ide_drive_t *drive);
static ide_driver_t ide_cdrom_driver = { static ide_driver_t ide_cdrom_driver = {
owner: THIS_MODULE,
name: "ide-cdrom", name: "ide-cdrom",
version: IDECD_VERSION, version: IDECD_VERSION,
media: ide_cdrom, media: ide_cdrom,
...@@ -3099,11 +3100,10 @@ char *ignore = NULL; ...@@ -3099,11 +3100,10 @@ char *ignore = NULL;
MODULE_PARM(ignore, "s"); MODULE_PARM(ignore, "s");
MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
int ide_cdrom_reinit (ide_drive_t *drive) static int ide_cdrom_reinit (ide_drive_t *drive)
{ {
struct cdrom_info *info; struct cdrom_info *info;
MOD_INC_USE_COUNT;
if (!strstr("ide-cdrom", drive->driver_req)) if (!strstr("ide-cdrom", drive->driver_req))
goto failed; goto failed;
if (!drive->present) if (!drive->present)
...@@ -3141,10 +3141,8 @@ int ide_cdrom_reinit (ide_drive_t *drive) ...@@ -3141,10 +3141,8 @@ int ide_cdrom_reinit (ide_drive_t *drive)
goto failed; goto failed;
} }
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0; return 0;
failed: failed:
MOD_DEC_USE_COUNT;
return 1; return 1;
} }
......
...@@ -1637,12 +1637,13 @@ static int idedisk_cleanup (ide_drive_t *drive) ...@@ -1637,12 +1637,13 @@ static int idedisk_cleanup (ide_drive_t *drive)
} }
static int idedisk_init (void); static int idedisk_init (void);
int idedisk_reinit(ide_drive_t *drive); static int idedisk_reinit(ide_drive_t *drive);
/* /*
* IDE subdriver functions, registered with ide.c * IDE subdriver functions, registered with ide.c
*/ */
static ide_driver_t idedisk_driver = { static ide_driver_t idedisk_driver = {
owner: THIS_MODULE,
name: "ide-disk", name: "ide-disk",
version: IDEDISK_VERSION, version: IDEDISK_VERSION,
media: ide_disk, media: ide_disk,
...@@ -1683,9 +1684,8 @@ static ide_module_t idedisk_module = { ...@@ -1683,9 +1684,8 @@ static ide_module_t idedisk_module = {
MODULE_DESCRIPTION("ATA DISK Driver"); MODULE_DESCRIPTION("ATA DISK Driver");
int idedisk_reinit(ide_drive_t *drive) static int idedisk_reinit(ide_drive_t *drive)
{ {
MOD_INC_USE_COUNT;
/* strstr("foo", "") is non-NULL */ /* strstr("foo", "") is non-NULL */
if (!strstr("ide-disk", drive->driver_req)) if (!strstr("ide-disk", drive->driver_req))
goto failed; goto failed;
...@@ -1708,10 +1708,8 @@ int idedisk_reinit(ide_drive_t *drive) ...@@ -1708,10 +1708,8 @@ int idedisk_reinit(ide_drive_t *drive)
goto failed; goto failed;
} }
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0; return 0;
failed: failed:
MOD_DEC_USE_COUNT;
return 1; return 1;
} }
......
...@@ -2144,12 +2144,13 @@ static ide_proc_entry_t idefloppy_proc[] = { ...@@ -2144,12 +2144,13 @@ static ide_proc_entry_t idefloppy_proc[] = {
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
static int idefloppy_init (void); static int idefloppy_init (void);
int idefloppy_reinit(ide_drive_t *drive); static int idefloppy_reinit(ide_drive_t *drive);
/* /*
* IDE subdriver functions, registered with ide.c * IDE subdriver functions, registered with ide.c
*/ */
static ide_driver_t idefloppy_driver = { static ide_driver_t idefloppy_driver = {
owner: THIS_MODULE,
name: "ide-floppy", name: "ide-floppy",
version: IDEFLOPPY_VERSION, version: IDEFLOPPY_VERSION,
media: ide_floppy, media: ide_floppy,
...@@ -2192,10 +2193,9 @@ static ide_module_t idefloppy_module = { ...@@ -2192,10 +2193,9 @@ static ide_module_t idefloppy_module = {
NULL NULL
}; };
int idefloppy_reinit (ide_drive_t *drive) static int idefloppy_reinit (ide_drive_t *drive)
{ {
idefloppy_floppy_t *floppy; idefloppy_floppy_t *floppy;
MOD_INC_USE_COUNT;
if (!strstr("ide-floppy", drive->driver_req)) if (!strstr("ide-floppy", drive->driver_req))
goto failed; goto failed;
if (!drive->present) if (!drive->present)
...@@ -2222,10 +2222,8 @@ int idefloppy_reinit (ide_drive_t *drive) ...@@ -2222,10 +2222,8 @@ int idefloppy_reinit (ide_drive_t *drive)
DRIVER(drive)->busy++; DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy); idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0; return 0;
failed: failed:
MOD_DEC_USE_COUNT;
return 1; return 1;
} }
......
...@@ -6301,12 +6301,13 @@ static ide_proc_entry_t idetape_proc[] = { ...@@ -6301,12 +6301,13 @@ static ide_proc_entry_t idetape_proc[] = {
#endif #endif
static int idetape_init (void); static int idetape_init (void);
int idetape_reinit(ide_drive_t *drive); static int idetape_reinit(ide_drive_t *drive);
/* /*
* IDE subdriver functions, registered with ide.c * IDE subdriver functions, registered with ide.c
*/ */
static ide_driver_t idetape_driver = { static ide_driver_t idetape_driver = {
owner: THIS_MODULE,
name: "ide-tape", name: "ide-tape",
version: IDETAPE_VERSION, version: IDETAPE_VERSION,
media: ide_tape, media: ide_tape,
...@@ -6361,12 +6362,11 @@ static struct file_operations idetape_fops = { ...@@ -6361,12 +6362,11 @@ static struct file_operations idetape_fops = {
release: idetape_chrdev_release, release: idetape_chrdev_release,
}; };
int idetape_reinit (ide_drive_t *drive) static int idetape_reinit (ide_drive_t *drive)
{ {
idetape_tape_t *tape; idetape_tape_t *tape;
int minor; int minor;
MOD_INC_USE_COUNT;
if (!strstr("ide-tape", drive->driver_req)) if (!strstr("ide-tape", drive->driver_req))
goto failed; goto failed;
if (!drive->present) if (!drive->present)
...@@ -6410,10 +6410,8 @@ int idetape_reinit (ide_drive_t *drive) ...@@ -6410,10 +6410,8 @@ int idetape_reinit (ide_drive_t *drive)
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL); &idetape_fops, NULL);
devfs_register_tape(tape->de_r); devfs_register_tape(tape->de_r);
MOD_DEC_USE_COUNT;
return 0; return 0;
failed: failed:
MOD_DEC_USE_COUNT;
return 1; return 1;
} }
......
...@@ -2515,59 +2515,28 @@ int system_bus_clock (void) ...@@ -2515,59 +2515,28 @@ int system_bus_clock (void)
return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed )); return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
} }
static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
int ide_reinit_drive (ide_drive_t *drive) int ide_reinit_drive (ide_drive_t *drive)
{ {
switch (drive->media) { ide_module_t *module;
#ifdef CONFIG_BLK_DEV_IDECD spin_lock(&drivers_lock);
case ide_cdrom: for (module = ide_modules; module; module = module->next) {
{ ide_driver_t *driver = module->info;
extern int ide_cdrom_reinit(ide_drive_t *drive); if (!try_inc_mod_count(driver->owner))
if (ide_cdrom_reinit(drive)) continue;
return 1; spin_unlock(&drivers_lock);
break; if (driver->reinit(drive) == 0) {
} if (driver->owner)
#endif /* CONFIG_BLK_DEV_IDECD */ __MOD_DEC_USE_COUNT(driver->owner);
#ifdef CONFIG_BLK_DEV_IDEDISK return 0;
case ide_disk:
{
extern int idedisk_reinit(ide_drive_t *drive);
if (idedisk_reinit(drive))
return 1;
break;
}
#endif /* CONFIG_BLK_DEV_IDEDISK */
#ifdef CONFIG_BLK_DEV_IDEFLOPPY
case ide_floppy:
{
extern int idefloppy_reinit(ide_drive_t *drive);
if (idefloppy_reinit(drive))
return 1;
break;
} }
#endif /* CONFIG_BLK_DEV_IDEFLOPPY */ spin_lock(&drivers_lock);
#ifdef CONFIG_BLK_DEV_IDETAPE if (driver->owner)
case ide_tape: __MOD_DEC_USE_COUNT(driver->owner);
{
extern int idetape_reinit(ide_drive_t *drive);
if (idetape_reinit(drive))
return 1;
break;
} }
#endif /* CONFIG_BLK_DEV_IDETAPE */ spin_unlock(&drivers_lock);
#ifdef CONFIG_BLK_DEV_IDESCSI
/*
* {
* extern int idescsi_reinit(ide_drive_t *drive);
* if (idescsi_reinit(drive))
* return 1;
* break;
* }
*/
#endif /* CONFIG_BLK_DEV_IDESCSI */
default:
return 1; return 1;
}
return 0;
} }
static int ide_ioctl (struct inode *inode, struct file *file, static int ide_ioctl (struct inode *inode, struct file *file,
...@@ -3605,12 +3574,16 @@ int ide_register_module (ide_module_t *module) ...@@ -3605,12 +3574,16 @@ int ide_register_module (ide_module_t *module)
failed--; failed--;
} }
spin_lock(&drivers_lock);
for (p = ide_modules; p; p = p->next) { for (p = ide_modules; p; p = p->next) {
if (p == module) if (p == module) {
spin_unlock(&drivers_lock);
return 1; return 1;
} }
}
module->next = ide_modules; module->next = ide_modules;
ide_modules = module; ide_modules = module;
spin_unlock(&drivers_lock);
revalidate_drives(); revalidate_drives();
return 0; return 0;
} }
...@@ -3635,9 +3608,11 @@ void ide_unregister_module (ide_module_t *module) ...@@ -3635,9 +3608,11 @@ void ide_unregister_module (ide_module_t *module)
#endif #endif
} }
spin_lock(&drivers_lock);
for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next)); for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next));
if (*p) if (*p)
*p = (*p)->next; *p = (*p)->next;
spin_unlock(&drivers_lock);
} }
struct block_device_operations ide_fops[] = {{ struct block_device_operations ide_fops[] = {{
......
...@@ -545,6 +545,7 @@ static int idescsi_reinit(ide_drive_t *drive); ...@@ -545,6 +545,7 @@ static int idescsi_reinit(ide_drive_t *drive);
* IDE subdriver functions, registered with ide.c * IDE subdriver functions, registered with ide.c
*/ */
static ide_driver_t idescsi_driver = { static ide_driver_t idescsi_driver = {
owner: THIS_MODULE,
name: "ide-scsi", name: "ide-scsi",
version: IDESCSI_VERSION, version: IDESCSI_VERSION,
media: ide_scsi, media: ide_scsi,
...@@ -582,7 +583,6 @@ static int idescsi_reinit(ide_drive_t *drive) ...@@ -582,7 +583,6 @@ static int idescsi_reinit(ide_drive_t *drive)
idescsi_scsi_t *scsi; idescsi_scsi_t *scsi;
int id; int id;
MOD_INC_USE_COUNT;
if (!strstr("ide-scsi", drive->driver_req)) if (!strstr("ide-scsi", drive->driver_req))
goto failed; goto failed;
if (!drive->present) if (!drive->present)
...@@ -602,10 +602,8 @@ static int idescsi_reinit(ide_drive_t *drive) ...@@ -602,10 +602,8 @@ static int idescsi_reinit(ide_drive_t *drive)
for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++) for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
; ;
idescsi_setup (drive, scsi, id); idescsi_setup (drive, scsi, id);
MOD_DEC_USE_COUNT;
return 0; return 0;
failed: failed:
MOD_DEC_USE_COUNT;
return 1; return 1;
} }
......
...@@ -890,6 +890,7 @@ read_proc_t proc_ide_read_geometry; ...@@ -890,6 +890,7 @@ read_proc_t proc_ide_read_geometry;
#define IDE_SUBDRIVER_VERSION 1 #define IDE_SUBDRIVER_VERSION 1
typedef struct ide_driver_s { typedef struct ide_driver_s {
struct module *owner;
const char *name; const char *name;
const char *version; const char *version;
byte media; byte media;
...@@ -1218,21 +1219,6 @@ int ide_reinit_drive (ide_drive_t *drive); ...@@ -1218,21 +1219,6 @@ int ide_reinit_drive (ide_drive_t *drive);
#ifdef CONFIG_BLK_DEV_IDE #ifdef CONFIG_BLK_DEV_IDE
int ideprobe_init (void); int ideprobe_init (void);
#endif /* CONFIG_BLK_DEV_IDE */ #endif /* CONFIG_BLK_DEV_IDE */
#ifdef CONFIG_BLK_DEV_IDEDISK
int idedisk_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDEDISK */
#ifdef CONFIG_BLK_DEV_IDECD
int ide_cdrom_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDECD */
#ifdef CONFIG_BLK_DEV_IDETAPE
int idetape_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDETAPE */
#ifdef CONFIG_BLK_DEV_IDEFLOPPY
int idefloppy_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDEFLOPPY */
#ifdef CONFIG_BLK_DEV_IDESCSI
int idescsi_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDESCSI */
#endif /* _IDE_C */ #endif /* _IDE_C */
int ide_register_module (ide_module_t *module); int ide_register_module (ide_module_t *module);
......
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