Skip to content

Commit b0b26ad

Browse files
igawChristoph Hellwig
authored andcommitted
nvmet-fc: take tgtport reference only once
The reference counting code can be simplified. Instead taking a tgtport refrerence at the beginning of nvmet_fc_alloc_hostport and put it back if not a new hostport object is allocated, only take it when a new hostport object is allocated. Signed-off-by: Daniel Wagner <wagi@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 1a90956 commit b0b26ad

File tree

1 file changed

+7
-15
lines changed
  • drivers/nvme/target

1 file changed

+7
-15
lines changed

drivers/nvme/target/fc.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,33 +1018,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
10181018
struct nvmet_fc_hostport *newhost, *match = NULL;
10191019
unsigned long flags;
10201020

1021+
/*
1022+
* Caller holds a reference on tgtport.
1023+
*/
1024+
10211025
/* if LLDD not implemented, leave as NULL */
10221026
if (!hosthandle)
10231027
return NULL;
10241028

1025-
/*
1026-
* take reference for what will be the newly allocated hostport if
1027-
* we end up using a new allocation
1028-
*/
1029-
if (!nvmet_fc_tgtport_get(tgtport))
1030-
return ERR_PTR(-EINVAL);
1031-
10321029
spin_lock_irqsave(&tgtport->lock, flags);
10331030
match = nvmet_fc_match_hostport(tgtport, hosthandle);
10341031
spin_unlock_irqrestore(&tgtport->lock, flags);
10351032

1036-
if (match) {
1037-
/* no new allocation - release reference */
1038-
nvmet_fc_tgtport_put(tgtport);
1033+
if (match)
10391034
return match;
1040-
}
10411035

10421036
newhost = kzalloc(sizeof(*newhost), GFP_KERNEL);
1043-
if (!newhost) {
1044-
/* no new allocation - release reference */
1045-
nvmet_fc_tgtport_put(tgtport);
1037+
if (!newhost)
10461038
return ERR_PTR(-ENOMEM);
1047-
}
10481039

10491040
spin_lock_irqsave(&tgtport->lock, flags);
10501041
match = nvmet_fc_match_hostport(tgtport, hosthandle);
@@ -1053,6 +1044,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
10531044
kfree(newhost);
10541045
newhost = match;
10551046
} else {
1047+
nvmet_fc_tgtport_get(tgtport);
10561048
newhost->tgtport = tgtport;
10571049
newhost->hosthandle = hosthandle;
10581050
INIT_LIST_HEAD(&newhost->host_list);

0 commit comments

Comments
 (0)