Skip to contentSkip to conversation

scsi: libsas: fix error handing in sas_ex_discover_expander()

PATCH In review Yang Yingliang 2 participants 3 messages Nov 4, 2022 – Nov 7, 2022

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

PATCH 1/1 scsi: libsas: fix error handing in sas_ex_discover_expander()

Check return value of sas_port_alloc() and sas_port_add() and handle the error. If they fail, free the device and port, then returns NULL instead of using BUG_ON().

Fixes 2908d778ab3e ("[SCSI] aic94xx: new driver")
---
 drivers/scsi/libsas/sas_expander.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_expander.c +11 -2
index 5ce251830104..88b8b955d533 100644
@@ -935,8 +935,17 @@ static struct domain_device *sas_ex_discover_expander(
 		return NULL;
 
 	phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
-	/* FIXME: better error handling */
-	BUG_ON(sas_port_add(phy->port) != 0);
+	if (!phy->port) {
+		sas_put_device(child);
+		return NULL;
+	}
+
+	if (sas_port_add(phy->port)) {
+		sas_port_free(phy->port);
+		phy->port = NULL;
+		sas_put_device(child);
+		return NULL;
+	}
 
 
 	switch (phy->attached_dev_type) {
Signature · 1 line
2.25.1
reviewer
#1 lore raw
Quoted 6 lines · Yang Yingliang

Check return value of sas_port_alloc() and sas_port_add() and handle the error. If they fail, free the device and port, then returns NULL instead of using BUG_ON().

Fixes 2908d778ab3e ("[SCSI] aic94xx: new driver")

I already sent a patch to handle all errors here:

https://lore.kernel.org/linux-scsi/[email protected]/

Do you actually have a cascaded expander setup to test this?

Quoted 27 lines
---
  drivers/scsi/libsas/sas_expander.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_expander.c +10 -2
index 5ce251830104..88b8b955d533 100644
@@ -935,8 +935,17 @@ static struct domain_device *sas_ex_discover_expander(
  		return NULL;
 
  	phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
-	/* FIXME: better error handling */
-	BUG_ON(sas_port_add(phy->port) != 0);
+	if (!phy->port) {
+		sas_put_device(child);
+		return NULL;
+	}
+
+	if (sas_port_add(phy->port)) {
+		sas_port_free(phy->port);
+		phy->port = NULL;
+		sas_put_device(child);
+		return NULL; > +	}
 
 
  	switch (phy->attached_dev_type) {
#2 lore raw
Quoted 5 lines · John Garry
Quoted 4 lines · Yang Yingliang

Check return value of sas_port_alloc() and sas_port_add() and handle the error. If they fail, free the device and port, then returns NULL instead of using BUG_ON().

Quoted 7 lines
Quoted 2 lines
Fixes 2908d778ab3e ("[SCSI] aic94xx: new driver")

I already sent a patch to handle all errors here:

https://lore.kernel.org/linux-scsi/[email protected]/

Your patch is better to handle all of these, this patch can be dropped.

Thanks,
Yang

Quoted 30 lines

Do you actually have a cascaded expander setup to test this?

Quoted 15 lines

---
  drivers/scsi/libsas/sas_expander.c | 13 +++++++++++--

  1 file changed, 11 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_expander.c +1 -2
index 5ce251830104..88b8b955d533 100644
@@ -935,8 +935,17 @@ static struct domain_device 
 *sas_ex_discover_expander(
           return NULL;
         phy->port = sas_port_alloc(&parent->rphy->dev, phy_id);
-    /* FIXME: better error handling */
-    BUG_ON(sas_port_add(phy->port) != 0);
+    if (!phy->port) {

drivers/scsi/libsas/sas_expander.c static struct domain_device · line 948

Quoted 10 lines
drivers/scsi/libsas/sas_expander.c +9 -0
+        sas_put_device(child);
+        return NULL;
+    }
+
+    if (sas_port_add(phy->port)) {
+        sas_port_free(phy->port);
+        phy->port = NULL;
+        sas_put_device(child);
+        return NULL; > +    }
           switch (phy->attached_dev_type) {

.