From: Eshaan Deshmukh <eshaan2031@icloud.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
"James E . J . Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: John Garry <john.g.garry@oracle.com>,
Jason Yan <yanaijie@huawei.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Eshaan Deshmukh <eshaan2031@icloud.com>
Subject: [PATCH v3 1/3] scsi: libsas: Handle errors in sas_ex_add_parent_port()
Date: Wed, 12 Aug 2026 14:48:06 -0500 [thread overview]
Message-ID: <20260812194808.576586-2-eshaan2031@icloud.com> (raw)
In-Reply-To: <20260812194808.576586-1-eshaan2031@icloud.com>
The function sas_ex_add_parent_port() uses BUG_ON() if sas_port_alloc()
or sas_port_add() fails. Change sas_ex_add_parent_port() to return error
codes to the caller and free the sas_port_alloc() allocation. Also
change sas_ex_discover_dev() to handle errors returned by
sas_ex_add_parent_port().
Signed-off-by: Eshaan Deshmukh <eshaan2031@icloud.com>
---
drivers/scsi/libsas/sas_expander.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index f471ab464..f1a1417b0 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -33,19 +33,29 @@ static void sas_port_add_ex_phy(struct sas_port *port, struct ex_phy *ex_phy)
ex_phy->phy_state = PHY_DEVICE_DISCOVERED;
}
-static void sas_ex_add_parent_port(struct domain_device *dev, int phy_id)
+static int sas_ex_add_parent_port(struct domain_device *dev, int phy_id)
{
struct expander_device *ex = &dev->ex_dev;
struct ex_phy *ex_phy = &ex->ex_phy[phy_id];
+ int error;
if (!ex->parent_port) {
ex->parent_port = sas_port_alloc(&dev->rphy->dev, phy_id);
- /* FIXME: error handling */
- BUG_ON(!ex->parent_port);
- BUG_ON(sas_port_add(ex->parent_port));
+ if (!ex->parent_port)
+ return -ENOMEM;
+
+ error = sas_port_add(ex->parent_port);
+ if (error) {
+ sas_port_free(ex->parent_port);
+ ex->parent_port = NULL;
+ return error;
+ }
+
sas_port_mark_backlink(ex->parent_port);
}
sas_port_add_ex_phy(ex->parent_port, ex_phy);
+
+ return 0;
}
/* ---------- SMP task management ---------- */
@@ -981,12 +991,14 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
}
/* Parent and domain coherency */
- if (!dev->parent && sas_phy_match_port_addr(dev->port, ex_phy)) {
- sas_ex_add_parent_port(dev, phy_id);
- return 0;
- }
+ if (!dev->parent && sas_phy_match_port_addr(dev->port, ex_phy))
+ return sas_ex_add_parent_port(dev, phy_id);
+
if (dev->parent && sas_phy_match_dev_addr(dev->parent, ex_phy)) {
- sas_ex_add_parent_port(dev, phy_id);
+ res = sas_ex_add_parent_port(dev, phy_id);
+ if (res)
+ return res;
+
if (ex_phy->routing_attr == TABLE_ROUTING)
sas_configure_phy(dev, phy_id, dev->port->sas_addr, 1);
return 0;
--
2.55.0
next prev parent reply other threads:[~2026-08-12 19:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 19:48 [PATCH v3 0/3] scsi: libsas: Handle errors in 3 functions Eshaan Deshmukh
2026-08-12 19:48 ` Eshaan Deshmukh [this message]
2026-08-12 19:48 ` [PATCH v3 2/3] scsi: libsas: Handle errors in sas_set_ex_phy() Eshaan Deshmukh
2026-08-12 19:48 ` [PATCH v3 3/3] scsi: libsas: Handle errors in sas_ex_discover_expander() Eshaan Deshmukh
2026-08-14 16:45 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260812194808.576586-2-eshaan2031@icloud.com \
--to=eshaan2031@icloud.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=john.g.garry@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=yanaijie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®