From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBCF73FFD; Tue, 29 Apr 2025 18:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949633; cv=none; b=ZQX1GAiZjPUcwqh1xrixsPMEa69+nb7T83zrj6dDkLg0sR/yakuvOBnBE1US5Ic3w2UQHWiydQSPDBDDE8Qr3Sz5QZsmmmvg7MKU2iXmOiLX3OJTc6TVmsAHkeCsh3NvyKbzZTPDrEEf8t9x2wmsfP5Gu9c2kjTlvMCyeD0227c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949633; c=relaxed/simple; bh=7IwtVnu6Nn5Nd7vE0U18a5UnkmDQaOTVDIeaWZw01a4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q5I+8Ld9W0o59Y6cYMXJ/I+az8WttnlEifEaV9ztOVk3jBArRBA/zut8WscJxBkoMzNSnCetzXZRk9jL8pYkk78x12aHP4XbiVkbalkGYlnTFO/Dt9Oz3tniI1nbQiXlYj41XO5U925ns3nJT4aWTDCidqCf3JEDDGqBaPSD3Nw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=E1tsOisk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="E1tsOisk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A883C4CEE3; Tue, 29 Apr 2025 18:00:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745949632; bh=7IwtVnu6Nn5Nd7vE0U18a5UnkmDQaOTVDIeaWZw01a4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E1tsOiskE3PFMdMlepppiRmXIDlLeidSlL+yuGfA44/VfbCWFo7bG73WFgXn8DQE+ bj4WBOtIfz1LMdTU/vXoKX64kkDSJIOZbpOmv+EhXbwQrfPApv/7YgR4pzKHzVbSHw S5oc1OEFHAVfC7V3TaRpsNk697+D6SUCXjygubYI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Daniel Wagner , Hannes Reinecke , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.15 352/373] nvmet-fc: take tgtport reference only once Date: Tue, 29 Apr 2025 18:43:49 +0200 Message-ID: <20250429161137.612872400@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161123.119104857@linuxfoundation.org> References: <20250429161123.119104857@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Wagner [ 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 Reviewed-by: Hannes Reinecke Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/fc.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 88893e78661c6..9f6d91e79aac5 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1030,33 +1030,24 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle) struct nvmet_fc_hostport *newhost, *match = NULL; unsigned long flags; + /* + * Caller holds a reference on tgtport. + */ + /* if LLDD not implemented, leave as NULL */ if (!hosthandle) 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); match = nvmet_fc_match_hostport(tgtport, hosthandle); spin_unlock_irqrestore(&tgtport->lock, flags); - if (match) { - /* no new allocation - release reference */ - nvmet_fc_tgtport_put(tgtport); + if (match) return match; - } newhost = kzalloc(sizeof(*newhost), GFP_KERNEL); - if (!newhost) { - /* no new allocation - release reference */ - nvmet_fc_tgtport_put(tgtport); + if (!newhost) return ERR_PTR(-ENOMEM); - } spin_lock_irqsave(&tgtport->lock, flags); match = nvmet_fc_match_hostport(tgtport, hosthandle); @@ -1065,6 +1056,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle) kfree(newhost); newhost = match; } else { + nvmet_fc_tgtport_get(tgtport); newhost->tgtport = tgtport; newhost->hosthandle = hosthandle; INIT_LIST_HEAD(&newhost->host_list); -- 2.39.5