Prepare for constifying SCSI host templates
Subsystems (4)
v5 cover Prepare for constifying SCSI host templates
Hi Martin,
This patch series prepares for constifying SCSI host templates by moving the members that are not constant out of the SCSI host template. This patch series is based on Linus' master branch instead of the SCSI for-next branch. Please consider this patch series for the next merge window.
Thanks,
Bart.
Changes compared to v4:
- Added three additional patches: fail host creation if creating the proc directory fails, a use-after-free fix and an improvement for the kernel module unload code.
Changes compared to v3:
- Changed the 'present' counter from 8 to 32 bits.
- Fixed a bug in an error path (reported by John Garry).
- Changed EXPORT_SYMBOL() into EXPORT_SYMBOL_GPL().
- Split patch 1/3 into two patches.
Changes compared to v2:
- Optimized the show_info == NULL case.
- Added a patch that removes the code that clears the module pointer in the host template.
Changes compared to v1:
- Fix the CONFIG_SCSI_PROC_FS=n build.
Bart Van Assche (7):
scsi: esas2r: Initialize two host template members implicitly
scsi: esas2r: Introduce scsi_template_proc_dir()
scsi: core: Fail host creation if creating the proc directory fails
scsi: core: Introduce a new list for SCSI proc directory entries
scsi: core: Fix a use-after-free related to releasing device handlers
module: Improve support for asynchronous module exit code
scsi: core: Improve SCSI device removal
drivers/scsi/esas2r/esas2r_main.c | 19 +++-- drivers/scsi/hosts.c | 3 +- drivers/scsi/scsi_priv.h | 6 +- drivers/scsi/scsi_proc.c | 124 +++++++++++++++++++++++++----- drivers/scsi/scsi_sysfs.c | 9 +-- include/linux/module.h | 1 + include/scsi/scsi_host.h | 18 ++--- kernel/module/main.c | 10 +++ 8 files changed, 143 insertions(+), 47 deletions(-)
PATCH v5 1/7 scsi: esas2r: Initialize two host template members implicitly
Prepare for removing the 'proc_dir' and 'present' members from the SCSI host template by implicitly initializing 'present' and 'emulated' in 'driver_template'.
--- drivers/scsi/esas2r/esas2r_main.c | 2 -- 1 file changed, 2 deletions(-)
drivers/scsi/esas2r/esas2r_main.c +0 -2
@@ -248,8 +248,6 @@ static struct scsi_host_template driver_template = { .sg_tablesize = SG_CHUNK_SIZE, .cmd_per_lun = ESAS2R_DEFAULT_CMD_PER_LUN, - .present = 0, - .emulated = 0, .proc_name = ESAS2R_DRVR_NAME, .change_queue_depth = scsi_change_queue_depth, .max_sectors = 0xFFFF,
PATCH v5 2/7 scsi: esas2r: Introduce scsi_template_proc_dir()
In reply to Bart Van AsschePrepare for removing the 'proc_dir' and 'present' members from the SCSI host template. This patch does not change any functionality.
--- drivers/scsi/esas2r/esas2r_main.c | 17 +++++++++++------ drivers/scsi/scsi_proc.c | 11 +++++++++++ include/scsi/scsi_host.h | 6 ++++++ 3 files changed, 28 insertions(+), 6 deletions(-)
drivers/scsi/esas2r/esas2r_main.c +11 -6
@@ -635,10 +635,13 @@ static void __exit esas2r_exit(void)esas2r_log (ESAS2R_LOG_INFO ,"%s called" , __func__);if (esas2r_proc_major >0 ) { +struct proc_dir_entry *proc_dir; +esas2r_log (ESAS2R_LOG_INFO ,"unregister proc" ); -remove_proc_entry (ATTONODE_NAME , - esas2r_proc_host->hostt->proc_dir); + proc_dir =scsi_template_proc_dir (esas2r_proc_host->hostt); +if (proc_dir) +remove_proc_entry (ATTONODE_NAME , proc_dir);unregister_chrdev (esas2r_proc_major,ESAS2R_DRVR_NAME ); esas2r_proc_major =0 ;
@@ -728,11 +731,13 @@ const char *esas2r_info(struct Scsi_Host *sh) esas2r_proc_major);if (esas2r_proc_major >0 ) { -struct proc_dir_entry *pde; +struct proc_dir_entry *proc_dir; +struct proc_dir_entry *pde =NULL ; - pde =proc_create (ATTONODE_NAME ,0 , - sh->hostt->proc_dir, - &esas2r_proc_ops); + proc_dir =scsi_template_proc_dir (sh->hostt); +if (proc_dir) + pde =proc_create (ATTONODE_NAME ,0 , proc_dir, + &esas2r_proc_ops);if (!pde) { esas2r_log_dev(ESAS2R_LOG_WARN,
drivers/scsi/scsi_proc.c +11 -0
@@ -83,6 +83,17 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file) 4 * PAGE_SIZE); } +/** +* scsi_template_proc_dir() - returns the procfs dir for a SCSI host template +* @sht: SCSI host template pointer. +*/ +struct proc_dir_entry * +scsi_template_proc_dir (const struct scsi_host_template *sht) +{ +return sht->proc_dir; +} +EXPORT_SYMBOL_GPL (scsi_template_proc_dir); +static const struct proc_ops proc_scsi_ops = { .proc_open = proc_scsi_host_open, .proc_release = single_release,
include/scsi/scsi_host.h +6 -0
@@ -751,6 +751,12 @@ extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);extern int __must_check scsi_add_host_with_dma (struct Scsi_Host *,struct device *,struct device *); +#if defined(CONFIG_SCSI_PROC_FS ) +struct proc_dir_entry * +scsi_template_proc_dir (const struct scsi_host_template *sht); +#else +#define scsi_template_proc_dir (sht) NULL +#endif extern void scsi_scan_host (struct Scsi_Host *);extern void scsi_rescan_device (struct device *);extern void scsi_remove_host (struct Scsi_Host *);
PATCH v5 3/7 scsi: core: Fail host creation if creating the proc directory fails
In reply to Bart Van AsscheUsers expect that the contents of /proc/scsi is in sync with the contents of /sys/class/scsi_host. Hence fail host creation if creating the proc directory fails.
--- drivers/scsi/hosts.c | 3 ++- drivers/scsi/scsi_priv.h | 4 ++-- drivers/scsi/scsi_proc.c | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-)
drivers/scsi/hosts.c +2 -1
@@ -519,7 +519,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) "failed to create tmf workq\n"); goto fail; } -scsi_proc_hostdir_add (shost->hostt); +if (scsi_proc_hostdir_add (shost->hostt) <0 ) + goto fail;return shost; fail:/*
drivers/scsi/scsi_priv.h +2 -2
@@ -100,14 +100,14 @@ extern void scsi_evt_thread(struct work_struct *work);/* scsi_proc.c */ #ifdef CONFIG_SCSI_PROC_FS -extern void scsi_proc_hostdir_add (struct scsi_host_template *); +extern int scsi_proc_hostdir_add (struct scsi_host_template *);extern void scsi_proc_hostdir_rm (struct scsi_host_template *);extern void scsi_proc_host_add (struct Scsi_Host *);extern void scsi_proc_host_rm (struct Scsi_Host *);extern int scsi_init_procfs (void );extern void scsi_exit_procfs (void );#else -# define scsi_proc_hostdir_add (sht) do { } while (0) +# define scsi_proc_hostdir_add (sht) 0# define scsi_proc_hostdir_rm (sht) do { } while (0)# define scsi_proc_host_add (shost) do { } while (0)# define scsi_proc_host_rm (shost) do { } while (0)
drivers/scsi/scsi_proc.c +9 -4
@@ -108,20 +108,25 @@ static const struct proc_ops proc_scsi_ops = {* * Sets sht->proc_dir to the new directory. */ - -void scsi_proc_hostdir_add (struct scsi_host_template *sht) +int scsi_proc_hostdir_add (struct scsi_host_template *sht) { +int ret =0 ; +if (!sht->show_info) -return ; +return 0 ;mutex_lock (&global_host_template_mutex);if (!sht->present++) { sht->proc_dir =proc_mkdir (sht->proc_name, proc_scsi); -if (!sht->proc_dir) +if (!sht->proc_dir) {printk (KERN_ERR "%s: proc_mkdir failed for %s\n" , __func__, sht->proc_name); + ret = -ENOMEM ; + } }mutex_unlock (&global_host_template_mutex); + +return ret; }/**
Re: [PATCH v5 3/7] scsi: core: Fail host creation if creating the proc directory fails
Quoted 11 lines · Bart Van Assche
Users expect that the contents of
/proc/scsiis in sync with the contents of/sys/class/scsi_host. Hence fail host creation if creating the proc directory fails.Cc Christoph Hellwig <[email protected]>Cc Ming Lei <[email protected]>Cc Hannes Reinecke <[email protected]>Cc John Garry <[email protected]>Cc Mike Christie <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
PATCH v5 4/7 scsi: core: Introduce a new list for SCSI proc directory entries
In reply to Bart Van AsscheInstead of using scsi_host_template members to track the SCSI proc directory entries, track these entries in a list. This patch changes the time needed for looking up the proc dir pointer from O(1) into O(n). I think this is acceptable since the number of SCSI host adapter types per host is usually small (less than ten).
This patch has been tested by attaching two USB storage devices to a qemu host:
$ grep -aH . /proc/scsi/usb-storage/* /proc/scsi/usb-storage/7: Host scsi7: usb-storage /proc/scsi/usb-storage/7: Vendor: QEMU /proc/scsi/usb-storage/7: Product: QEMU USB HARDDRIVE /proc/scsi/usb-storage/7:Serial Number: 1-0000:00:02.1:00.0-6 /proc/scsi/usb-storage/7: Protocol: Transparent SCSI /proc/scsi/usb-storage/7: Transport: Bulk /proc/scsi/usb-storage/7: Quirks: SANE_SENSE /proc/scsi/usb-storage/8: Host scsi8: usb-storage /proc/scsi/usb-storage/8: Vendor: QEMU /proc/scsi/usb-storage/8: Product: QEMU USB HARDDRIVE /proc/scsi/usb-storage/8:Serial Number: 1-0000:00:02.1:00.0-7 /proc/scsi/usb-storage/8: Protocol: Transparent SCSI /proc/scsi/usb-storage/8: Transport: Bulk /proc/scsi/usb-storage/8: Quirks: SANE_SENSE
This patch prepares for constifying most SCSI host templates.
--- drivers/scsi/scsi_priv.h | 4 +- drivers/scsi/scsi_proc.c | 112 ++++++++++++++++++++++++++++++++------- include/scsi/scsi_host.h | 12 ----- 3 files changed, 94 insertions(+), 34 deletions(-)
drivers/scsi/scsi_priv.h +2 -2
@@ -100,8 +100,8 @@ extern void scsi_evt_thread(struct work_struct *work);/* scsi_proc.c */ #ifdef CONFIG_SCSI_PROC_FS -extern int scsi_proc_hostdir_add (struct scsi_host_template *); -extern void scsi_proc_hostdir_rm (struct scsi_host_template *); +extern int scsi_proc_hostdir_add (const struct scsi_host_template *); +extern void scsi_proc_hostdir_rm (const struct scsi_host_template *);extern void scsi_proc_host_add (struct Scsi_Host *);extern void scsi_proc_host_rm (struct Scsi_Host *);extern int scsi_init_procfs (void );
drivers/scsi/scsi_proc.c +92 -20
181 lines not on this page · raw message
include/scsi/scsi_host.h +0 -12
@@ -357,12 +357,6 @@ struct scsi_host_template {*/ const char *proc_name; -/* -* Used to store the procfs directory if a driver implements the -* show_info method. -*/ -struct proc_dir_entry *proc_dir; -/* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number
@@ -423,12 +417,6 @@ struct scsi_host_template {*/ short cmd_per_lun; -/* -* present contains counter indicating how many boards of this -* type were found when we did the scan. -*/ -unsigned char present; -/* If use block layer to manage tags, this is tag allocation policy */ int tag_alloc_policy;
Re: [PATCH v5 4/7] scsi: core: Introduce a new list for SCSI proc directory entries
Quoted 27 lines · Bart Van Assche
Instead of using
scsi_host_templatemembers to track the SCSI proc directory entries, track these entries in a list. This patch changes the time needed for looking up the proc dir pointer from O(1) into O(n). I think this is acceptable since the number of SCSI host adapter types per host is usually small (less than ten).This patch has been tested by attaching two USB storage devices to a qemu host:
$ grep -aH . /proc/scsi/usb-storage/* /proc/scsi/usb-storage/7: Host scsi7: usb-storage /proc/scsi/usb-storage/7: Vendor: QEMU /proc/scsi/usb-storage/7: Product: QEMU USB HARDDRIVE /proc/scsi/usb-storage/7:Serial Number: 1-0000:00:02.1:00.0-6 /proc/scsi/usb-storage/7: Protocol: Transparent SCSI /proc/scsi/usb-storage/7: Transport: Bulk /proc/scsi/usb-storage/7: Quirks: SANE_SENSE /proc/scsi/usb-storage/8: Host scsi8: usb-storage /proc/scsi/usb-storage/8: Vendor: QEMU /proc/scsi/usb-storage/8: Product: QEMU USB HARDDRIVE /proc/scsi/usb-storage/8:Serial Number: 1-0000:00:02.1:00.0-7 /proc/scsi/usb-storage/8: Protocol: Transparent SCSI /proc/scsi/usb-storage/8: Transport: Bulk /proc/scsi/usb-storage/8: Quirks: SANE_SENSEThis patch prepares for constifying most SCSI host templates.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc Ming Lei <[email protected]>Cc Hannes Reinecke <[email protected]>Cc John Garry <[email protected]>Cc Mike Christie <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
I have some comments below, but no big ones, so:
Quoted 111 lines
--- drivers/scsi/scsi_priv.h | 4 +- drivers/scsi/scsi_proc.c | 112 ++++++++++++++++++++++++++++++++------- include/scsi/scsi_host.h | 12 ----- 3 files changed, 94 insertions(+), 34 deletions(-)drivers/scsi/scsi_priv.h +2
-2@@ -100,8 +100,8 @@ extern void scsi_evt_thread(struct work_struct *work);/* scsi_proc.c */ #ifdef CONFIG_SCSI_PROC_FS -extern int scsi_proc_hostdir_add (struct scsi_host_template *); -extern void scsi_proc_hostdir_rm (struct scsi_host_template *); +extern int scsi_proc_hostdir_add (const struct scsi_host_template *); +extern void scsi_proc_hostdir_rm (const struct scsi_host_template *);extern void scsi_proc_host_add (struct Scsi_Host *);extern void scsi_proc_host_rm (struct Scsi_Host *);extern int scsi_init_procfs (void );drivers/scsi/scsi_proc.c +48
-6@@ -43,8 +43,23 @@static struct proc_dir_entry *proc_scsi; -/* Protect sht->present and sht->proc_dir */ +/* Protects scsi_proc_list */ static DEFINE_MUTEX (global_host_template_mutex); +static LIST_HEAD (scsi_proc_list); + +/** +* struct scsi_proc_entry - (host template, SCSI proc dir) association +* @entry: entry in scsi_proc_list. +* @sht: SCSI host template associated with the procfs directory. +* @proc_dir: procfs directory associated with the SCSI host template. +* @present: Number of SCSI hosts instantiated for @sht. +*/ +struct scsi_proc_entry { +struct list_head entry; +const struct scsi_host_template *sht; +struct proc_dir_entry *proc_dir; +unsigned int present; +};static ssize_t proc_scsi_host_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos)@@ -83,6 +98,32 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file) 4 * PAGE_SIZE); } +static struct scsi_proc_entry * +__scsi_lookup_proc_entry (const struct scsi_host_template *sht) +{ +struct scsi_proc_entry *e; + +lockdep_assert_held (&global_host_template_mutex); + +list_for_each_entry (e, &scsi_proc_list, entry) +if (e->sht == sht) +return e; + +return NULL ; +} + +static struct scsi_proc_entry * +scsi_lookup_proc_entry (const struct scsi_host_template *sht) +{ +struct scsi_proc_entry *e; + +mutex_lock (&global_host_template_mutex); + e =__scsi_lookup_proc_entry (sht); +mutex_unlock (&global_host_template_mutex); + +return e; +} +/** * scsi_template_proc_dir() - returns the procfs dir for a SCSI host template * @sht: SCSI host template pointer. @@ -90,7 +131,9 @@ static int proc_scsi_host_open(struct inode *inode, struct file *file)struct proc_dir_entry *scsi_template_proc_dir (const struct scsi_host_template *sht) { -return sht->proc_dir; +struct scsi_proc_entry *e =scsi_lookup_proc_entry (sht); + +return e ? e->proc_dir :NULL ; }EXPORT_SYMBOL_GPL (scsi_template_proc_dir);@@ -108,24 +151,38 @@ static const struct proc_ops proc_scsi_ops = {* * Sets sht->proc_dir to the new directory. */ -int scsi_proc_hostdir_add (struct scsi_host_template *sht) +int scsi_proc_hostdir_add (const struct scsi_host_template *sht) { -int ret =0 ; +struct scsi_proc_entry *e; +int ret = -ENOMEM ;if (!sht->show_info)return 0 ;mutex_lock (&global_host_template_mutex); -if (!sht->present++) { - sht->proc_dir =proc_mkdir (sht->proc_name, proc_scsi);
drivers/scsi/scsi_proc.c static const struct proc_ops proc_scsi_ops = { · line 167
Quoted 10 lines
drivers/scsi/scsi_proc.c +5
-5-if (!sht->proc_dir) { -printk (KERN_ERR "%s: proc_mkdir failed for %s\n" , - __func__, sht->proc_name); - ret = -ENOMEM ; - } + e =__scsi_lookup_proc_entry (sht); +if (!e) { + e =kzalloc (sizeof (*e),GFP_KERNEL ); +if (!e) + goto unlock;
maybe it's better to set ret = -ENOMEM here (and not initialize ret), as every other path it is set, AFAICS
Quoted 6 lines
drivers/scsi/scsi_proc.c +5
-0} +if (e->present++) + goto success; + e->proc_dir =proc_mkdir (sht->proc_name, proc_scsi); +if (!e->proc_dir) { + printk(KERN_ERR "%s: proc_mkdir failed for %s\n", __func__,
drivers/scsi/scsi_proc.c static const struct proc_ops proc_scsi_ops = { · line 183
Quoted 10 lines
drivers/scsi/scsi_proc.c +9
-0+ sht->proc_name); + goto unlock; + } + e->sht = sht; +list_add_tail (&e->entry, &scsi_proc_list); +success: + e =NULL ; + ret =0 ; +unlock:mutex_unlock (&global_host_template_mutex);
Note: The code might be just neater to have multiple calls to mutex_unlock(). Maybe you have looked at that, I don't know.
Quoted 33 lines
drivers/scsi/scsi_proc.c +8
-4+kfree (e);return ret; }@@ -133,15 +190,19 @@ int scsi_proc_hostdir_add(struct scsi_host_template *sht)* scsi_proc_hostdir_rm - remove directory in /proc for a scsi host * @sht: owner of directory */ -void scsi_proc_hostdir_rm (struct scsi_host_template *sht) +void scsi_proc_hostdir_rm (const struct scsi_host_template *sht) { +struct scsi_proc_entry *e; +if (!sht->show_info)return ;mutex_lock (&global_host_template_mutex); -if (!--sht->present && sht->proc_dir) { + e =__scsi_lookup_proc_entry (sht); +if (e && !--e->present) {remove_proc_entry (sht->proc_name, proc_scsi); - sht->proc_dir =NULL ; +list_del (&e->entry); +kfree (e); }mutex_unlock (&global_host_template_mutex); }@@ -153,16 +214,21 @@ void scsi_proc_hostdir_rm(struct scsi_host_template *sht)*/ void scsi_proc_host_add (struct Scsi_Host *shost) { -struct scsi_host_template *sht = shost->hostt;
drivers/scsi/scsi_proc.c void scsi_proc_hostdir_rm(struct scsi_host_template *sht) · line 225
Quoted 10 lines
drivers/scsi/scsi_proc.c +6
-1+const struct scsi_host_template *sht = shost->hostt; +struct scsi_proc_entry *e;struct proc_dir_entry *p;char name[10 ]; -if (!sht->proc_dir) +if (!sht->show_info) +return ; + + e =scsi_lookup_proc_entry (sht);
hmm... this really should not fail, right?. Maybe an error message would be appropiate here (for failure).
Quoted 14 lines
drivers/scsi/scsi_proc.c +3
-2+if (!e)return ;sprintf (name,"%d" , shost->host_no); - p =proc_create_data (name,S_IRUGO |S_IWUSR , - sht->proc_dir, &proc_scsi_ops, shost); + p =proc_create_data (name,S_IRUGO |S_IWUSR , e->proc_dir, + &proc_scsi_ops, shost);if (!p) printk(KERN_ERR "%s: Failed to register host %d in" "%s\n", __func__, shost->host_no,@@ -175,13 +241,19 @@ void scsi_proc_host_add(struct Scsi_Host *shost)*/ void scsi_proc_host_rm (struct Scsi_Host *shost)
drivers/scsi/scsi_proc.c void scsi_proc_host_add(struct Scsi_Host *shost) · line 251
Quoted 10 lines
drivers/scsi/scsi_proc.c +6
-1{ +const struct scsi_host_template *sht = shost->hostt; +struct scsi_proc_entry *e;char name[10 ]; -if (!shost->hostt->proc_dir) +if (!sht->show_info) +return ; + + e =scsi_lookup_proc_entry (sht);
Same comment as scsi_proc_host_add
Quoted 41 lines
drivers/scsi/scsi_proc.c +2
-1+if (!e)return ;sprintf (name,"%d" , shost->host_no); -remove_proc_entry (name, shost->hostt->proc_dir); +remove_proc_entry (name, e->proc_dir); }/** * proc_print_scsidevice - return data about this host include/scsi/scsi_host.h +0
-12@@ -357,12 +357,6 @@ struct scsi_host_template {*/ const char *proc_name; -/* -* Used to store the procfs directory if a driver implements the -* show_info method. -*/ -struct proc_dir_entry *proc_dir; -/* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number @@ -423,12 +417,6 @@ struct scsi_host_template {*/ short cmd_per_lun; -/* -* present contains counter indicating how many boards of this -* type were found when we did the scan. -*/ -unsigned char present; -/* If use block layer to manage tags, this is tag allocation policy */ int tag_alloc_policy;.
Re: [PATCH v5 4/7] scsi: core: Introduce a new list for SCSI proc directory entries
Quoted 16 lines · John Garry
Quoted 15 lines · Bart Van Assche
drivers/scsi/scsi_proc.c +1
-1-int scsi_proc_hostdir_add (struct scsi_host_template *sht) +int scsi_proc_hostdir_add (const struct scsi_host_template *sht){
- int ret = 0;
+ structscsi_proc_entry*e;
+ int ret =-ENOMEM;
if (!sht->show_info)
return 0;mutex_lock(&global_host_template_mutex);
- if (!sht->present++) {
-sht->proc_dir=proc_mkdir(sht->proc_name, proc_scsi); - if (!sht->proc_dir) {
- printk(KERN_ERR "%s:proc_mkdirfailed for %s\n", -__func__,sht->proc_name);
- ret =-ENOMEM;
Quoted 8 lines
Quoted 6 lines
- }
+ e =__scsi_lookup_proc_entry(sht);
+ if (!e) {
+ e =kzalloc(sizeof(*e), GFP_KERNEL);
+ if (!e)
+ goto unlock;maybe it's better to set ret =
-ENOMEMhere (and not initialize ret), as every other path it is set, AFAICS
I will make this change and also set ret if proc_mkdir() fails.
Quoted 13 lines
Quoted 4 lines
void
scsi_proc_host_add(struct Scsi_Host *shost){
- structscsi_host_template*sht =shost->hostt; + const structscsi_host_template*sht =shost->hostt;Quoted 8 lines
+ struct
scsi_proc_entry*e;
structproc_dir_entry*p;
char name[10];
- if (!sht->proc_dir)
+ if (!sht->show_info)
+ return;
+
+ e =scsi_lookup_proc_entry(sht);
Quoted 1 line
hmm... this really should not fail, right?. Maybe an error message would be appropiate here (for failure).
If scsi_proc_hostdir_add() failed scsi_lookup_proc_entry() will return NULL. I will add an error message.
Quoted 16 lines
Quoted 16 lines
+ if (!e)
return;
sprintf(name,"%d", shost->host_no);
- p = proc_create_data(name,S_IRUGO|S_IWUSR,
-sht->proc_dir,&proc_scsi_ops, shost);
+ p =proc_create_data(name, S_IRUGO | S_IWUSR, e->proc_dir, + &proc_scsi_ops, shost);
if (!p)
printk(KERN_ERR "%s: Failed to register host %d in" "%s\n",__func__,shost->host_no,drivers/scsi/scsi_proc.c +2
-0@@ -175,13 +241,19 @@ void scsi_proc_host_add(struct Scsi_Host *shost)*/ void scsi_proc_host_rm(struct Scsi_Host *shost) { + const struct scsi_host_template *sht = shost->hostt; + struct scsi_proc_entry *e;
Quoted 8 lines
drivers/scsi/scsi_proc.c void scsi_proc_host_add(struct Scsi_Host *shost) · line 251
Quoted 6 lines
drivers/scsi/scsi_proc.c +4
-1char name[10]; - if (!shost->hostt->proc_dir) + if (!sht->show_info) + return; + + e = scsi_lookup_proc_entry(sht);Same comment as
scsi_proc_host_add
If scsi_proc_hostdir_add() failed scsi_lookup_proc_entry() will return NULL.
Thanks,
Bart.
PATCH v5 5/7 scsi: core: Fix a use-after-free related to releasing device handlers
In reply to Bart Van AsscheThe SCSI device name can be freed by kobject_cleanup() before scsi_device_dev_release_usercontext() is called since the latter function may be called asynchronously. Hence, the SCSI device name must not be dereferenced from inside the SCSI device release function. Since scsi_dh_release_device() dereferences the SCSI device name, call it earlier. This patch fixes the following use-after-free:
BUG: KASAN: use-after-free in string+0xdc/0x1d0 Read of size 1 at addr ffff8881280d05f0 by task kworker/54:2/1373 CPU: 54 PID: 1373 Comm: kworker/54:2 Tainted: G E 6.0.0-rc5-dbg #12 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.0-debian-1.16.0-4 04/01/2014 Workqueue: events scsi_device_dev_release_usercontext Call Trace: <TASK> show_stack+0x4e/0x53 dump_stack_lvl+0x51/0x66 print_address_description.constprop.0.cold+0xd5/0x412 print_report.cold+0x90/0x219 kasan_report+0xb1/0xe0 __asan_load1+0x4d/0x50 string+0xdc/0x1d0 vsnprintf+0x44d/0x7f0 snprintf+0x88/0xa0 dev_vprintk_emit+0x19c/0x1dc dev_printk_emit+0x8c/0xa6 __dev_printk+0x73/0x8f _dev_printk+0xa8/0xbe sdev_prefix_printk+0x12c/0x180 scsi_dh_release_device+0x74/0xa0 scsi_device_dev_release_usercontext+0x60/0x8a0 process_one_work+0x571/0xa40 worker_thread+0x90/0x650 kthread+0x185/0x1c0 ret_from_fork+0x1f/0x30 Freed by task 509: kasan_save_stack+0x26/0x50 kasan_set_track+0x25/0x30 kasan_set_free_info+0x24/0x40 ____kasan_slab_free+0x155/0x1c0 __kasan_slab_free+0x12/0x20 kfree+0x1fe/0x3e0 kfree_const+0x21/0x30 kobject_cleanup+0x8d/0x1c0 kobject_put+0x6e/0x90 put_device+0x13/0x20 __scsi_remove_device+0x140/0x200 scsi_forget_host+0xa7/0xb0 scsi_remove_host+0x9b/0x1b0 srp_remove_work+0x12b/0x2e0 [ib_srp] process_one_work+0x571/0xa40 worker_thread+0x90/0x650 kthread+0x185/0x1c0 ret_from_fork+0x1f/0x30
--- drivers/scsi/scsi_sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +3 -2
@@ -456,8 +456,6 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) mod = sdev->host->hostt->module; -scsi_dh_release_device (sdev); - parent = sdev->sdev_gendev.parent;spin_lock_irqsave (sdev->host->host_lock, flags);
@@ -1479,6 +1477,9 @@ void __scsi_remove_device(struct scsi_device *sdev)kref_put (&sdev->host->tagset_refcnt, scsi_mq_free_tags);cancel_work_sync (&sdev->requeue_work); +/* Only detach the device handler after I/O processing has finished. */ +scsi_dh_release_device (sdev); +if (sdev->host->hostt->slave_destroy) sdev->host->hostt->slave_destroy (sdev);transport_destroy_device (dev);
PATCH v5 6/7 module: Improve support for asynchronous module exit code
In reply to Bart Van AsscheSome kernel modules call device_del() from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers call scsi_remove_host() from their module exit code. scsi_remove_host() may invoke scsi_device_dev_release_usercontext() asynchronously. scsi_device_dev_release_usercontext() uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in the delete_module() system call until the module reference count drops to zero.
The following debug patch has been used to make the new wait_event() call wait:
drivers/scsi/scsi_sysfs.c +2 -0
@@ -14,6 +14,7 @@#include <linux/device.h> #include <linux/pm_runtime.h> #include <linux/bsg.h> +#include <linux/delay.h> #include <scsi/scsi.h> #include <scsi/scsi_device.h>
@@ -518,6 +519,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)if (parent)put_device (parent); +msleep (100 );module_put (mod); }
kernel/module/main.c +3 -1
@@ -756,8 +756,10 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,* unloading is not forced, wait for the module reference count to drop * to zero again. */ -if (!forced) +if (!forced) { +WARN_ON_ONCE (atomic_read (&mod->refcnt));wait_event (mod->refcnt_wq,atomic_read (&mod->refcnt) ==0 ); + }blocking_notifier_call_chain (&module_notify_list,MODULE_STATE_GOING , mod);klp_module_going (mod);
kernel/workqueue.c +1 -1
@@ -3355,7 +3355,7 @@ int schedule_on_each_cpu(work_func_t func)*/ int execute_in_process_context (work_func_t fn,struct execute_work *ew) { -if (!in_interrupt ()) { +if (false && !in_interrupt ()) {fn (&ew->work);return 0 ; }
--- include/linux/module.h | 1 + kernel/module/main.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
include/linux/module.h +1 -0
@@ -533,6 +533,7 @@ struct module {/* Destruction function. */ void (*exit)(void ); +wait_queue_head_t refcnt_wq;atomic_t refcnt;#endif
kernel/module/main.c +10 -0
@@ -550,6 +550,7 @@ static int module_unload_init(struct module *mod)/* Hold reference count during initialization. */ atomic_inc (&mod->refcnt); +init_waitqueue_head (&mod->refcnt_wq);return 0 ; }
@@ -750,6 +751,13 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,/* Final destruction now no one is using it. */ if (mod->exit !=NULL ) mod->exit (); +/* +* If the module reference count was increased by mod->exit() and if +* unloading is not forced, wait for the module reference count to drop +* to zero again. +*/ +if (!forced) +wait_event (mod->refcnt_wq,atomic_read (&mod->refcnt) ==0 );blocking_notifier_call_chain (&module_notify_list,MODULE_STATE_GOING , mod);klp_module_going (mod);
@@ -854,6 +862,8 @@ void module_put(struct module *module)WARN_ON (ret <0 );/* Failed to put refcount */ trace_module_put (module, _RET_IP_);preempt_enable (); +if (ret ==0 ) +wake_up (&module->refcnt_wq); } }EXPORT_SYMBOL (module_put);
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 10 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callscsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.
Hi Luis,
I'd like to know your opinion about this patch since you are the maintainer of the kernel module system.
Thanks,
Bart.
Luis Chamberlain
maintainerRe: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 12 lines · Bart Van Assche
Quoted 10 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callscsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.
Quoted 4 lines
Hi Luis,
I'd like to know your opinion about this patch since you are the maintainer of the kernel module system.
See this patch which extends the documentation of try_module_get():
https://lkml.kernel.org/r/[email protected]
You can ignore discussion around the thread as sadly it is just irrelevant stuff not about that patch. But the logic it spells out is still true.
So, in short, using try_module_get() on exit is actually the wrong thing to do and it is no surprise it would fail. I haven't gotten yet around to reviewing Mauro's driver API which let's you unbind drivers, but it sounds related so I CC'd you on that.
So I'd like to ask instead if an alternative to using try_module_get() on exit would be better here and for the future.
Luis
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 26 lines · Luis Chamberlain
Quoted 12 lines · Bart Van Assche
Quoted 10 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callscsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.Quoted 4 lines
Hi Luis,
I'd like to know your opinion about this patch since you are the maintainer of the kernel module system.
See this patch which extends the documentation of
try_module_get():https://lkml.kernel.org/r/[email protected]
You can ignore discussion around the thread as sadly it is just irrelevant stuff not about that patch. But the logic it spells out is still true.
Quoted 7 lines
So, in short, using
try_module_get()on exit is actually the wrong thing to do and it is no surprise it would fail. I haven't gotten yet around to reviewing Mauro's driver API which let's you unbind drivers, but it sounds related so I CC'd you on that.So I'd like to ask instead if an alternative to using
try_module_get()on exit would be better here and for the future.
Hi Luis,
The extended documentation of try_module_get() is very helpful. But please note that this patch is not related to try_module_get() at all. See also patch 7/7 in this series (https://lore.kernel.org/linux-scsi/[email protected]/).
Thanks,
Bart.
Luis Chamberlain
maintainerRe: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 32 lines · Bart Van Assche
Quoted 31 lines · Luis Chamberlain
Quoted 12 lines · Bart Van Assche
Quoted 10 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callscsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.Quoted 4 lines
Hi Luis,
I'd like to know your opinion about this patch since you are the maintainer of the kernel module system.
See this patch which extends the documentation of
try_module_get():https://lkml.kernel.org/r/[email protected]
You can ignore discussion around the thread as sadly it is just irrelevant stuff not about that patch. But the logic it spells out is still true.
So, in short, using
try_module_get()on exit is actually the wrong thing to do and it is no surprise it would fail. I haven't gotten yet around to reviewing Mauro's driver API which let's you unbind drivers, but it sounds related so I CC'd you on that.
Quoted 8 lines
Quoted 2 lines
So I'd like to ask instead if an alternative to using
try_module_get()on exit would be better here and for the future.Hi Luis,
The extended documentation of
try_module_get()is very helpful. But please
note that this patch is not related totry_module_get()at all. See also
patch 7/7 in this series (https://lore.kernel.org/linux-scsi/[email protected]/).
I cannot see how this patch set is no way related to try_module_get() given the 7/7 patch you posted replaces try_module_get() with __module_get(). My point, and hint, is that the original construct that added try_module_get() on removal was flawed and I'm not sure trying to expand on that idea would or even *should* be fruitful given the issues / tribal knowledge I tried extending documentation for.
It would beg the question if instead re-evaluating the goal could be done in such a way that the new documentation I suggested on try_module_get() would be seriously taken into account.
Luis
Luis Chamberlain
maintainerRe: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 49 lines · Luis Chamberlain
Quoted 32 lines · Bart Van Assche
Quoted 31 lines · Luis Chamberlain
Quoted 12 lines · Bart Van Assche
Quoted 10 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callscsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.Quoted 4 lines
Hi Luis,
I'd like to know your opinion about this patch since you are the maintainer of the kernel module system.
See this patch which extends the documentation of
try_module_get():https://lkml.kernel.org/r/[email protected]
You can ignore discussion around the thread as sadly it is just irrelevant stuff not about that patch. But the logic it spells out is still true.
So, in short, using
try_module_get()on exit is actually the wrong thing to do and it is no surprise it would fail. I haven't gotten yet around to reviewing Mauro's driver API which let's you unbind drivers, but it sounds related so I CC'd you on that.Quoted 8 lines
Quoted 2 lines
So I'd like to ask instead if an alternative to using
try_module_get()on exit would be better here and for the future.Hi Luis,
The extended documentation of
try_module_get()is very helpful. But please
note that this patch is not related totry_module_get()at all. See also
patch 7/7 in this series (https://lore.kernel.org/linux-scsi/[email protected]/).I cannot see how this patch set is no way related to
try_module_get()given the 7/7 patch you posted replacestry_module_get()with__module_get(). My point, and hint, is that the original construct that addedtry_module_get()on removal was flawed and I'm not sure trying to expand on that idea would or even *should* be fruitful given the issues / tribal knowledge I tried extending documentation for.
Quoted 3 lines
It would beg the question if instead re-evaluating the goal could be done in such a way that the new documentation I suggested on
try_module_get()would be seriously taken into account.
Yeah I've gone ahead and re-read your original patch again the issue with that is it waits *once* for the refcnt to go to 0, but that does not forbit it from going back up, at which point you have a race which can still create the situation. Every subsystem is different, but for instance simply running a loop opening a device block file should suffice to bump the refcnt of a respective block driver module. So at least the patch itself won't ultimately address this issue I'm afraid.
Luis
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 8 lines · Luis Chamberlain
Yeah I've gone ahead and re-read your original patch again the issue with that is it waits *once* for the refcnt to go to 0, but that does not forbit it from going back up, at which point you have a race which can still create the situation. Every subsystem is different, but for instance simply running a loop opening a device block file should suffice to bump the refcnt of a respective block driver module. So at least the patch itself won't ultimately address this issue I'm afraid.
Hi Luis,
Thanks for the feedback. I will try to find a solution that does not require to modify the kernel module code.
Bart.
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
In reply to Bart Van AsscheQuoted 3 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers call
It isn't only related with device, any kobject has such issue, or any reference counter usage has similar potential risk, see previous discussion:
https://lore.kernel.org/lkml/YsZm7lSXYAHT14ui@T590/
IMO, it is one fundamental problem wrt. module vs. reference counting or kobject uses at least, since the callback depends on module code segment.
Quoted 7 lines
scsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.
The issue can't be addressed by the normal mod->refcnt, since user need to unload module when the device isn't used.
thanks,
Ming
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 22 lines · Ming Lei
Quoted 3 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callIt isn't only related with device, any kobject has such issue, or any reference counter usage has similar potential risk, see previous discussion:
https://lore.kernel.org/lkml/YsZm7lSXYAHT14ui@T590/
IMO, it is one fundamental problem wrt. module vs. reference counting or kobject uses at least, since the callback depends on module code segment.
Quoted 7 lines
scsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.
Quoted 2 lines
The issue can't be addressed by the normal
mod->refcnt, since user need to unload module when the device isn't used.
Hi Ming,
How about removing support for calling scsi_device_put() from atomic context as is done in the untested patch below?
Thanks,
Bart.
drivers/scsi/scsi.c +3 -0
@@ -561,6 +561,8 @@ EXPORT_SYMBOL(scsi_report_opcode);*/ int scsi_device_get (struct scsi_device *sdev) { +might_sleep (); +if (sdev->sdev_state ==SDEV_DEL || sdev->sdev_state ==SDEV_CANCEL ) goto fail;if (!get_device (&sdev->sdev_gendev))
@@ -588,6 +590,7 @@ void scsi_device_put(struct scsi_device *sdev) {struct module *mod = sdev->host->hostt->module; +might_sleep ();put_device (&sdev->sdev_gendev);module_put (mod); }
drivers/scsi/scsi_sysfs.c +2 -18
@@ -441,7 +441,7 @@ static void scsi_device_cls_release(struct device *class_dev)put_device (&sdev->sdev_gendev); } -static void scsi_device_dev_release_usercontext (struct work_struct *work) +static void scsi_device_dev_release (struct device *dev) {struct scsi_device *sdev;struct device *parent;
@@ -450,11 +450,8 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)struct scsi_vpd *vpd_pg0 =NULL , *vpd_pg89 =NULL ;struct scsi_vpd *vpd_pgb0 =NULL , *vpd_pgb1 =NULL , *vpd_pgb2 =NULL ;unsigned long flags; -struct module *mod; - - sdev = container_of(work, struct scsi_device, ew.work); - mod = sdev->host->hostt->module; + sdev =to_scsi_device (dev); parent = sdev->sdev_gendev.parent;
@@ -516,19 +513,6 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)if (parent)put_device (parent); -module_put (mod); -} - -static void scsi_device_dev_release (struct device *dev) -{ -struct scsi_device *sdp =to_scsi_device (dev); - -/* Set module pointer as NULL in case of module unloading */ -if (!try_module_get (sdp->host->hostt->module)) - sdp->host->hostt->module =NULL ; - -execute_in_process_context (scsi_device_dev_release_usercontext, - &sdp->ew); }static struct class sdev_class = {
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 23 lines · Bart Van Assche
Quoted 22 lines · Ming Lei
Quoted 3 lines · Bart Van Assche
Some kernel modules call
device_del()from their module exit code and schedule asynchronous work from inside the .release callback without waiting until that callback has finished. As an example, many SCSI LLD drivers callIt isn't only related with device, any kobject has such issue, or any reference counter usage has similar potential risk, see previous discussion:
https://lore.kernel.org/lkml/YsZm7lSXYAHT14ui@T590/
IMO, it is one fundamental problem wrt. module vs. reference counting or kobject uses at least, since the callback depends on module code segment.
Quoted 7 lines
scsi_remove_host()from their module exit code.scsi_remove_host()may invokescsi_device_dev_release_usercontext()asynchronously.scsi_device_dev_release_usercontext()uses the host template pointer and that pointer usually exists in static storage in the SCSI LLD. Support using the module reference count to keep the module around until asynchronous module exiting has completed by waiting in thedelete_module()system call until the module reference count drops to zero.
Quoted 7 lines
Quoted 2 lines
The issue can't be addressed by the normal
mod->refcnt, since user need to unload module when the device isn't used.Hi Ming,
How about removing support for calling
scsi_device_put()from atomic context as is done in the untested patch below?
That can't work.
The problem is that no existed mechanism can guarantee that kobject reference drops to zero inside module_exit().
Thanks,
Ming
Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code
Quoted 8 lines · Ming Lei
Quoted 2 lines · Bart Van Assche
How about removing support for calling
scsi_device_put()from atomic context as is done in the untested patch below?That can't work.
The problem is that no existed mechanism can guarantee that kobject reference drops to zero inside
module_exit().
Hi Ming,
I agree that the patch in my previous email won't address potential calls of .release functions while a module is being unloaded or after a module has been unloaded. However, that's not the purpose of that patch. The purpose of that patch is to rework all code that modifies members of the scsi host template.
Thanks,
Bart.
PATCH v5 7/7 scsi: core: Improve SCSI device removal
In reply to Bart Van AsscheInstead of clearing the host template module pointer if the LLD kernel module is being unloaded, call __module_get() unconditionally. This patch is a bug fix because it prevents that a SCSI LLD is unloaded after scsi_device_dev_release() returns and before scsi_device_dev_release_usercontext() is called.
--- drivers/scsi/scsi_sysfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/scsi_sysfs.c +1 -3
@@ -523,9 +523,7 @@ static void scsi_device_dev_release(struct device *dev) {struct scsi_device *sdp =to_scsi_device (dev); -/* Set module pointer as NULL in case of module unloading */ -if (!try_module_get (sdp->host->hostt->module)) - sdp->host->hostt->module =NULL ; +__module_get (sdp->host->hostt->module);execute_in_process_context (scsi_device_dev_release_usercontext, &sdp->ew);