Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Haoxiang Li" <haoxiang_li2024@163.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: libsas: Handle expander discovery allocation failures
Date: Tue, 23 Jun 2026 11:48:55 +0000	[thread overview]
Message-ID: <20260623114856.B9EA41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623112909.2172701-1-haoxiang_li2024@163.com>

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

Pre-existing issues:
- [High] The return value of `sas_rphy_add()` is ignored in `sas_ex_discover_expander()`, leading to incomplete sysfs registration and kernel warnings during device teardown on error.
--

commit 89b8642b2949851837e884780fd3067fcff48014
Author: Haoxiang Li <haoxiang_li2024@163.com>

scsi: libsas: Handle expander discovery allocation failures

This commit adds error handling for sas_port_alloc(), sas_port_add(), and
sas_expander_alloc() in sas_ex_discover_expander(). It unwinds the
allocated resources to prevent dereferencing uninitialized or NULL pointers.

> diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
> index f471ab464a78b..56c04c4ae8181 100644
> --- a/drivers/scsi/libsas/sas_expander.c
> +++ b/drivers/scsi/libsas/sas_expander.c

[ ... ]

> @@ -926,6 +928,9 @@ static struct domain_device *sas_ex_discover_expander(
>  		rphy = NULL;	/* shut gcc up */
>  		BUG();
>  	}
> +	if (!rphy)
> +		goto out_delete_port;
> +

[Severity: High]
This isn't a bug introduced by this patch, but further down in
sas_ex_discover_expander(), the return value of sas_rphy_add() is ignored:

	sas_init_dev(child);
	sas_fill_in_rphy(child, rphy);
	sas_rphy_add(rphy);

If sas_rphy_add() fails (for example, if device_add() fails under memory
pressure), the remote phy is not registered with sysfs.

When the device is eventually removed, or if discovery fails later in this
function, sas_rphy_delete() is unconditionally called:

	res = sas_discover_expander(child);
	if (res) {
		sas_rphy_delete(rphy);

Because sas_rphy_delete() calls device_del(), doing this on a device that
failed device_add() violates the driver core API.

Can this trigger a kernel WARN_ON or oops during device teardown? Could we
check the return value of sas_rphy_add() and handle the registration failure
along with these other resource allocation failures?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260623112909.2172701-1-haoxiang_li2024@163.com?part=1

  reply	other threads:[~2026-06-23 11:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 11:29 [PATCH] scsi: libsas: Handle expander discovery allocation failures Haoxiang Li
2026-06-23 11:48 ` sashiko-bot [this message]
2026-06-26 22:11 ` Damien Le Moal

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=20260623114856.B9EA41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=haoxiang_li2024@163.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox