nvmet-fc: take tgtport reference only once
[ Upstream commit b0b26ad0e1943de25ce82a7e5af3574f31b1cf99 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
bb4b487bbd
commit
9635d486b6
@@ -1028,33 +1028,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
|
|||||||
struct nvmet_fc_hostport *newhost, *match = NULL;
|
struct nvmet_fc_hostport *newhost, *match = NULL;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Caller holds a reference on tgtport.
|
||||||
|
*/
|
||||||
|
|
||||||
/* if LLDD not implemented, leave as NULL */
|
/* if LLDD not implemented, leave as NULL */
|
||||||
if (!hosthandle)
|
if (!hosthandle)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/*
|
|
||||||
* take reference for what will be the newly allocated hostport if
|
|
||||||
* we end up using a new allocation
|
|
||||||
*/
|
|
||||||
if (!nvmet_fc_tgtport_get(tgtport))
|
|
||||||
return ERR_PTR(-EINVAL);
|
|
||||||
|
|
||||||
spin_lock_irqsave(&tgtport->lock, flags);
|
spin_lock_irqsave(&tgtport->lock, flags);
|
||||||
match = nvmet_fc_match_hostport(tgtport, hosthandle);
|
match = nvmet_fc_match_hostport(tgtport, hosthandle);
|
||||||
spin_unlock_irqrestore(&tgtport->lock, flags);
|
spin_unlock_irqrestore(&tgtport->lock, flags);
|
||||||
|
|
||||||
if (match) {
|
if (match)
|
||||||
/* no new allocation - release reference */
|
|
||||||
nvmet_fc_tgtport_put(tgtport);
|
|
||||||
return match;
|
return match;
|
||||||
}
|
|
||||||
|
|
||||||
newhost = kzalloc(sizeof(*newhost), GFP_KERNEL);
|
newhost = kzalloc(sizeof(*newhost), GFP_KERNEL);
|
||||||
if (!newhost) {
|
if (!newhost)
|
||||||
/* no new allocation - release reference */
|
|
||||||
nvmet_fc_tgtport_put(tgtport);
|
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irqsave(&tgtport->lock, flags);
|
spin_lock_irqsave(&tgtport->lock, flags);
|
||||||
match = nvmet_fc_match_hostport(tgtport, hosthandle);
|
match = nvmet_fc_match_hostport(tgtport, hosthandle);
|
||||||
@@ -1063,6 +1054,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
|
|||||||
kfree(newhost);
|
kfree(newhost);
|
||||||
newhost = match;
|
newhost = match;
|
||||||
} else {
|
} else {
|
||||||
|
nvmet_fc_tgtport_get(tgtport);
|
||||||
newhost->tgtport = tgtport;
|
newhost->tgtport = tgtport;
|
||||||
newhost->hosthandle = hosthandle;
|
newhost->hosthandle = hosthandle;
|
||||||
INIT_LIST_HEAD(&newhost->host_list);
|
INIT_LIST_HEAD(&newhost->host_list);
|
||||||
|
|||||||
Reference in New Issue
Block a user