All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eshaan Deshmukh" <eshaan2031@icloud.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 2/3] scsi: libsas: Handle errors in sas_set_ex_phy()
Date: Wed, 12 Aug 2026 20:05:40 +0000	[thread overview]
Message-ID: <20260812200541.72F5F1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260812194808.576586-3-eshaan2031@icloud.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Returning -EBUSY when SAS_HA_ATA_EH_ACTIVE is set aborts the entire expander discovery.

Pre-existing issues:
- [High] Setting phy->phy = NULL on sas_phy_add failure without cleaning up phy_state leads to a NULL pointer dereference in sas_ex_get_linkrate.
--

--- Patch [2]: [PATCH v3 2/3] scsi: libsas: Handle errors in sas_set_ex_phy() ---
commit bb6067e9bf28e3d0ad6e9081b09eb33b9747146c
Author: Eshaan Deshmukh <eshaan2031@icloud.com>

scsi: libsas: Handle errors in sas_set_ex_phy()

The function sas_set_ex_phy() uses BUG_ON() if sas_phy_alloc() fails.
Change it to return -ENOMEM error code if that happens. Change all the
other returns in sas_set_ex_phy() to return 0 to preserve current
functionality, or to return an error. Change all uses of sas_set_ex_phy
to handle the returned error codes.

> diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
> index f1a1417b09819..ab6afbad37feb 100644
> --- a/drivers/scsi/libsas/sas_expander.c
> +++ b/drivers/scsi/libsas/sas_expander.c
[ ... ]
> @@ -220,14 +220,15 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
>  	struct sas_rphy *rphy = dev->rphy;
>  	bool new_phy = !phy->phy;
>  	char *type;
> +	int error;
>  
>  	if (new_phy) {
>  		if (WARN_ON_ONCE(test_bit(SAS_HA_ATA_EH_ACTIVE, &ha->state)))
> -			return;
> +			return -EBUSY;

[Severity: High]
Will returning -EBUSY here abort the entire expander discovery?

Previously, this returned void, allowing the discovery loop to continue.
If a transient ATA error coincides with an expander hotplug event, this
-EBUSY error propagates up through sas_ex_phy_discover_helper() to
sas_discover_domain(), where it causes the newly discovered expander device
to be destroyed via sas_rphy_free().

Since sas_discover_domain() does not defer on ATA EH, could a transient
ATA error permanently fail the discovery of a SAS expander?

>  		phy->phy = sas_phy_alloc(&rphy->dev, phy_id);
>  
> -		/* FIXME: error_handling */
> -		BUG_ON(!phy->phy);
> +		if (!phy->phy)
> +			return -ENOMEM;
>  	}
>  
[ ... ]
> @@ -296,11 +297,14 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
>  	phy->phy->enabled = (phy->linkrate != SAS_PHY_DISABLED);
>  
>   skip:
> -	if (new_phy)
> -		if (sas_phy_add(phy->phy)) {
> +	if (new_phy) {
> +		error = sas_phy_add(phy->phy);
> +		if (error) {
>  			sas_phy_free(phy->phy);
> -			return;
> +			phy->phy = NULL;
> +			return error;
>  		}
> +	}

[Severity: High]
This is a pre-existing issue, but does setting phy->phy to NULL here on
sas_phy_add() failure lead to a NULL pointer dereference later?

If device registration fails, phy->phy is freed and set to NULL, but
phy->phy_state remains PHY_EMPTY and attached_sas_addr is still populated.

If this error is ignored during revalidation, later operations like
sas_ex_get_linkrate() might iterate over the phys, match the address, and
pass the NULL phy->phy to sas_port_add_phy():

sas_ex_get_linkrate()
   if (sas_phy_match_dev_addr(child, phy)) {
      ...
      sas_port_add_phy(port, phy->phy);

sas_port_add_phy() will then unconditionally dereference the NULL phy pointer
when checking the port_siblings list.

Should the ex_phy array be scrubbed (e.g., reverting phy_state to
PHY_VACANT) when registration fails to prevent this?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812194808.576586-1-eshaan2031@icloud.com?part=2

  reply	other threads:[~2026-08-12 20:05 UTC|newest]

Thread overview: 7+ 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 ` [PATCH v3 1/3] scsi: libsas: Handle errors in sas_ex_add_parent_port() Eshaan Deshmukh
2026-08-12 20:00   ` sashiko-bot
2026-08-12 19:48 ` [PATCH v3 2/3] scsi: libsas: Handle errors in sas_set_ex_phy() Eshaan Deshmukh
2026-08-12 20:05   ` sashiko-bot [this message]
2026-08-12 19:48 ` [PATCH v3 3/3] scsi: libsas: Handle errors in sas_ex_discover_expander() Eshaan Deshmukh
2026-08-12 20:01   ` sashiko-bot

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=20260812200541.72F5F1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eshaan2031@icloud.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.