Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2713739pxj; Mon, 31 May 2021 08:55:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMkXxzetDkMhfRdaAufYlPLXs+aOWj+v9furdFYcGJaIzJYXOHXoUJKlXCtEyyrLw/RhYD X-Received: by 2002:a05:6e02:d0c:: with SMTP id g12mr13295878ilj.32.1622476500879; Mon, 31 May 2021 08:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622476500; cv=none; d=google.com; s=arc-20160816; b=Hx88i+le9VAZer5yB+VCIMkp7KnW+N2Oh2PNT2rRQwHRxj6fTxSgT0bSi6yg0YOFBm AV3EwKNFE1HtFBSvUGDYzfmbBOomaHK1hxtkofDIdO3jMEeIuYMp9dqz8gjTB7p5x6ng lF9+7Sh8PE9mRODgmDjHr+zibRIJTmsg0n9a1dSMB14muD4Pu1+6XP5TQs0QH/FYScoT 37399DFoDLt6A1CfZlnPY+8QbzKfsIAk2UqPVc3T3bbQ5rmzkmGbo2Ge1C9uHgUtna9Q xCzfbBy/fRD8ppnxaFS3eOoV/s1L0wLdE+bBTWzuSkM7J24jK1s4jpmUVg+i63BBPyKm rtpw== 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=548h6vWvWS2suUW2o8tzgcNHzb7rhBQYvQiXOiZX7Ss=; b=h9WMVUzZ2biuojtLgpO61hpX8aw6WIdK2ivuTGXcI1pFNXtZefNoNzuzMVJuG93MrS d4ffgv8q/OHvv+i45fcI4swBxJNd8bQveivMqxyvGpGn4/Kq/Z5KDxWt3xiEcfbBLCwq fFhXX2EQiDOMz1lROz5KRJnLaulVAg61wKnx3R8LPUXQYa1ObVJXWV94at4b5N9A5YwD YE2Xkopgl4Dt/yyi31dq5BsctiLLjzWiOpzQ445j6AQaBQQ2Ny2vaFq1sJvrb2YpbQko nuTOs/lzvWn8I8Mo6p27jLRqKBFD7OQVQ79vCY5SOGgyWWLCGrtm2Y+7RB9lgZgPvM9J Bzew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IppzKfFz; 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 t19si13005340iog.66.2021.05.31.08.54.47; Mon, 31 May 2021 08:55:00 -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=IppzKfFz; 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 S234623AbhEaPz3 (ORCPT + 99 others); Mon, 31 May 2021 11:55:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:56304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233999AbhEaO3h (ORCPT ); Mon, 31 May 2021 10:29:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 440CD61C27; Mon, 31 May 2021 13:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468919; bh=uJvxStNRGL8ZMqTvhb7qpbB1W1mC9gnlKx7vYR510TA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IppzKfFzcl8f5ApIbcFPMyZMtDfjSM2QjvwQ5hYcb2U051FRED9zaafutDYEntMYM Euuqk7BPN3+5byrIxA0F64OdGOjcGENiCgUuHndRJNqZ0TMLJTmhxWkDwmZS/q4qnX v10pzC7Ipwbl86TdlHkbyTfRVVyGj0y5QMKfX63k= 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.4 162/177] scsi: libsas: Use _safe() loop in sas_resume_port() Date: Mon, 31 May 2021 15:15:19 +0200 Message-Id: <20210531130653.527014111@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 7c86fd248129..f751a12f92ea 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