Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752160AbdIKBob (ORCPT ); Sun, 10 Sep 2017 21:44:31 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36732 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752096AbdIKBoa (ORCPT ); Sun, 10 Sep 2017 21:44:30 -0400 X-Google-Smtp-Source: AOwi7QB6GNpwy4zb735Thxv6kLpxrP8JdIwOV5zPEcvReLgWClTWyKkxZy8X/6OVlAF6z0U3zN7QBA== Subject: Re: [PATCH] scsi: shost->async_scan should be protected by mutex_lock To: "Ouyangzhaowei (Charles)" , jejb@linux.vnet.ibm.com, martin.petersen@oracle.com, linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, Suoben , "Wulizhen (Pss)" References: From: Tyrel Datwyler Message-ID: <8e8d0a1b-f053-6eab-a85a-ec83201b50be@gmail.com> Date: Sun, 10 Sep 2017 18:44:26 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1471 Lines: 40 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 > --- > 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); >