Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2686878pxj; Mon, 31 May 2021 08:15:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLYMUSo7zy09kvH4lrahSY3dzL/DOsLp2xBiBEmf54XWGACvq8SGvhgVZ6YdLT+NmZPH2l X-Received: by 2002:a17:906:4e08:: with SMTP id z8mr19514769eju.538.1622474129347; Mon, 31 May 2021 08:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622474129; cv=none; d=google.com; s=arc-20160816; b=LSzfH94IAB2ZzQ0SI12L4r75/28BYI/dseCvFXbv7uIRaISlEmjU8Av8A4ERs4Mm63 HF7H+pO77+fR719L63fxHxQPBYURQcozhWzOg3gVToNq9VTofsbCkL1bcxndBr3OYbNZ WpB8YUlUlFKxXVMTXxXeY6kmbZpHyjhaCtDDJey4K0vRkzWSp5Ltwg14EoWXiNhSiIDr ybaCIl/EEwqA057xj7gdQX8EDrh7yczO+EYgBThHhMf0FEDRZr2HeEHphlz3pamAlVji n8YTu6LYGr2kJR8FBG3zueh1nDHG0MqEk3dRn5ywozUFjdS48MQO1FXJN5Br9fwQXlDi t+nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LYHQsOtBz9YCYRhl02atQRO838YeA5C+HLrqiN683SA=; b=WFVrXK7oNEN+i4vBJWOKjueMyE72hAhs9G7IwW17hH7RZe2GE9Tms234/C/xU4MlO/ nKYmDELM6CNfQQdxi+Uik7XrPg6CgTTOte/g5GcDRbTSRkgcCPFjT2uy6H9J2mi/z6kc KCwmjKHM0o9PUh3rg6F2Qul3Utg7E8RM9pIet9A2N7CoOoLGMnB/vmuX4flUmSShbibl XyW3h7M6VYT2egxzEXA8FwL/21Td5r1iAFBQliXBVL/BCPL3yAF/aqAbS68L5n0oI+U9 Q/cYNALTX/22zLM0xRdIEAJXEkTGprYFfDpaok1IGzkp25SXHW0K9NnRz1UR1Ip1vIGl yzgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cG6z8VNT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si15894928edz.248.2021.05.31.08.15.06; Mon, 31 May 2021 08:15: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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cG6z8VNT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232920AbhEaPOJ (ORCPT + 99 others); Mon, 31 May 2021 11:14:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:40230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233345AbhEaOLg (ORCPT ); Mon, 31 May 2021 10:11:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 03D806140B; Mon, 31 May 2021 13:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468473; bh=RkNj7Sxouky+EMx7MnkcMWjpYcOVlf2hJ4xc/nFXHn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cG6z8VNTOv5Mr+sRvGUii8gonD7r8YtjSh4kRhT5gN2Hb235E0F3gLZlq4o+CtpI+ n2+x8fqbp9MlV3hhWmDdYgoV64i0rZ09zrxKUHe8tPc/vcErNM0DMm14RpzfkV4Ck5 nbcEihOmkNKoQyF1HZcx4w4n6TqwJbnuqXqDsa1o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Dan Carpenter , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.10 232/252] scsi: libsas: Use _safe() loop in sas_resume_port() Date: Mon, 31 May 2021 15:14:57 +0200 Message-Id: <20210531130705.884177492@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 8c7e7b8486cda21269d393245883c5e4737d5ee7 ] If sas_notify_lldd_dev_found() fails then this code calls: sas_unregister_dev(port, dev); which removes "dev", our list iterator, from the list. This could lead to an endless loop. We need to use list_for_each_entry_safe(). Link: https://lore.kernel.org/r/YKUeq6gwfGcvvhty@mwanda Fixes: 303694eeee5e ("[SCSI] libsas: suspend / resume support") Reviewed-by: John Garry Signed-off-by: Dan Carpenter Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/libsas/sas_port.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/libsas/sas_port.c b/drivers/scsi/libsas/sas_port.c index 19cf418928fa..e3d03d744713 100644 --- a/drivers/scsi/libsas/sas_port.c +++ b/drivers/scsi/libsas/sas_port.c @@ -25,7 +25,7 @@ static bool phy_is_wideport_member(struct asd_sas_port *port, struct asd_sas_phy static void sas_resume_port(struct asd_sas_phy *phy) { - struct domain_device *dev; + struct domain_device *dev, *n; struct asd_sas_port *port = phy->port; struct sas_ha_struct *sas_ha = phy->ha; struct sas_internal *si = to_sas_internal(sas_ha->core.shost->transportt); @@ -44,7 +44,7 @@ static void sas_resume_port(struct asd_sas_phy *phy) * 1/ presume every device came back * 2/ force the next revalidation to check all expander phys */ - list_for_each_entry(dev, &port->dev_list, dev_list_node) { + list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) { int i, rc; rc = sas_notify_lldd_dev_found(dev); -- 2.30.2