Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2519993ybk; Mon, 18 May 2020 00:51:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlE9YA/NENH95cA+YuRKstkNmXOxDUl7SAZS4nDocNzGtMhTcb4afKbQNKNSVQMbkbDXVE X-Received: by 2002:a17:906:fcb9:: with SMTP id qw25mr12196825ejb.326.1589788289399; Mon, 18 May 2020 00:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589788289; cv=none; d=google.com; s=arc-20160816; b=GVNl0uB1N1NlKEc1OgUmYmF6iaocXfFs7FK58ysrPXnEHWZZ66t7sxwbh5RiTjNszz QQEfB8TZgsvRW3Wx5iCxZE7yZZb+EEx5B1f0rHiQNFKSTbSyZeGNYU46QtfpsCqZOJC6 4Pj5dleuX/ie5yeNIxX8d6ufu0VvC1DD/Xdm2ZaoSUfc82FxXMm/mFL/Fe4HMSyNlhZN FECcwKlVRrq+SYTcK4AxDOA0xNrFf6zU3f1CT8O/Vsb90CeTN0+fAtLUvGz8bdXyf2UH WAy0p8fEzfWioNh8qs64krB0MsVT1NI8v1HwiUGEBsK1rOgGCjPFsNXAmyRtI5VRTJEy 96DQ== 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:mime-version :message-id:date:subject:cc:to:from; bh=X54sFtRddlZunb+kWsqAab2xTXRQfUM87AzA/ocDFJU=; b=qXFWzPuhJ5uEt0ChvVcq8JvIZbMS9M0AHJxpD0ltUtSlY0NVCwcBImCt6zm4VIDqJt LiS9BOJe6H/rctSAVNdjA1JHbkTTZnhCJpY9bbvMgDU1fjufggisaKqV3WHeIiAKchk9 2DPJ5EavkD0kgWq21bLTFzWiV/YxfjHcjbqmrbYwuUuNp3ipgnDbmrr0lehDDpIaP5WL DbW7On9pAPKsUiIEE52RX6fNkA91HmDqj/36PhPLgBcvqOD/WsawlVVqbKOumcpaqjn2 1O8lJ22mzbQhPMg887oJ6vzhwRs7hAa/zFStZSwYt8Gq0KZ6Y5whR2aqc/gDzzzlqr+D xMJw== 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 f15si6492856ejd.359.2020.05.18.00.51.06; Mon, 18 May 2020 00:51:29 -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 S1727900AbgERHqq (ORCPT + 99 others); Mon, 18 May 2020 03:46:46 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51452 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726489AbgERHqq (ORCPT ); Mon, 18 May 2020 03:46:46 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 33CF4265351D7FE83BD5; Mon, 18 May 2020 15:46:39 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 18 May 2020 15:46:30 +0800 From: Ye Bin To: , CC: , , Subject: [PATCH] scsi: Fix incorrect usage of shost_for_each_device Date: Mon, 18 May 2020 15:44:20 +0800 Message-ID: <20200518074420.39275-1-yebin10@huawei.com> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.21.3