Skip to contentSkip to conversation

scsi: libsas: Fix error path in sas_notify_lldd_dev_found()

PATCH Applied Dan Carpenter 4 participants 4 messages Sep 5, 2020 – Sep 9, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: libsas: Fix error path in sas_notify_lldd_dev_found()

In sas_notify_lldd_dev_found(), if we can't find a device, then it seems like the wrong thing to mark the device as found and to increment the reference count. None of the callers ever drop the reference in that situation.

Fixes 735f7d2fedf5 ("[SCSI] libsas: fix domain_device leak")
---
 drivers/scsi/libsas/sas_discover.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/libsas/sas_discover.c +2 -1
index cd7c7d269f6f..d0f9e90e3279 100644
@@ -182,10 +182,11 @@ int sas_notify_lldd_dev_found(struct domain_device *dev)
 		pr_warn("driver on host %s cannot handle device %016llx, error:%d\n",
 			dev_name(sas_ha->dev),
 			SAS_ADDR(dev->sas_addr), res);
+		return res;
 	}
 	set_bit(SAS_DEV_FOUND, &dev->state);
 	kref_get(&dev->kref);
-	return res;
+	return 0;
 }
 
 
Signature · 1 line
2.28.0
reviewer Reviewed-by on v1 1/1
#1 lore raw

ÔÚ 2020/9/5 20:58, Dan Carpenter дµÀ:

Quoted 19 lines

In sas_notify_lldd_dev_found(), if we can't find a device, then it seems like the wrong thing to mark the device as found and to increment the reference count. None of the callers ever drop the reference in that situation.

Fixes 735f7d2fedf5 ("[SCSI] libsas: fix domain_device leak")
---
  drivers/scsi/libsas/sas_discover.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/libsas/sas_discover.c +0 -0
index cd7c7d269f6f..d0f9e90e3279 100644
@@ -182,10 +182,11 @@ int sas_notify_lldd_dev_found(struct domain_device *dev)
  		pr_warn("driver on host %s cannot handle device %016llx, error:%d\n",
  			dev_name(sas_ha->dev),

drivers/scsi/libsas/sas_discover.c int sas_notify_lldd_dev_found(struct domain_device *dev) · line 192

Quoted 10 lines
drivers/scsi/libsas/sas_discover.c +2 -1
  			SAS_ADDR(dev->sas_addr), res);
+		return res;
  	}
  	set_bit(SAS_DEV_FOUND, &dev->state);
  	kref_get(&dev->kref);
-	return res;
+	return 0;
  }
 
 

Hi Dan, thanks for finding this,

#2 lore raw
In reply to Dan Carpenter
Quoted 1 line · Dan Carpenter

In sas_notify_lldd_dev_found(), if we can't find a device,

nit: the callback is for the LLDD is to allocate resources, device context etc., for that domain_device, and not find the device. The device has been found at this point.

Quoted 16 lines

then it seems
like the wrong thing to mark the device as found and to increment the reference count. None of the callers ever drop the reference in that situation.

Fixes 735f7d2fedf5 ("[SCSI] libsas: fix domain_device leak")
---
  drivers/scsi/libsas/sas_discover.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/libsas/sas_discover.c +0 -0
index cd7c7d269f6f..d0f9e90e3279 100644

drivers/scsi/libsas/sas_discover.c int sas_notify_lldd_dev_found(struct domain_device *dev) · line 189

Quoted 9 lines
drivers/scsi/libsas/sas_discover.c +2 -1
@@ -182,10 +182,11 @@ int sas_notify_lldd_dev_found(struct domain_device *dev)
  		pr_warn("driver on host %s cannot handle device %016llx, error:%d\n",
  			dev_name(sas_ha->dev),
  			SAS_ADDR(dev->sas_addr), res);
+		return res;
  	}
  	set_bit(SAS_DEV_FOUND, &dev->state);
  	kref_get(&dev->kref);
-	return res;
+	return 0;

This looks ok.

drivers/scsi/libsas/sas_discover.c int sas_notify_lldd_dev_found(struct domain_device *dev) · line 190

Quoted 1 line
drivers/scsi/libsas/sas_discover.c +0 -0
  }

Thanks,
John

Quoted 3 lines
#3 lore raw
In reply to Dan Carpenter
Quoted 4 lines · Dan Carpenter

In sas_notify_lldd_dev_found(), if we can't find a device, then it seems like the wrong thing to mark the device as found and to increment the reference count. None of the callers ever drop the reference in that situation.

Applied to 5.9/scsi-fixes, thanks!

[1/1] scsi: libsas: Fix error path in sas_notify_lldd_dev_found()

      https://git.kernel.org/mkp/scsi/c/fdcb7900d9ab
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering