From: Wentao Liang <vulab@iscas.ac.cn>
To: Justin Tee <justin.tee@broadcom.com>, Paul Ely <paul.ely@broadcom.com>
Cc: James Bottomley <James.Bottomley@hansenpartnership.com>,
James Smart <james.smart@broadcom.com>,
"Martin K . Petersen" <mkp@kernel.org>,
Nigel Kirkland <nigel.kirkland@broadcom.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH v2 1/3] scsi: lpfc: Fix ndlp reference leak in lpfc_release_rpi()
Date: Sat, 7 Nov 2026 16:16:53 +0000 [thread overview]
Message-ID: <20261107161655.2628796-1-vulab@iscas.ac.cn> (raw)
In-Reply-To: <CAEQnVQn7fpgpm5zY=8ne0G5M_KXWg4qjecMK6smk-q+_0j1PEw@mail.gmail.com>
lpfc_release_rpi() only drops the node reference and frees the mailbox
memory it took when lpfc_sli_issue_mbox() returns MBX_NOT_FINISHED. The
SLI-4 issue path can also return -EIO for a command it refuses to
submit, in which case the completion handler never runs and both the
reference and the mailbox are leaked.
Clean up whenever the command was not handed to the port.
The candidate came from a static analysis tool we run over the tree.
DeepSeek and GPT-6.1 Sol were used to audit the finding and to help
write the fix; I reviewed the result line by line and I am responsible
for it.
Fixes: 4430f7fd09ec ("scsi: lpfc: Rework locations of ndlp reference taking")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
Changes in v2:
- Rebased on v7.4-rc1.
- Reworded the comment above the check so that it does not depend on the
SLI-4 return value. The check itself is unchanged.
- Sorry for the month it took me to answer the review.
drivers/scsi/lpfc/lpfc_nportdisc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index fb8844c69491..fbe3c97723b2 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -1155,7 +1155,11 @@ lpfc_release_rpi(struct lpfc_hba *phba, struct lpfc_vport *vport,
ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag);
rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
- if (rc == MBX_NOT_FINISHED) {
+ /* The completion handler frees the mailbox and drops the node
+ * reference, and it only runs when the command was queued or
+ * already completed.
+ */
+ if (rc != MBX_SUCCESS && rc != MBX_BUSY) {
lpfc_nlp_put(ndlp);
mempool_free(pmb, phba->mbox_mem_pool);
}
next prev parent reply other threads:[~2026-11-07 16:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 14:47 [PATCH] " Wentao Liang
2026-09-17 19:35 ` Paul Ely
2026-10-06 21:21 ` Paul Ely
2026-11-07 15:17 ` Wentao Liang
2026-11-07 16:16 ` Wentao Liang [this message]
2026-11-07 16:16 ` [PATCH v2 2/3] scsi: lpfc: Report bsg mailbox failures as an errno Wentao Liang
2026-11-07 16:16 ` [PATCH v2 3/3] scsi: lpfc: Return MBX status when a non-polled mbox cannot be issued Wentao Liang
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=20261107161655.2628796-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=James.Bottomley@hansenpartnership.com \
--cc=james.smart@broadcom.com \
--cc=justin.tee@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=nigel.kirkland@broadcom.com \
--cc=paul.ely@broadcom.com \
--cc=stable@vger.kernel.org \
/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®