All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: mpt3sas: Fix sas_device reference leak in mpt3sas_transport_port_add()
Date: Thu, 17 Sep 2026 15:27:09 +0000	[thread overview]
Message-ID: <20260917152709.821021F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260917151720.2158664-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] mpt3sas: build failure due to undeclared sas_device_put()
- [Low] mpt3sas: dead code in out_fail path as sas_device is always NULL
--

commit 488cd1fc5aeb3fa9ed5496cf3747de1d6edef41f
Author: Wentao Liang <vulab@iscas.ac.cn>

scsi: mpt3sas: Fix sas_device reference leak in mpt3sas_transport_port_add()

This patch attempts to fix a reference leak in the error path of
mpt3sas_transport_port_add() by dropping the reference to sas_device. It
adds a check and a call to sas_device_put() in the out_fail label.

Cc: stable@vger.kernel.org

> diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
> --- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
> @@ -777,6 +777,8 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
>  	list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_list,
>  	    port_siblings)
>  		list_del(&mpt3sas_phy->port_siblings);
> +	if (sas_device)
> +		sas_device_put(sas_device);

[Severity: Low]
Does this compile against the current mpt3sas driver? It appears
sas_device_put() is not declared for mpt3sas in this kernel baseline, and
the mpt3sas version of struct _sas_device lacks a reference count. Is this
perhaps a flawed backport or ported from a different driver version?

[Severity: Low]
Can this cleanup branch ever execute? Looking at
mpt3sas_transport_port_add(), when the code jumps to out_fail before
sas_device is assigned, it is NULL.

The only assignment to sas_device is immediately followed by a check that
jumps to out_fail only if sas_device is already NULL:

	sas_device = mpt3sas_scsih_sas_device_find_by_sas_address(ioc,
			    mpt3sas_port->remote_identify.sas_address);
	if (!sas_device) {
		dfailprintk(ioc, printk(MPT3SAS_FMT
			"failure at %s:%d/%s()!\n",
			ioc->name, __FILE__, __LINE__, __func__));
		goto out_fail;
	}

Subsequent code, including the sas_rphy_add() call, does not jump to
out_fail on error. This makes the if (sas_device) check mathematically
guaranteed to be false whenever out_fail is executed.

>  	kfree(mpt3sas_port);
>  	return NULL;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260917151720.2158664-1-vulab@iscas.ac.cn?part=1

      reply	other threads:[~2026-09-17 15:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 15:17 [PATCH] scsi: mpt3sas: Fix sas_device reference leak in mpt3sas_transport_port_add() Wentao Liang
2026-09-17 15:27 ` sashiko-bot [this message]

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=20260917152709.821021F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vulab@iscas.ac.cn \
    /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.