nvmet-fc: check successful reference in nvmet_fc_find_target_assoc
authorJames Smart <jsmart2021@gmail.com>
Fri, 24 Jul 2020 16:40:00 +0000 (09:40 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 29 Jul 2020 05:45:20 +0000 (07:45 +0200)
When searching for an association based on an association id, when there
is a match, the code takes a reference. However, it is not validating
that the reference taking was successful.

Check the status of the reference. If unsuccessful, the device is being
deleted and should be ignored.

Signed-off-by: James Smart <jsmart2021@gmail.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/fc.c

index 27fd3b5..c15356b 100644 (file)
@@ -1243,7 +1243,8 @@ nvmet_fc_find_target_assoc(struct nvmet_fc_tgtport *tgtport,
        list_for_each_entry(assoc, &tgtport->assoc_list, a_list) {
                if (association_id == assoc->association_id) {
                        ret = assoc;
-                       nvmet_fc_tgt_a_get(assoc);
+                       if (!nvmet_fc_tgt_a_get(assoc))
+                               ret = NULL;
                        break;
                }
        }