Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-fc: fix reference leak in nvme_fc_nvme_discovery_store()
@ 2026-10-23 14:00 Martin George
  2026-10-23 14:39 ` Laurence Oberman
  2026-10-23 22:06 ` Keith Busch
  0 siblings, 2 replies; 3+ messages in thread
From: Martin George @ 2026-10-23 14:00 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, kbusch, sagi

nvme_fc_nvme_discovery_store() takes an lport and rport reference before
checking whether the rport is already queued on the local discovery
list. On the retry path (goto restart), rports that were queued in an
earlier pass are skipped by the list_empty() check, but the references
taken for them in the current pass are never dropped, leaking one lport
and one rport reference per retry.

Check list_empty() first and only take references for rports that are
actually added to the local discovery list.

Signed-off-by: Martin George <marting@netapp.com>
---
 drivers/nvme/host/fc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 48454cb7a0fc..03f6fffc9574 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -3778,6 +3778,9 @@ static ssize_t nvme_fc_nvme_discovery_store(struct device *dev,
 restart:
 	list_for_each_entry(lport, &nvme_fc_lport_list, port_list) {
 		list_for_each_entry(rport, &lport->endp_list, endp_list) {
+			/* skip rports already queued for discovery */
+			if (!list_empty(&rport->disc_list))
+				continue;
 			if (!nvme_fc_lport_get(lport))
 				continue;
 			if (!nvme_fc_rport_get(rport)) {
@@ -3799,9 +3802,7 @@ static ssize_t nvme_fc_nvme_discovery_store(struct device *dev,
 				       "failures\n");
 				goto process_local_list;
 			}
-			if (list_empty(&rport->disc_list))
-				list_add_tail(&rport->disc_list,
-					      &local_disc_list);
+			list_add_tail(&rport->disc_list, &local_disc_list);
 		}
 	}
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-23 22:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 14:00 [PATCH] nvme-fc: fix reference leak in nvme_fc_nvme_discovery_store() Martin George
2026-10-23 14:39 ` Laurence Oberman
2026-10-23 22:06 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox