Skip to contentSkip to conversation

nvme: target: fix error checking in nvmet_fc_schedule_delete_assoc()

PATCH In review Alexandr Sapozhnkiov 4 participants 4 messages Oct 2, 2025 – Oct 6, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: target: fix error checking in nvmet_fc_schedule_delete_assoc()

From: Alexandr Sapozhnikov <[email protected]>

The nvmet_fc_tgtport_get() function may return an error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/nvme/target/fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/fc.c +2 -2
index 337ee1cb09ae..68a416a92bfc 100644
@@ -1110,8 +1110,8 @@ nvmet_fc_delete_assoc_work(struct work_struct *work)
 static void
 nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
 {
-	nvmet_fc_tgtport_get(assoc->tgtport);
-	queue_work(nvmet_wq, &assoc->del_work);
+	if (nvmet_fc_tgtport_get(assoc->tgtport))
+		queue_work(nvmet_wq, &assoc->del_work);
 }
 
 static bool
Signature · 1 line
2.43.0
#1 lore raw

Adding Daniel who has been touching this area recently.

Quoted 28 lines · Alexandr Sapozhnkiov

From: Alexandr Sapozhnikov <[email protected]>

The nvmet_fc_tgtport_get() function may return an error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/nvme/target/fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/fc.c +2 -2
index 337ee1cb09ae..68a416a92bfc 100644
@@ -1110,8 +1110,8 @@ nvmet_fc_delete_assoc_work(struct work_struct *work)
 static void
 nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
 {
-	nvmet_fc_tgtport_get(assoc->tgtport);
-	queue_work(nvmet_wq, &assoc->del_work);
+	if (nvmet_fc_tgtport_get(assoc->tgtport))
+		queue_work(nvmet_wq, &assoc->del_work);
 }
 
 static bool
Signature · 1 line
2.43.0

---end quoted text---

#2 lore raw

Hi Alexandr,

Quoted 6 lines · Christoph Hellwig

Adding Daniel who has been touching this area recently.

Quoted 3 lines · Alexandr Sapozhnkiov

From: Alexandr Sapozhnikov <[email protected]>

The nvmet_fc_tgtport_get() function may return an error.

This description is not correct, because nvmet_fc_tgtport_get wraps around kref_get_unless_zero. The return value is never an error code.

Quoted 7 lines
Quoted 7 lines

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/nvme/target/fc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/nvme/target/fc.c nvmet_fc_delete_assoc_work(struct work_struct *work) · line 1114

Quoted 12 lines
drivers/nvme/target/fc.c +2 -2
index 337ee1cb09ae..68a416a92bfc 100644
@@ -1110,8 +1110,8 @@ nvmet_fc_delete_assoc_work(struct work_struct *work)
 static void
 nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
 {
-	nvmet_fc_tgtport_get(assoc->tgtport);
-	queue_work(nvmet_wq, &assoc->del_work);
+	if (nvmet_fc_tgtport_get(assoc->tgtport))
+		queue_work(nvmet_wq, &assoc->del_work);

nvmet_fc_schedule_delete_assoc can only be called when a reference is held on the assoc->tgtport. The nvmet_fc_tgtport_get is necessary so that the resource is not going away while the work item is executed.

And this patch doesn't seem against a recent kernel as it misses commit 70289ae5cac4 ("nvmet-fc: put ref when assoc->del_work is already scheduled") which was added for 6.15.

I am not against this change but I was under the impression we don't add code to make some tools happy. Maybe it would be enough to add a comment?

Thanks,
Daniel