Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: libsas: use _safe() loop in sas_resume_port()
       [not found] <20210518082855.GB32682@kadam>
@ 2021-05-19 14:20 ` Dan Carpenter
  2021-05-19 14:48   ` John Garry
  2021-05-22  4:40   ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-05-19 14:20 UTC (permalink / raw)
  To: James E.J. Bottomley, Dan Williams
  Cc: Martin K. Petersen, Alan Stern, Jacek Danecki, James Bottomley,
	linux-scsi, linux-kernel, kernel-janitors

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().

Fixes: 303694eeee5e ("[SCSI] libsas: suspend / resume support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: libsas: use _safe() loop in sas_resume_port()
  2021-05-19 14:20 ` [PATCH] scsi: libsas: use _safe() loop in sas_resume_port() Dan Carpenter
@ 2021-05-19 14:48   ` John Garry
  2021-05-22  4:40   ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: John Garry @ 2021-05-19 14:48 UTC (permalink / raw)
  To: Dan Carpenter, James E.J. Bottomley, Dan Williams
  Cc: Martin K. Petersen, Alan Stern, Jacek Danecki, James Bottomley,
	linux-scsi, linux-kernel, kernel-janitors

On 19/05/2021 15:20, Dan Carpenter wrote:
> 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().
> 
> Fixes: 303694eeee5e ("[SCSI] libsas: suspend / resume support")
> Signed-off-by: Dan Carpenter<dan.carpenter@oracle.com>

Reviewed-by: John Garry <john.garry@huawei.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: libsas: use _safe() loop in sas_resume_port()
  2021-05-19 14:20 ` [PATCH] scsi: libsas: use _safe() loop in sas_resume_port() Dan Carpenter
  2021-05-19 14:48   ` John Garry
@ 2021-05-22  4:40   ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2021-05-22  4:40 UTC (permalink / raw)
  To: Dan Carpenter, James E.J. Bottomley, Dan Williams
  Cc: Martin K . Petersen, Alan Stern, linux-scsi, kernel-janitors,
	linux-kernel, James Bottomley, Jacek Danecki

On Wed, 19 May 2021 17:20:27 +0300, Dan Carpenter wrote:

> 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().

Applied to 5.13/scsi-fixes, thanks!

[1/1] scsi: libsas: use _safe() loop in sas_resume_port()
      https://git.kernel.org/mkp/scsi/c/8c7e7b8486cd

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-22  4:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210518082855.GB32682@kadam>
2021-05-19 14:20 ` [PATCH] scsi: libsas: use _safe() loop in sas_resume_port() Dan Carpenter
2021-05-19 14:48   ` John Garry
2021-05-22  4:40   ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox