nvmet-fc: simplify and fix nvmet_fc_alloc_hostport
Subsystems (3)
PATCH 1/1 nvmet-fc: simplify and fix nvmet_fc_alloc_hostport
From: Amit Engel <[email protected]>
Alloc newhost only if no host has been found in host_list Add a missing tgtport release reference
Signed-off-by Amit Engel <[email protected]>
--- drivers/nvme/target/fc.c | 45 +++++++++++++++------------------------- 1 file changed, 17 insertions(+), 28 deletions(-)
drivers/nvme/target/fc.c +17 -28
@@ -1034,28 +1034,6 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)if (!nvmet_fc_tgtport_get (tgtport))return ERR_PTR (-EINVAL ); - newhost =kzalloc (sizeof (*newhost),GFP_KERNEL ); -if (!newhost) { -spin_lock_irqsave (&tgtport->lock, flags); -list_for_each_entry (host, &tgtport->host_list, host_list) { -if (host->hosthandle == hosthandle && !host->invalid) { -if (nvmet_fc_hostport_get (host)) { - match = host; -break ; - } - } - } -spin_unlock_irqrestore (&tgtport->lock, flags); -/* no allocation - release reference */ -nvmet_fc_tgtport_put (tgtport); -return (match) ? match :ERR_PTR (-ENOMEM ); - } - - newhost->tgtport = tgtport; - newhost->hosthandle = hosthandle; -INIT_LIST_HEAD (&newhost->host_list); -kref_init (&newhost->ref); -spin_lock_irqsave (&tgtport->lock, flags);list_for_each_entry (host, &tgtport->host_list, host_list) {if (host->hosthandle == hosthandle && !host->invalid) {
@@ -1065,13 +1043,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle) } } } -if (match) { -kfree (newhost); - newhost =NULL ; -/* releasing allocation - release reference */ -nvmet_fc_tgtport_put (tgtport); - }else +if (!match) { + newhost =kzalloc (sizeof (*newhost),GFP_KERNEL ); +if (!newhost) { +/* no allocation - release reference */ +nvmet_fc_tgtport_put (tgtport); +spin_unlock_irqrestore (&tgtport->lock, flags); +return ERR_PTR (-ENOMEM ); + } + + newhost->tgtport = tgtport; + newhost->hosthandle = hosthandle; +INIT_LIST_HEAD (&newhost->host_list); +kref_init (&newhost->ref); +list_add_tail (&newhost->host_list, &tgtport->host_list); + } +/* release reference */ +nvmet_fc_tgtport_put (tgtport);spin_unlock_irqrestore (&tgtport->lock, flags);return (match) ? match : newhost;
Signature · 7 lines
2.18.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 6 lines · On 3/3/21 08:43, [email protected] wrote:
From: Amit Engel <[email protected]>
Alloc newhost only if no host has been found in
host_listAdd a missing tgtport release referenceSigned-off-by Amit Engel <[email protected]>
You need to CC James on this patch.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme