Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1058336ybg; Wed, 3 Jun 2020 23:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvCrYdtpmgwjlwmJQzQZL15wwtsMI361Z6flxz79OLVHKv1aVQ7LPW8jMu4bxi8MRgGV0K X-Received: by 2002:a17:906:60d3:: with SMTP id f19mr2599526ejk.478.1591250911323; Wed, 03 Jun 2020 23:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591250911; cv=none; d=google.com; s=arc-20160816; b=Dolx19OSrbfP5qeZRTdpk101JaVQkCl4+aQLUAi1p2eT+czk28jKl7FKHYx/HrQPts kO+iXDtmlpdXExT7GxI7TSc3crYqtTtap0yCgN28j0f5M6FgCO/9NfJozFCvakLk3K9j ktvYUjkg8eJq10S3V+Fz9AMZYHyxCbgj+PwDp7dmnFVFJYyiOtu9eTS3Gfxvdkju023W Vxz/fmR1utRiwMnnG3kHHOSLPTmmTs4F9NnF9THGvUBpZccRhYyRid3Tom/D0oCLe6po A1cELRCBEt0YMHs/WoStdhj7Cj3g6OiVvqtMLuRs0a8nX7uGvrtCKW78toXA8fPPVMHY GYwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=XXyzC49Oyik6OLj80BnTJFw8ULrNTOFKyFYaT9g2uYk=; b=ZNz/kU2RPEorakXPu++t9nfVJMwVwZkdmGZE2ZJW2xL8rCUO9Z2uoAKA+vbKYjgTn9 4V1f9W7ymEPIAukYJ2HJfElxEnJrDFahMUykwqJgxdH1FwBFqj4/bqj3jDJlaA2SWsUE XuExc5a8vwytJ2zZAJLvpG9ykMqVf2MAwnt6shaLVzvI/8eWXBBw7QCB3NoAol6IjsY2 QPWAkn05JwAOzMvbtSyloxDDWvmNWmvvgjC6pXJ9KS3MDStoyuw8CfeVolyDTvJ8Qg8z DTTpNxKMSbva6+g5JbqO7T1lxYIM+XYfhLGyRwtIZy5Jzz+WLpBT6MvIxj3POvOIr2lN iUEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oz26si1143711ejb.252.2020.06.03.23.08.07; Wed, 03 Jun 2020 23:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726668AbgFDGGA (ORCPT + 99 others); Thu, 4 Jun 2020 02:06:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:54212 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbgFDGF7 (ORCPT ); Thu, 4 Jun 2020 02:05:59 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77FA1AFC1; Thu, 4 Jun 2020 06:06:01 +0000 (UTC) Subject: Re: [PATCH] scsi: Fix incorrect usage of shost_for_each_device To: Ye Bin , martin.petersen@oracle.com, jejb@linux.ibm.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200518074420.39275-1-yebin10@huawei.com> From: Hannes Reinecke Message-ID: Date: Thu, 4 Jun 2020 08:05:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200518074420.39275-1-yebin10@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/18/20 9:44 AM, Ye Bin wrote: > shost_for_each_device(sdev, shost) \ > for ((sdev) = __scsi_iterate_devices((shost), NULL); \ > (sdev); \ > (sdev) = __scsi_iterate_devices((shost), (sdev))) > > When terminating shost_for_each_device() iteration with break or return, > scsi_device_put() should be used to prevent stale scsi device references from > being left behind. > > Signed-off-by: Ye Bin > --- > drivers/scsi/scsi_error.c | 2 ++ > drivers/scsi/scsi_lib.c | 4 +++- > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c > index 978be1602f71..927b1e641842 100644 > --- a/drivers/scsi/scsi_error.c > +++ b/drivers/scsi/scsi_error.c > @@ -1412,6 +1412,7 @@ static int scsi_eh_stu(struct Scsi_Host *shost, > sdev_printk(KERN_INFO, sdev, > "%s: skip START_UNIT, past eh deadline\n", > current->comm)); > + scsi_device_put(sdev); > break; > } > stu_scmd = NULL; > @@ -1478,6 +1479,7 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, > sdev_printk(KERN_INFO, sdev, > "%s: skip BDR, past eh deadline\n", > current->comm)); > + scsi_device_put(sdev); > break; > } > bdr_scmd = NULL; > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c > index be1a4a9a5fca..173bc7fc2836 100644 > --- a/drivers/scsi/scsi_lib.c > +++ b/drivers/scsi/scsi_lib.c > @@ -2859,8 +2859,10 @@ scsi_host_unblock(struct Scsi_Host *shost, int new_state) > > shost_for_each_device(sdev, shost) { > ret = scsi_internal_device_unblock(sdev, new_state); > - if (ret) > + if (ret) { > + scsi_device_put(sdev); > break; > + } > } > return ret; > } > Reviewed-by: Hannes Reinecke Cheers, Hannes -- Dr. Hannes Reinecke Teamlead Storage & Networking hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer