Commit fed60d4e authored by Doug Ledford's avatar Doug Ledford

Merge bk://linux.bkbits.net/linux-2.5

into flossy.devel.redhat.com:/usr/local/home/dledford/bk/linus-2.5
parents 41977e4b 15018efc
...@@ -230,8 +230,8 @@ extern int x_scsi_host_reset(Scsi_Cmnd *); ...@@ -230,8 +230,8 @@ extern int x_scsi_host_reset(Scsi_Cmnd *);
extern int x_scsi_old_abort(Scsi_Cmnd *); extern int x_scsi_old_abort(Scsi_Cmnd *);
extern int x_scsi_old_reset(Scsi_Cmnd *, unsigned int); extern int x_scsi_old_reset(Scsi_Cmnd *, unsigned int);
#endif #endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,28) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45)
extern int x_scsi_bios_param(Disk *, struct block_device *, int *); extern int x_scsi_bios_param(Scsi_Device *, struct block_device *, sector_t, int[]);
#else #else
extern int x_scsi_bios_param(Disk *, kdev_t, int *); extern int x_scsi_bios_param(Disk *, kdev_t, int *);
#endif #endif
......
...@@ -732,9 +732,6 @@ void esp_initialize(struct NCR_ESP *esp) ...@@ -732,9 +732,6 @@ void esp_initialize(struct NCR_ESP *esp)
/* Reset the thing before we try anything... */ /* Reset the thing before we try anything... */
esp_bootup_reset(esp, eregs); esp_bootup_reset(esp, eregs);
#ifdef MODULE
MOD_INC_USE_COUNT;
#endif
esps_in_use++; esps_in_use++;
} }
...@@ -3638,7 +3635,6 @@ int init_module(void) { return 0; } ...@@ -3638,7 +3635,6 @@ int init_module(void) { return 0; }
void cleanup_module(void) {} void cleanup_module(void) {}
void esp_release(void) void esp_release(void)
{ {
MOD_DEC_USE_COUNT;
esps_in_use--; esps_in_use--;
esps_running = esps_in_use; esps_running = esps_in_use;
} }
......
...@@ -9310,7 +9310,8 @@ aic7xxx_detect(Scsi_Host_Template *template) ...@@ -9310,7 +9310,8 @@ aic7xxx_detect(Scsi_Host_Template *template)
pci_write_config_dword(pdev, DEVCONFIG, devconfig); pci_write_config_dword(pdev, DEVCONFIG, devconfig);
#endif /* AIC7XXX_STRICT_PCI_SETUP */ #endif /* AIC7XXX_STRICT_PCI_SETUP */
if(temp_p->base && check_region(temp_p->base, MAXREG - MINREG)) if(temp_p->base && !request_region(temp_p->base, MAXREG - MINREG,
"aic7xxx"))
{ {
printk("aic7xxx: <%s> at PCI %d/%d/%d\n", printk("aic7xxx: <%s> at PCI %d/%d/%d\n",
board_names[aic_pdevs[i].board_name_index], board_names[aic_pdevs[i].board_name_index],
...@@ -9388,12 +9389,6 @@ aic7xxx_detect(Scsi_Host_Template *template) ...@@ -9388,12 +9389,6 @@ aic7xxx_detect(Scsi_Host_Template *template)
} }
#endif #endif
/*
* Lock out other contenders for our i/o space.
*/
if(temp_p->base)
request_region(temp_p->base, MAXREG - MINREG, "aic7xxx");
/* /*
* We HAVE to make sure the first pause_sequencer() and all other * We HAVE to make sure the first pause_sequencer() and all other
* subsequent I/O that isn't PCI config space I/O takes place * subsequent I/O that isn't PCI config space I/O takes place
...@@ -9742,7 +9737,7 @@ aic7xxx_detect(Scsi_Host_Template *template) ...@@ -9742,7 +9737,7 @@ aic7xxx_detect(Scsi_Host_Template *template)
{ {
base = SLOTBASE(slot) + MINREG; base = SLOTBASE(slot) + MINREG;
if (check_region(base, MAXREG - MINREG)) if (!request_region(base, MAXREG - MINREG, "aic7xxx"))
{ {
/* /*
* Some other driver has staked a * Some other driver has staked a
...@@ -9755,6 +9750,7 @@ aic7xxx_detect(Scsi_Host_Template *template) ...@@ -9755,6 +9750,7 @@ aic7xxx_detect(Scsi_Host_Template *template)
type = aic7xxx_probe(slot, base + AHC_HID0, &flags); type = aic7xxx_probe(slot, base + AHC_HID0, &flags);
if (type == -1) if (type == -1)
{ {
release_region(base, MAXREG - MINREG);
slot++; slot++;
continue; continue;
} }
...@@ -9762,13 +9758,10 @@ aic7xxx_detect(Scsi_Host_Template *template) ...@@ -9762,13 +9758,10 @@ aic7xxx_detect(Scsi_Host_Template *template)
if (temp_p == NULL) if (temp_p == NULL)
{ {
printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n"); printk(KERN_WARNING "aic7xxx: Unable to allocate device space.\n");
release_region(base, MAXREG - MINREG);
slot++; slot++;
continue; /* back to the beginning of the while loop */ continue; /* back to the beginning of the while loop */
} }
/*
* Lock out other contenders for our i/o space.
*/
request_region(base, MAXREG - MINREG, "aic7xxx");
/* /*
* Pause the card preserving the IRQ type. Allow the operator * Pause the card preserving the IRQ type. Allow the operator
...@@ -10972,6 +10965,10 @@ aic7xxx_reset(Scsi_Cmnd *cmd) ...@@ -10972,6 +10965,10 @@ aic7xxx_reset(Scsi_Cmnd *cmd)
* *
* Description: * Description:
* Return the disk geometry for the given SCSI device. * Return the disk geometry for the given SCSI device.
*
* Note:
* This function is broken for today's really large drives and needs
* fixed.
*-F*************************************************************************/ *-F*************************************************************************/
int int
aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev, aic7xxx_biosparam(struct scsi_device *sdev, struct block_device *bdev,
......
...@@ -131,12 +131,6 @@ int scsi_remove_host(struct Scsi_Host *shost) ...@@ -131,12 +131,6 @@ int scsi_remove_host(struct Scsi_Host *shost)
struct scsi_device *sdev; struct scsi_device *sdev;
struct scsi_cmnd *scmd; struct scsi_cmnd *scmd;
/*
* Current policy is all shosts go away on unregister.
*/
if (shost->hostt->module && GET_USE_COUNT(shost->hostt->module))
return 1;
/* /*
* FIXME Do ref counting. We force all of the devices offline to * FIXME Do ref counting. We force all of the devices offline to
* help prevent race conditions where other hosts/processors could * help prevent race conditions where other hosts/processors could
...@@ -500,8 +494,6 @@ int scsi_register_host(Scsi_Host_Template *shost_tp) ...@@ -500,8 +494,6 @@ int scsi_register_host(Scsi_Host_Template *shost_tp)
cur_cnt = scsi_hosts_registered; cur_cnt = scsi_hosts_registered;
MOD_INC_USE_COUNT;
/* /*
* The detect routine must carefully spinunlock/spinlock if it * The detect routine must carefully spinunlock/spinlock if it
* enables interrupts, since all interrupt handlers do spinlock as * enables interrupts, since all interrupt handlers do spinlock as
...@@ -585,8 +577,6 @@ int scsi_unregister_host(Scsi_Host_Template *shost_tp) ...@@ -585,8 +577,6 @@ int scsi_unregister_host(Scsi_Host_Template *shost_tp)
printk(KERN_INFO "scsi : %d host%s left.\n", scsi_hosts_registered, printk(KERN_INFO "scsi : %d host%s left.\n", scsi_hosts_registered,
(scsi_hosts_registered == 1) ? "" : "s"); (scsi_hosts_registered == 1) ? "" : "s");
MOD_DEC_USE_COUNT;
unlock_kernel(); unlock_kernel();
return 0; return 0;
......
...@@ -549,7 +549,7 @@ extern void scsi_mark_host_reset(struct Scsi_Host *); ...@@ -549,7 +549,7 @@ extern void scsi_mark_host_reset(struct Scsi_Host *);
struct Scsi_Device_Template struct Scsi_Device_Template
{ {
struct Scsi_Device_Template * next; struct list_head list;
const char * name; const char * name;
const char * tag; const char * tag;
struct module * module; /* Used for loadable modules */ struct module * module; /* Used for loadable modules */
......
...@@ -760,9 +760,8 @@ struct mega_hbas mega_hbas[MAX_CONTROLLERS]; ...@@ -760,9 +760,8 @@ struct mega_hbas mega_hbas[MAX_CONTROLLERS];
/* For controller re-ordering */ /* For controller re-ordering */
static struct file_operations megadev_fops = { static struct file_operations megadev_fops = {
ioctl:megadev_ioctl_entry, .owner = THIS_MODULE,
open:megadev_open, .ioctl = megadev_ioctl_entry,
release:megadev_close,
}; };
/* /*
...@@ -4333,15 +4332,6 @@ static void enq_scb_freelist (mega_host_config * megacfg, mega_scb * scb, int lo ...@@ -4333,15 +4332,6 @@ static void enq_scb_freelist (mega_host_config * megacfg, mega_scb * scb, int lo
} }
} }
/*
* Routines for the character/ioctl interface to the driver
*/
static int megadev_open (struct inode *inode, struct file *filep)
{
MOD_INC_USE_COUNT;
return 0; /* success */
}
static int megadev_ioctl_entry (struct inode *inode, struct file *filep, static int megadev_ioctl_entry (struct inode *inode, struct file *filep,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
...@@ -4852,16 +4842,6 @@ megadev_doioctl (mega_host_config * megacfg, Scsi_Cmnd * sc) ...@@ -4852,16 +4842,6 @@ megadev_doioctl (mega_host_config * megacfg, Scsi_Cmnd * sc)
return scb; return scb;
} }
static int
megadev_close (struct inode *inode, struct file *filep)
{
#ifdef MODULE
MOD_DEC_USE_COUNT;
#endif
return 0;
}
static int static int
mega_support_ext_cdb(mega_host_config *this_hba) mega_support_ext_cdb(mega_host_config *this_hba)
{ {
......
...@@ -163,6 +163,7 @@ static int osst_dev_max; ...@@ -163,6 +163,7 @@ static int osst_dev_max;
struct Scsi_Device_Template osst_template = struct Scsi_Device_Template osst_template =
{ {
module: THIS_MODULE, module: THIS_MODULE,
list: LIST_HEAD_INIT(osst_template.list),
name: "OnStream tape", name: "OnStream tape",
tag: "osst", tag: "osst",
scsi_type: TYPE_TAPE, scsi_type: TYPE_TAPE,
...@@ -4174,14 +4175,12 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp) ...@@ -4174,14 +4175,12 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
#endif #endif
return (-EBUSY); return (-EBUSY);
} }
STp->in_use = 1;
STp->rew_at_close = (minor(inode->i_rdev) & 0x80) == 0;
if (STp->device->host->hostt->module) if (!try_module_get(STp->device->host->hostt->module))
__MOD_INC_USE_COUNT(STp->device->host->hostt->module); return (-ENXIO);
if (osst_template.module)
__MOD_INC_USE_COUNT(osst_template.module);
STp->device->access_count++; STp->device->access_count++;
STp->in_use = 1;
STp->rew_at_close = (minor(inode->i_rdev) & 0x80) == 0;
if (mode != STp->current_mode) { if (mode != STp->current_mode) {
#if DEBUG #if DEBUG
...@@ -4521,10 +4520,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp) ...@@ -4521,10 +4520,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
STp->header_ok = 0; STp->header_ok = 0;
STp->device->access_count--; STp->device->access_count--;
if (STp->device->host->hostt->module) module_put(STp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(STp->device->host->hostt->module);
if (osst_template.module)
__MOD_DEC_USE_COUNT(osst_template.module);
return retval; return retval;
} }
...@@ -4652,10 +4648,7 @@ static int os_scsi_tape_close(struct inode * inode, struct file * filp) ...@@ -4652,10 +4648,7 @@ static int os_scsi_tape_close(struct inode * inode, struct file * filp)
STp->in_use = 0; STp->in_use = 0;
STp->device->access_count--; STp->device->access_count--;
if (STp->device->host->hostt->module) module_put(STp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(STp->device->host->hostt->module);
if(osst_template.module)
__MOD_DEC_USE_COUNT(osst_template.module);
return result; return result;
} }
......
...@@ -135,7 +135,7 @@ static struct softscsi_data softscsi_data[NR_CPUS] __cacheline_aligned; ...@@ -135,7 +135,7 @@ static struct softscsi_data softscsi_data[NR_CPUS] __cacheline_aligned;
/* /*
* List of all highlevel drivers. * List of all highlevel drivers.
*/ */
static struct Scsi_Device_Template *scsi_devicelist; LIST_HEAD(scsi_devicelist);
static DECLARE_RWSEM(scsi_devicelist_mutex); static DECLARE_RWSEM(scsi_devicelist_mutex);
/* /*
...@@ -1963,9 +1963,15 @@ void scsi_detect_device(struct scsi_device *sdev) ...@@ -1963,9 +1963,15 @@ void scsi_detect_device(struct scsi_device *sdev)
struct Scsi_Device_Template *sdt; struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex); down_read(&scsi_devicelist_mutex);
for (sdt = scsi_devicelist; sdt; sdt = sdt->next) list_for_each_entry(sdt, &scsi_devicelist, list)
if (sdt->detect) if (sdt->detect) {
if(try_module_get(sdt->module)) {
(*sdt->detect)(sdev); (*sdt->detect)(sdev);
module_put(sdt->module);
} else {
printk(KERN_WARNING "SCSI module %s not ready, skipping detection.\n", sdt->name);
}
}
up_read(&scsi_devicelist_mutex); up_read(&scsi_devicelist_mutex);
} }
...@@ -1974,14 +1980,20 @@ int scsi_attach_device(struct scsi_device *sdev) ...@@ -1974,14 +1980,20 @@ int scsi_attach_device(struct scsi_device *sdev)
struct Scsi_Device_Template *sdt; struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex); down_read(&scsi_devicelist_mutex);
for (sdt = scsi_devicelist; sdt; sdt = sdt->next) list_for_each_entry(sdt, &scsi_devicelist, list)
if (sdt->attach) if (sdt->attach) {
/* /*
* XXX check result when the upper level attach * XXX check result when the upper level attach
* return values are fixed, and on failure goto * return values are fixed, and on failure goto
* fail. * fail.
*/ */
(*sdt->attach) (sdev); if(try_module_get(sdt->module)) {
(*sdt->attach)(sdev);
module_put(sdt->module);
} else {
printk(KERN_WARNING "SCSI module %s not ready, skipping attach.\n", sdt->name);
}
}
up_read(&scsi_devicelist_mutex); up_read(&scsi_devicelist_mutex);
return 0; return 0;
...@@ -1997,9 +2009,15 @@ void scsi_detach_device(struct scsi_device *sdev) ...@@ -1997,9 +2009,15 @@ void scsi_detach_device(struct scsi_device *sdev)
struct Scsi_Device_Template *sdt; struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex); down_read(&scsi_devicelist_mutex);
for (sdt = scsi_devicelist; sdt; sdt = sdt->next) list_for_each_entry(sdt, &scsi_devicelist, list)
if (sdt->detach) if (sdt->detach) {
if(try_module_get(sdt->module)) {
(*sdt->detach)(sdev); (*sdt->detach)(sdev);
module_put(sdt->module);
} else {
printk(KERN_WARNING "SCSI module %s not ready, skipping detach.\n", sdt->name);
}
}
up_read(&scsi_devicelist_mutex); up_read(&scsi_devicelist_mutex);
} }
...@@ -2064,24 +2082,34 @@ void scsi_slave_detach(struct scsi_device *sdev) ...@@ -2064,24 +2082,34 @@ void scsi_slave_detach(struct scsi_device *sdev)
/* /*
* This entry point should be called by a loadable module if it is trying * This entry point should be called by a loadable module if it is trying
* add a high level scsi driver to the system. * add a high level scsi driver to the system.
*
* This entry point is called from the upper level module's module_init()
* routine. That implies that when this function is called, the
* scsi_mod module is locked down because of upper module layering and
* that the high level driver module is locked down by being in it's
* init routine. So, the *only* thing we have to do to protect adds
* we perform in this function is to make sure that all call's
* to the high level driver's attach() and detach() call in points, other
* than via scsi_register_device and scsi_unregister_device which are in
* the module_init and module_exit code respectively and therefore already
* locked down by the kernel module loader, are wrapped by try_module_get()
* and module_put() to avoid races on device adds and removes.
*/ */
int scsi_register_device(struct Scsi_Device_Template *tpnt) int scsi_register_device(struct Scsi_Device_Template *tpnt)
{ {
Scsi_Device *SDpnt; Scsi_Device *SDpnt;
struct Scsi_Host *shpnt; struct Scsi_Host *shpnt;
int out_of_space = 0;
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
if (scsi_host_get_next(NULL) == NULL) if (scsi_host_get_next(NULL) == NULL)
request_module("scsi_hostadapter"); request_module("scsi_hostadapter");
#endif #endif
if (tpnt->next) if (!list_empty(&tpnt->list))
return 1; return 1;
down_write(&scsi_devicelist_mutex); down_write(&scsi_devicelist_mutex);
tpnt->next = scsi_devicelist; list_add_tail(&tpnt->list, &scsi_devicelist);
scsi_devicelist = tpnt;
up_write(&scsi_devicelist_mutex); up_write(&scsi_devicelist_mutex);
tpnt->scsi_driverfs_driver.name = (char *)tpnt->tag; tpnt->scsi_driverfs_driver.name = (char *)tpnt->tag;
...@@ -2120,13 +2148,6 @@ int scsi_register_device(struct Scsi_Device_Template *tpnt) ...@@ -2120,13 +2148,6 @@ int scsi_register_device(struct Scsi_Device_Template *tpnt)
} }
} }
MOD_INC_USE_COUNT;
if (out_of_space) {
scsi_unregister_device(tpnt); /* easiest way to clean up?? */
return 1;
}
return 0; return 0;
} }
...@@ -2134,15 +2155,6 @@ int scsi_unregister_device(struct Scsi_Device_Template *tpnt) ...@@ -2134,15 +2155,6 @@ int scsi_unregister_device(struct Scsi_Device_Template *tpnt)
{ {
Scsi_Device *SDpnt; Scsi_Device *SDpnt;
struct Scsi_Host *shpnt; struct Scsi_Host *shpnt;
struct Scsi_Device_Template *spnt;
struct Scsi_Device_Template *prev_spnt;
lock_kernel();
/*
* If we are busy, this is not going to fly.
*/
if (GET_USE_COUNT(tpnt->module) != 0)
goto error_out;
driver_unregister(&tpnt->scsi_driverfs_driver); driver_unregister(&tpnt->scsi_driverfs_driver);
...@@ -2162,28 +2174,14 @@ int scsi_unregister_device(struct Scsi_Device_Template *tpnt) ...@@ -2162,28 +2174,14 @@ int scsi_unregister_device(struct Scsi_Device_Template *tpnt)
* Extract the template from the linked list. * Extract the template from the linked list.
*/ */
down_write(&scsi_devicelist_mutex); down_write(&scsi_devicelist_mutex);
spnt = scsi_devicelist; list_del(&tpnt->list);
prev_spnt = NULL;
while (spnt != tpnt) {
prev_spnt = spnt;
spnt = spnt->next;
}
if (prev_spnt == NULL)
scsi_devicelist = tpnt->next;
else
prev_spnt->next = spnt->next;
up_write(&scsi_devicelist_mutex); up_write(&scsi_devicelist_mutex);
MOD_DEC_USE_COUNT;
unlock_kernel();
/* /*
* Final cleanup for the driver is done in the driver sources in the * Final cleanup for the driver is done in the driver sources in the
* cleanup function. * cleanup function.
*/ */
return 0; return 0;
error_out:
unlock_kernel();
return -1;
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
...@@ -2379,11 +2377,11 @@ static int __init init_scsi(void) ...@@ -2379,11 +2377,11 @@ static int __init init_scsi(void)
sgp->slab = kmem_cache_create(sgp->name, size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL); sgp->slab = kmem_cache_create(sgp->name, size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
if (!sgp->slab) if (!sgp->slab)
panic("SCSI: can't init sg slab\n"); printk(KERN_ERR "SCSI: can't init sg slab %s\n", sgp->name);
sgp->pool = mempool_create(SG_MEMPOOL_SIZE, scsi_pool_alloc, scsi_pool_free, sgp->slab); sgp->pool = mempool_create(SG_MEMPOOL_SIZE, scsi_pool_alloc, scsi_pool_free, sgp->slab);
if (!sgp->pool) if (!sgp->pool)
panic("SCSI: can't init sg mempool\n"); printk(KERN_ERR "SCSI: can't init sg mempool %s\n", sgp->name);
} }
/* /*
...@@ -2393,13 +2391,12 @@ static int __init init_scsi(void) ...@@ -2393,13 +2391,12 @@ static int __init init_scsi(void)
proc_scsi = proc_mkdir("scsi", 0); proc_scsi = proc_mkdir("scsi", 0);
if (!proc_scsi) { if (!proc_scsi) {
printk (KERN_ERR "cannot init /proc/scsi\n"); printk (KERN_ERR "cannot init /proc/scsi\n");
return -ENOMEM; goto out_error;
} }
generic = create_proc_info_entry ("scsi/scsi", 0, 0, scsi_proc_info); generic = create_proc_info_entry ("scsi/scsi", 0, 0, scsi_proc_info);
if (!generic) { if (!generic) {
printk (KERN_ERR "cannot init /proc/scsi/scsi\n"); printk (KERN_ERR "cannot init /proc/scsi/scsi\n");
remove_proc_entry("scsi", 0); goto out_proc_error;
return -ENOMEM;
} }
generic->write_proc = proc_scsi_gen_write; generic->write_proc = proc_scsi_gen_write;
#endif #endif
...@@ -2414,6 +2411,19 @@ static int __init init_scsi(void) ...@@ -2414,6 +2411,19 @@ static int __init init_scsi(void)
open_softirq(SCSI_SOFTIRQ, scsi_softirq, NULL); open_softirq(SCSI_SOFTIRQ, scsi_softirq, NULL);
return 0; return 0;
#ifdef CONFIG_PROC_FS
out_proc_error:
remove_proc_entry("scsi", 0);
#endif
out_error:
for (i = 0; i < SG_MEMPOOL_NR; i++) {
struct scsi_host_sg_pool *sgp = scsi_sg_pools + i;
mempool_destroy(sgp->pool);
kmem_cache_destroy(sgp->slab);
sgp->pool = NULL;
sgp->slab = NULL;
}
return -ENOMEM;
} }
static void __exit exit_scsi(void) static void __exit exit_scsi(void)
......
...@@ -104,6 +104,7 @@ static struct notifier_block sd_notifier_block = {sd_notifier, NULL, 0}; ...@@ -104,6 +104,7 @@ static struct notifier_block sd_notifier_block = {sd_notifier, NULL, 0};
static struct Scsi_Device_Template sd_template = { static struct Scsi_Device_Template sd_template = {
.module = THIS_MODULE, .module = THIS_MODULE,
.list = LIST_HEAD_INIT(sd_template.list),
.name = "disk", .name = "disk",
.tag = "sd", .tag = "sd",
.scsi_type = TYPE_DISK, .scsi_type = TYPE_DISK,
...@@ -453,10 +454,8 @@ static int sd_open(struct inode *inode, struct file *filp) ...@@ -453,10 +454,8 @@ static int sd_open(struct inode *inode, struct file *filp)
* The following code can sleep. * The following code can sleep.
* Module unloading must be prevented * Module unloading must be prevented
*/ */
if (sdp->host->hostt->module) if(!try_module_get(sdp->host->hostt->module))
__MOD_INC_USE_COUNT(sdp->host->hostt->module); return -ENOMEM;
if (sd_template.module)
__MOD_INC_USE_COUNT(sd_template.module);
sdp->access_count++; sdp->access_count++;
if (sdp->removable) { if (sdp->removable) {
...@@ -498,10 +497,7 @@ static int sd_open(struct inode *inode, struct file *filp) ...@@ -498,10 +497,7 @@ static int sd_open(struct inode *inode, struct file *filp)
error_out: error_out:
sdp->access_count--; sdp->access_count--;
if (sdp->host->hostt->module) module_put(sdp->host->hostt->module);
__MOD_DEC_USE_COUNT(sdp->host->hostt->module);
if (sd_template.module)
__MOD_DEC_USE_COUNT(sd_template.module);
return retval; return retval;
} }
...@@ -536,10 +532,7 @@ static int sd_release(struct inode *inode, struct file *filp) ...@@ -536,10 +532,7 @@ static int sd_release(struct inode *inode, struct file *filp)
if (scsi_block_when_processing_errors(sdp)) if (scsi_block_when_processing_errors(sdp))
scsi_set_medium_removal(sdp, SCSI_REMOVAL_ALLOW); scsi_set_medium_removal(sdp, SCSI_REMOVAL_ALLOW);
} }
if (sdp->host->hostt->module) module_put(sdp->host->hostt->module);
__MOD_DEC_USE_COUNT(sdp->host->hostt->module);
if (sd_template.module)
__MOD_DEC_USE_COUNT(sd_template.module);
return 0; return 0;
} }
...@@ -1241,6 +1234,7 @@ static int sd_attach(struct scsi_device * sdp) ...@@ -1241,6 +1234,7 @@ static int sd_attach(struct scsi_device * sdp)
gd->de = sdp->de; gd->de = sdp->de;
gd->major = SD_MAJOR(dsk_nr>>4); gd->major = SD_MAJOR(dsk_nr>>4);
gd->first_minor = (dsk_nr & 15)<<4; gd->first_minor = (dsk_nr & 15)<<4;
gd->minors = 16;
gd->fops = &sd_fops; gd->fops = &sd_fops;
if (dsk_nr > 26) if (dsk_nr > 26)
sprintf(gd->disk_name, "sd%c%c",'a'+dsk_nr/26-1,'a'+dsk_nr%26); sprintf(gd->disk_name, "sd%c%c",'a'+dsk_nr/26-1,'a'+dsk_nr%26);
......
...@@ -121,6 +121,7 @@ static rwlock_t sg_dev_arr_lock = RW_LOCK_UNLOCKED; /* Also used to lock ...@@ -121,6 +121,7 @@ static rwlock_t sg_dev_arr_lock = RW_LOCK_UNLOCKED; /* Also used to lock
static struct Scsi_Device_Template sg_template = { static struct Scsi_Device_Template sg_template = {
.module = THIS_MODULE, .module = THIS_MODULE,
.list = LIST_HEAD_INIT(sg_template.list),
.name = "generic", .name = "generic",
.tag = "sg", .tag = "sg",
.scsi_type = 0xff, .scsi_type = 0xff,
...@@ -261,8 +262,8 @@ sg_open(struct inode *inode, struct file *filp) ...@@ -261,8 +262,8 @@ sg_open(struct inode *inode, struct file *filp)
/* This driver's module count bumped by fops_get in <linux/fs.h> */ /* This driver's module count bumped by fops_get in <linux/fs.h> */
/* Prevent the device driver from vanishing while we sleep */ /* Prevent the device driver from vanishing while we sleep */
if (sdp->device->host->hostt->module) if (!try_module_get(sdp->device->host->hostt->module))
__MOD_INC_USE_COUNT(sdp->device->host->hostt->module); return -ENXIO;
sdp->device->access_count++; sdp->device->access_count++;
if (!((flags & O_NONBLOCK) || if (!((flags & O_NONBLOCK) ||
...@@ -317,8 +318,7 @@ sg_open(struct inode *inode, struct file *filp) ...@@ -317,8 +318,7 @@ sg_open(struct inode *inode, struct file *filp)
error_out: error_out:
sdp->device->access_count--; sdp->device->access_count--;
if ((!sdp->detached) && sdp->device->host->hostt->module) module_put(sdp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(sdp->device->host->hostt->module);
return retval; return retval;
} }
...@@ -336,9 +336,7 @@ sg_release(struct inode *inode, struct file *filp) ...@@ -336,9 +336,7 @@ sg_release(struct inode *inode, struct file *filp)
if (0 == sg_remove_sfp(sdp, sfp)) { /* Returns 1 when sdp gone */ if (0 == sg_remove_sfp(sdp, sfp)) { /* Returns 1 when sdp gone */
if (!sdp->detached) { if (!sdp->detached) {
sdp->device->access_count--; sdp->device->access_count--;
if (sdp->device->host->hostt->module) module_put(sdp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(sdp->device->host->hostt->
module);
} }
sdp->exclude = 0; sdp->exclude = 0;
wake_up_interruptible(&sdp->o_excl_wait); wake_up_interruptible(&sdp->o_excl_wait);
...@@ -1304,11 +1302,8 @@ sg_cmd_done(Scsi_Cmnd * SCpnt) ...@@ -1304,11 +1302,8 @@ sg_cmd_done(Scsi_Cmnd * SCpnt)
SCSI_LOG_TIMEOUT(1, printk("sg...bh: already closed, final cleanup\n")); SCSI_LOG_TIMEOUT(1, printk("sg...bh: already closed, final cleanup\n"));
if (0 == sg_remove_sfp(sdp, sfp)) { /* device still present */ if (0 == sg_remove_sfp(sdp, sfp)) { /* device still present */
sdp->device->access_count--; sdp->device->access_count--;
if (sdp->device->host->hostt->module) module_put(sdp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(sdp->device->host->hostt->module);
} }
if (sg_template.module)
__MOD_DEC_USE_COUNT(sg_template.module);
sfp = NULL; sfp = NULL;
} }
} else if (srp && srp->orphan) { } else if (srp && srp->orphan) {
...@@ -1539,12 +1534,7 @@ sg_detach(Scsi_Device * scsidp) ...@@ -1539,12 +1534,7 @@ sg_detach(Scsi_Device * scsidp)
} }
if (sfp->closed) { if (sfp->closed) {
sdp->device->access_count--; sdp->device->access_count--;
if (sg_template.module) module_put(sdp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(sg_template.module);
if (sdp->device->host->hostt->module)
__MOD_DEC_USE_COUNT(
sdp->device->host->
hostt->module);
__sg_remove_sfp(sdp, sfp); __sg_remove_sfp(sdp, sfp);
} else { } else {
delay = 1; delay = 1;
...@@ -2530,13 +2520,12 @@ sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp) ...@@ -2530,13 +2520,12 @@ sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp)
} }
write_unlock_irqrestore(&sg_dev_arr_lock, iflags); write_unlock_irqrestore(&sg_dev_arr_lock, iflags);
} else { } else {
sfp->closed = 1; /* flag dirty state on this fd */
sdp->device->access_count++;
/* MOD_INC's to inhibit unloading sg and associated adapter driver */ /* MOD_INC's to inhibit unloading sg and associated adapter driver */
if (sg_template.module) /* only bump the access_count if we actually succeeded in
__MOD_INC_USE_COUNT(sg_template.module); * throwing another counter on the host module */
if (sdp->device->host->hostt->module) if(try_module_get(sdp->device->host->hostt->module))
__MOD_INC_USE_COUNT(sdp->device->host->hostt->module); sdp->device->access_count++;
sfp->closed = 1; /* flag dirty state on this fd */
SCSI_LOG_TIMEOUT(1, printk("sg_remove_sfp: worrisome, %d writes pending\n", SCSI_LOG_TIMEOUT(1, printk("sg_remove_sfp: worrisome, %d writes pending\n",
dirty)); dirty));
} }
......
...@@ -72,6 +72,7 @@ static int sr_init_command(struct scsi_cmnd *); ...@@ -72,6 +72,7 @@ static int sr_init_command(struct scsi_cmnd *);
static struct Scsi_Device_Template sr_template = { static struct Scsi_Device_Template sr_template = {
.module = THIS_MODULE, .module = THIS_MODULE,
.list = LIST_HEAD_INIT(sr_template.list),
.name = "cdrom", .name = "cdrom",
.tag = "sr", .tag = "sr",
.scsi_type = TYPE_ROM, .scsi_type = TYPE_ROM,
...@@ -130,10 +131,7 @@ static void sr_release(struct cdrom_device_info *cdi) ...@@ -130,10 +131,7 @@ static void sr_release(struct cdrom_device_info *cdi)
if (cd->device->sector_size > 2048) if (cd->device->sector_size > 2048)
sr_set_blocklength(cd, 2048); sr_set_blocklength(cd, 2048);
cd->device->access_count--; cd->device->access_count--;
if (cd->device->host->hostt->module) module_put(cd->device->host->hostt->module);
__MOD_DEC_USE_COUNT(cd->device->host->hostt->module);
if (sr_template.module)
__MOD_DEC_USE_COUNT(sr_template.module);
} }
static struct cdrom_device_ops sr_dops = { static struct cdrom_device_ops sr_dops = {
...@@ -472,11 +470,9 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose) ...@@ -472,11 +470,9 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
if (!scsi_block_when_processing_errors(cd->device)) { if (!scsi_block_when_processing_errors(cd->device)) {
return -ENXIO; return -ENXIO;
} }
if(!try_module_get(cd->device->host->hostt->module))
return -ENXIO;
cd->device->access_count++; cd->device->access_count++;
if (cd->device->host->hostt->module)
__MOD_INC_USE_COUNT(cd->device->host->hostt->module);
if (sr_template.module)
__MOD_INC_USE_COUNT(sr_template.module);
/* If this device did not have media in the drive at boot time, then /* If this device did not have media in the drive at boot time, then
* we would have been unable to get the sector size. Check to see if * we would have been unable to get the sector size. Check to see if
......
...@@ -175,6 +175,7 @@ static void st_detach(Scsi_Device *); ...@@ -175,6 +175,7 @@ static void st_detach(Scsi_Device *);
static struct Scsi_Device_Template st_template = { static struct Scsi_Device_Template st_template = {
.module = THIS_MODULE, .module = THIS_MODULE,
.list = LIST_HEAD_INIT(st_template.list),
.name = "tape", .name = "tape",
.tag = "st", .tag = "st",
.scsi_type = TYPE_TAPE, .scsi_type = TYPE_TAPE,
...@@ -992,13 +993,13 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -992,13 +993,13 @@ static int st_open(struct inode *inode, struct file *filp)
DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); ) DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); )
return (-EBUSY); return (-EBUSY);
} }
if(!try_module_get(STp->device->host->hostt->module))
return (-ENXIO);
STp->device->access_count++;
STp->in_use = 1; STp->in_use = 1;
write_unlock(&st_dev_arr_lock); write_unlock(&st_dev_arr_lock);
STp->rew_at_close = STp->autorew_dev = (minor(inode->i_rdev) & 0x80) == 0; STp->rew_at_close = STp->autorew_dev = (minor(inode->i_rdev) & 0x80) == 0;
if (STp->device->host->hostt->module)
__MOD_INC_USE_COUNT(STp->device->host->hostt->module);
STp->device->access_count++;
if (!scsi_block_when_processing_errors(STp->device)) { if (!scsi_block_when_processing_errors(STp->device)) {
retval = (-ENXIO); retval = (-ENXIO);
...@@ -1040,8 +1041,7 @@ static int st_open(struct inode *inode, struct file *filp) ...@@ -1040,8 +1041,7 @@ static int st_open(struct inode *inode, struct file *filp)
normalize_buffer(STp->buffer); normalize_buffer(STp->buffer);
STp->in_use = 0; STp->in_use = 0;
STp->device->access_count--; STp->device->access_count--;
if (STp->device->host->hostt->module) module_put(STp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(STp->device->host->hostt->module);
return retval; return retval;
} }
...@@ -1175,8 +1175,7 @@ static int st_release(struct inode *inode, struct file *filp) ...@@ -1175,8 +1175,7 @@ static int st_release(struct inode *inode, struct file *filp)
STp->in_use = 0; STp->in_use = 0;
write_unlock(&st_dev_arr_lock); write_unlock(&st_dev_arr_lock);
STp->device->access_count--; STp->device->access_count--;
if (STp->device->host->hostt->module) module_put(STp->device->host->hostt->module);
__MOD_DEC_USE_COUNT(STp->device->host->hostt->module);
return result; return result;
} }
......
...@@ -1853,7 +1853,6 @@ char buf[32]; ...@@ -1853,7 +1853,6 @@ char buf[32];
printk("\n"); printk("\n");
printk(" Version %s - %s, Compiled %s at %s\n", printk(" Version %s - %s, Compiled %s at %s\n",
WD33C93_VERSION,WD33C93_DATE,__DATE__,__TIME__); WD33C93_VERSION,WD33C93_DATE,__DATE__,__TIME__);
MOD_INC_USE_COUNT;
} }
...@@ -2031,7 +2030,6 @@ void cleanup_module(void) {} ...@@ -2031,7 +2030,6 @@ void cleanup_module(void) {}
#endif #endif
void wd33c93_release(void) void wd33c93_release(void)
{ {
MOD_DEC_USE_COUNT;
} }
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
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