From patchwork Fri Oct 13 06:55:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ouyang Zhaowei (Charles)" X-Patchwork-Id: 10003547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 42C1F60325 for ; Fri, 13 Oct 2017 06:57:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 345F328FD8 for ; Fri, 13 Oct 2017 06:57:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2930228FDA; Fri, 13 Oct 2017 06:57:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA3EE28F15 for ; Fri, 13 Oct 2017 06:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753323AbdJMG5S (ORCPT ); Fri, 13 Oct 2017 02:57:18 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7994 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751024AbdJMG5S (ORCPT ); Fri, 13 Oct 2017 02:57:18 -0400 Received: from 172.30.72.58 (EHLO DGGEMS412-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DIZ04080; Fri, 13 Oct 2017 14:57:07 +0800 (CST) Received: from [127.0.0.1] (10.177.29.144) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.301.0; Fri, 13 Oct 2017 14:55:44 +0800 To: Tyrel Datwyler , , , CC: , Suoben , "Wulizhen (Pss)" From: "Ouyangzhaowei (Charles)" Subject: [RESEND PATCH] scsi: shost->async_scan should be protected by mutex_lock Message-ID: Date: Fri, 13 Oct 2017 14:55:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [10.177.29.144] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.59E063C3.00CA, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: de04c6e945dd384817aea521d2cd6f4c Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP shost->async_scan should be protected by mutex_lock, otherwise the check of "called twice" won't work. Signed-off-by: Ouyang Zhaowei --- drivers/scsi/scsi_scan.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; } 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; }