Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2641154pxj; Mon, 31 May 2021 07:12:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRcT4RKao/Nn22E8Q+jUbFBGg/3oiXQKPUXd0DiNKpu+NmTsMKfLxWeMqz2YHUr3CZy6HO X-Received: by 2002:a92:9411:: with SMTP id c17mr18705574ili.264.1622470321558; Mon, 31 May 2021 07:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622470321; cv=none; d=google.com; s=arc-20160816; b=XnZ8aJ68HGUmYmkA5m4HCEynZ9rbU0Vsbzd/Urst+Gb7tkjuCado7yWaO3dG3dlMEf FZlKMHOT50DMg9AzJEv4d1Od0NsgHckng0BOoDKrzhFTRBr9itZdMoAFD1kTIk+SMkCq Q0qDNJm8mhDrEi5JvDejGU6l5s0bwlUPeA806xm6y+L4V2SoZqG1os05p+4vExod88vH ROu8KT7fFwgv55B9TaRTacNBkGsYkV92ChlJy8EtX1zPIYazjR0xHC1E7XcqGGMaYRip 8wZAVYGTAcd+gTZ1GSRIxXpsNLoOKntwxiPU627JQcb6JO4mtLMZ4gd+ukEMWkDyKYWN 5wEQ== 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=9LzO35JfcuwnCmXmZSahBNPbVB7nnMvxAIiXJ95Oxfw=; b=ZrRj2MFGKFkukgJmHUWVDd5t8N+62A74EUF+H591UxJ/1v+nVCkIMXMCeZrlB8X5Yq wpHK5WDms5cRM5qqrixFcEh4wE6FwHgQQ1648F3xle5ttFE4k811mPodFjVlAN3XQVFr sd5yfsdpo6lDqLuP6q9J9Fd3XLuaQd6PUnb7qlK2q3t6lXNDz6DkdHX0JkiM1I3HUHE6 2xQg45F054xueluuZowHK65wc78AR9LzNKNsaRbp+nvcq/1lYy46qeJ0jL+qvg+3FmYh Lxx2w2WiWBJTKzlAWnRsYvwjQpi+TF/HYKFL8rGECNfO8M2ZchxCE0WvLLvinC9LbE1k 8fDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jipZPhLg; 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 a15si13426994ilq.109.2021.05.31.07.11.47; Mon, 31 May 2021 07:12:01 -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=jipZPhLg; 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 S231210AbhEaOLF (ORCPT + 99 others); Mon, 31 May 2021 10:11:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:49272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbhEaNom (ORCPT ); Mon, 31 May 2021 09:44:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1525D61417; Mon, 31 May 2021 13:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467768; bh=o1Vg1+Yrw0GnXAW2r/u+OLWNaxvLVS4WPTHwmj0OT+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jipZPhLgMBFL9ML4cex6eM56a+XQedSNLO6yYRfjSgYA7cFljAXQND4uSSCEz4h4+ fTjtrnUPA96mrWREdILoJtnvBLnLh/ptGH3aZ9O4cgPaxLKYmXR6FRH2n7aYgjhYpt RJYrtWwGlZ3cQd5sU+MQmPBSH4JPvuo7XjoA3Fow= 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.14 72/79] scsi: libsas: Use _safe() loop in sas_resume_port() Date: Mon, 31 May 2021 15:14:57 +0200 Message-Id: <20210531130638.298606074@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130636.002722319@linuxfoundation.org> References: <20210531130636.002722319@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 d3c5297c6c89..30e0730f613e 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