Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2752420pxj; Mon, 31 May 2021 09:51:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7IVJKF0N6yyZHiM0coXkcBcP+JE8YAqtPHgvtD8jV/8aRzwhuVTiAsqcXTLy06GkbqxZO X-Received: by 2002:a02:9208:: with SMTP id x8mr21356576jag.18.1622479896286; Mon, 31 May 2021 09:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479896; cv=none; d=google.com; s=arc-20160816; b=xhQN4uTsZ9eyCZqVGOk4JZpvc1SoBqRA1IydUsbnVHI+7NYxdM2DLBiQYpBO6Bz32T oA8B285ETo2BXqNig2oFhFbXxpI3m+VOXl9sR4BrR8VZ7agt7LieGm/2wfxl34CnI3Ij PCdfAjlblAUSBoNz3+IflI1yh9GXaF2qvgm+s+Cl3O3AUaiGsxq2z4qgNALN2IrQZkhg xNZ1sxnM8137IF+usHm0/Khoqby2f5oMNVVIDN8sMTemygRbbrmKtKJLlqE+Zte5F26u QF4eBQ81LMwgoOnOgiITYE7L3YYsKU1d3XGR9H8BGuHVr3wKxVRlhbJ+ySSq1ynEkj5S B86A== 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=CA0oskCAiVIZFZ9Wqgb65WSeFHkRQESLprQvbUFkfrO7b5GFcYLt7B2BZQU13Dhj4c nQmLVXF+OnC3IiSfYGcvnmCqyowSuGW2dyC04uGL2yVr2islryxp2m/A2coeXCoeks5p Qo1gto4hwdGhlRyQ4cPK0z0NIm5FlWVh0vjN53VWqbzYcp3rI9TabcNdhuLvKjviubBg sJewTUW4EN+FBmM3k867XVNZHkshEoP7J6lL169rTrR9oVHPyqS6Ki0yQaMv1TFtSRuv OkEbIxGUK/tD7ctq5H7J8uyNa6cPvtzf9JfCVnCUJGLAdcqJSqFAVL/tlDgUXi19fxdr 06TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=i82HYEc8; 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 z22si14924093jal.117.2021.05.31.09.51.23; Mon, 31 May 2021 09:51:36 -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=i82HYEc8; 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 S232080AbhEaQvN (ORCPT + 99 others); Mon, 31 May 2021 12:51:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:51180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231376AbhEaO5b (ORCPT ); Mon, 31 May 2021 10:57:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F67261CC4; Mon, 31 May 2021 14:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469636; bh=RkNj7Sxouky+EMx7MnkcMWjpYcOVlf2hJ4xc/nFXHn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i82HYEc8P1dvdxT5JdzIttPxnb8Gei9Q5qtrMvrNBIzgBW/mzDpdgtrJe7350HIbw Wd9UTwbrjMijv3sUjLvC9Ongi9ZDhTJc518k0KrgnHEeUY5tIsRUwcrLXJuOesa2Xr YQZQwl/RxDsrvouRxbN7X9WbJOLLzQpMDyrlQ4j8= 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.12 273/296] scsi: libsas: Use _safe() loop in sas_resume_port() Date: Mon, 31 May 2021 15:15:28 +0200 Message-Id: <20210531130712.922373099@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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