Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2628192pxj; Mon, 31 May 2021 06:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ2QS4L8CqsXbgql+CLLzXhRJZOEjH0rKgmvM8doncvLY5NacS+vGvNFEYnb8QuYYY6JGw X-Received: by 2002:a05:6602:158a:: with SMTP id e10mr17041477iow.137.1622469377262; Mon, 31 May 2021 06:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622469377; cv=none; d=google.com; s=arc-20160816; b=JLkYrwX6oB2tmQp9WUevn8XHqIThUDIa/fQDpxaqJ/aVdm7kwBQ1bFk9CkjV8Z0TlO CeF+tUuZ2GqXuNUvU7tMdhiP6V4aQPoeUWS2hzvQYKMmWFnWTFQhiHGfBP68RT37/wEQ wv0ec82ZFeYc3SXrwTod/umtExuv2/ZTXpsE1zSB1n8jn2DHSeZ4Hag31p+I1kAxsY0z OthHQnJIUvqXz/ZSMwXyFwzLrYlKDVcrHZ3rdL6tbVsp7+jxwdxu3moWDUNrZQUZnIvR PAJK5VBIjUfUEe6xW4B5CKvyznOOVx582814foH2uNUJXmVcuDDo7DfALNArTDAe+GWN IelQ== 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=SpSr3qza7LtbIcgmRUVoihTKE2FBkto6YVmA53obeO8=; b=JYr+Bw17IZ9vlaocOHI2IX4DQpXrfFlRWOF579ExEHgxdP0YyqBkjTvGHbPD0Z5pz0 xY8r6EGwqjOZTLaqB/t55S3sIEY31UXAN6jz8jdHJ23DmhOftwmiQI4sCZMHmvPuNYgW Yc5SJ2psOZg78GDFVsMci9mGMbQJUaCYcw+aSZPm4QwiOWEXM+ul9kdAavmXfwoDbYbi 71j+9unwL9RlTiAJe2ZsfUEbluI9qlgHYxokROfGedzfOX5CStQtbnncaLqOionk9+IQ tL3kbb82V/MinWllRdlfIuDa0UGaDFYZNWpkFY7FQcio4drzmXgAoTAhLeHjiME2CB7U xDfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NLtOa76N; 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 x99si13489670jah.122.2021.05.31.06.56.03; Mon, 31 May 2021 06:56:17 -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=NLtOa76N; 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 S232690AbhEaN45 (ORCPT + 99 others); Mon, 31 May 2021 09:56:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:44098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231560AbhEaNh1 (ORCPT ); Mon, 31 May 2021 09:37:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2354D6145E; Mon, 31 May 2021 13:26:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467576; bh=PCg0zHwCKIdVTKf5I8vRIK0jC9BXhIWMSDVCnQXMyWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLtOa76N9fUFi0yRnljBBh9y9MAAI8yGlADTERo75zrffRoJKs43B6wQDC10ast9C n6sIC03cZt4B6T55zN7hx2AHDIt1+U6JaD/eGTrolwFvdtIGhwLoYIK16cIDzQpFxs USzQNAHo3HmFZ6mCkfjqU77fscFuRxUzlYfC0THg= 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 4.19 108/116] scsi: libsas: Use _safe() loop in sas_resume_port() Date: Mon, 31 May 2021 15:14:44 +0200 Message-Id: <20210531130643.781611211@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 fad23dd39114..1a0b2ce398f7 100644 --- a/drivers/scsi/libsas/sas_port.c +++ b/drivers/scsi/libsas/sas_port.c @@ -41,7 +41,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); @@ -60,7 +60,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