* [PATCH] scsi: shost->async_scan should be protected by mutex_lock @ 2017-09-08 6:54 Ouyangzhaowei (Charles) 2017-09-11 1:44 ` Tyrel Datwyler 0 siblings, 1 reply; 3+ messages in thread From: Ouyangzhaowei (Charles) @ 2017-09-08 6:54 UTC (permalink / raw) To: jejb, martin.petersen, linux-kernel; +Cc: linux-scsi, Suoben, Wulizhen (Pss) shost->async_scan should be protected by mutex_lock, otherwise the check of "called twice" won't work. Signed-off-by: Ouyang Zhaowei <ouyangzhaowei@huawei.com> --- drivers/scsi/scsi_scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index fd88dab..1d1df51 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1722,6 +1722,7 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) if (strncmp(scsi_scan_type, "sync", 4) == 0) return NULL; + mutex_lock(&shost->scan_mutex); if (shost->async_scan) { shost_printk(KERN_DEBUG, shost, "%s called twice\n", __func__); return NULL; @@ -1735,7 +1736,6 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) goto err; init_completion(&data->prev_finished); - mutex_lock(&shost->scan_mutex); spin_lock_irqsave(shost->host_lock, flags); shost->async_scan = 1; spin_unlock_irqrestore(shost->host_lock, flags); ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: shost->async_scan should be protected by mutex_lock 2017-09-08 6:54 [PATCH] scsi: shost->async_scan should be protected by mutex_lock Ouyangzhaowei (Charles) @ 2017-09-11 1:44 ` Tyrel Datwyler 2017-09-13 3:59 ` Ouyangzhaowei (Charles) 0 siblings, 1 reply; 3+ messages in thread From: Tyrel Datwyler @ 2017-09-11 1:44 UTC (permalink / raw) To: Ouyangzhaowei (Charles), jejb, martin.petersen, linux-kernel Cc: linux-scsi, Suoben, Wulizhen (Pss) On 09/07/2017 11:54 PM, Ouyangzhaowei (Charles) wrote: > shost->async_scan should be protected by mutex_lock, otherwise the check > of "called twice" won't work. > > Signed-off-by: Ouyang Zhaowei <ouyangzhaowei@huawei.com> > --- > drivers/scsi/scsi_scan.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c > index fd88dab..1d1df51 100644 > --- a/drivers/scsi/scsi_scan.c > +++ b/drivers/scsi/scsi_scan.c > @@ -1722,6 +1722,7 @@ static struct async_scan_data > *scsi_prep_async_scan(struct Scsi_Host *shost) > if (strncmp(scsi_scan_type, "sync", 4) == 0) > return NULL; > > + mutex_lock(&shost->scan_mutex); The mutex will not be unlocked in the event that either the host has called scsi_prep_async_scan() twice, or a condition is meet the branches to the "err" label prior to where the original mutex_lock() was located below. -Tyrel > if (shost->async_scan) { > shost_printk(KERN_DEBUG, shost, "%s called twice\n", > __func__); > return NULL; > @@ -1735,7 +1736,6 @@ static struct async_scan_data > *scsi_prep_async_scan(struct Scsi_Host *shost) > goto err; > init_completion(&data->prev_finished); > > - mutex_lock(&shost->scan_mutex); > spin_lock_irqsave(shost->host_lock, flags); > shost->async_scan = 1; > spin_unlock_irqrestore(shost->host_lock, flags); > ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: shost->async_scan should be protected by mutex_lock 2017-09-11 1:44 ` Tyrel Datwyler @ 2017-09-13 3:59 ` Ouyangzhaowei (Charles) 0 siblings, 0 replies; 3+ messages in thread From: Ouyangzhaowei (Charles) @ 2017-09-13 3:59 UTC (permalink / raw) To: Tyrel Datwyler, jejb, martin.petersen, linux-kernel Cc: linux-scsi, Suoben, Wulizhen (Pss) shost->async_scan should be protected by mutex_lock, otherwise the check of "called twice" won't work. Signed-off-by: Ouyang Zhaowei <ouyangzhaowei@huawei.com> --- drivers/scsi/scsi_scan.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index fd88dab..20d539b 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1722,9 +1722,10 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) if (strncmp(scsi_scan_type, "sync", 4) == 0) return NULL; + mutex_lock(&shost->scan_mutex); if (shost->async_scan) { shost_printk(KERN_DEBUG, shost, "%s called twice\n", __func__); - return NULL; + goto unlock; } data = kmalloc(sizeof(*data), GFP_KERNEL); @@ -1735,7 +1736,6 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) goto err; init_completion(&data->prev_finished); - mutex_lock(&shost->scan_mutex); spin_lock_irqsave(shost->host_lock, flags); shost->async_scan = 1; spin_unlock_irqrestore(shost->host_lock, flags); @@ -1751,6 +1751,8 @@ static struct async_scan_data *scsi_prep_async_scan(struct Scsi_Host *shost) err: kfree(data); + unlock: + mutex_unlock(&shost->scan_mutex); return NULL; } On 2017.9.11 9:44, Tyrel Datwyler wrote: > On 09/07/2017 11:54 PM, Ouyangzhaowei (Charles) wrote: >> shost->async_scan should be protected by mutex_lock, otherwise the check >> of "called twice" won't work. >> >> Signed-off-by: Ouyang Zhaowei <ouyangzhaowei@huawei.com> >> --- >> drivers/scsi/scsi_scan.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c >> index fd88dab..1d1df51 100644 >> --- a/drivers/scsi/scsi_scan.c >> +++ b/drivers/scsi/scsi_scan.c >> @@ -1722,6 +1722,7 @@ static struct async_scan_data >> *scsi_prep_async_scan(struct Scsi_Host *shost) >> if (strncmp(scsi_scan_type, "sync", 4) == 0) >> return NULL; >> >> + mutex_lock(&shost->scan_mutex); > > The mutex will not be unlocked in the event that either the host has called > scsi_prep_async_scan() twice, or a condition is meet the branches to the "err" label prior > to where the original mutex_lock() was located below. Thanks for the review, I modified the patch, please check it out again. > > -Tyrel > >> if (shost->async_scan) { >> shost_printk(KERN_DEBUG, shost, "%s called twice\n", >> __func__); >> return NULL; >> @@ -1735,7 +1736,6 @@ static struct async_scan_data >> *scsi_prep_async_scan(struct Scsi_Host *shost) >> goto err; >> init_completion(&data->prev_finished); >> >> - mutex_lock(&shost->scan_mutex); >> spin_lock_irqsave(shost->host_lock, flags); >> shost->async_scan = 1; >> spin_unlock_irqrestore(shost->host_lock, flags); >> > > > . > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-13 4:00 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-09-08 6:54 [PATCH] scsi: shost->async_scan should be protected by mutex_lock Ouyangzhaowei (Charles) 2017-09-11 1:44 ` Tyrel Datwyler 2017-09-13 3:59 ` Ouyangzhaowei (Charles)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®