nvmet-fc: hold reference on hostport match
authorDaniel Wagner <dwagner@suse.de>
Wed, 31 Jan 2024 08:51:06 +0000 (09:51 +0100)
committerKeith Busch <kbusch@kernel.org>
Thu, 1 Feb 2024 15:44:51 +0000 (07:44 -0800)
The hostport data structure is shared between the association, this why
we keep track of the users via a refcount. So we should not decrement
the refcount on a match and free the hostport several times.

Reported by KASAN.

Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/target/fc.c

index b44b99525c44646c182c941d4c7aa4c76e93cc2d..205a12b1e8413a976cb4dd06e2817162d599bd79 100644 (file)
@@ -1068,8 +1068,6 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
                /* new allocation not needed */
                kfree(newhost);
                newhost = match;
-               /* no new allocation - release reference */
-               nvmet_fc_tgtport_put(tgtport);
        } else {
                newhost->tgtport = tgtport;
                newhost->hosthandle = hosthandle;