From nobody Mon Feb 9 10:27:36 2026 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 57687238D2E for ; Wed, 26 Feb 2025 18:46:17 +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=1740595577; cv=none; b=W8/e/vSmqIOBT9VstLGfkNN9qO0aP4IjG6nh+tOq4NeLBU55Rs4vAmDJJkbRgkWRHDR6mPbgyjjEcopizbKutqvXoOO7/BvV73rU5dTcdtGNI5ujIfpQiZyuv6/FnTCHoQ+8eUl39iXXWvwBUPxagLpEIvrxWEJremuF66mx1pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740595577; c=relaxed/simple; bh=LWNcOUyHSpm76/r8wsTzzymlSz71tkb01XzMtOR6qcc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a9Avgrplw+RyhO10q92wJbbRXdiIV3DT4mPmGP1mt/9/lvJZumB1YWK7vB1RzwLxFVXhonwWCcrc2mUr7dolCYP8C1uzeaKhfVGVWZ4QJ6p6krYGht51F/oMuNBGqOqkdBwF3Fad3JN9S5gyQgCMnBHn20p70DT8XKUZrZ7v218= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WRxP5h0k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WRxP5h0k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1AD9C4CEEC; Wed, 26 Feb 2025 18:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740595577; bh=LWNcOUyHSpm76/r8wsTzzymlSz71tkb01XzMtOR6qcc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WRxP5h0kukCPaOyW+ojFaAMhTV7G6BMdg1nMeYkDaXUszhMdm9K2XPTZNtLRe5s0J j6Ty7zKCZ2XJ0FX931zzsUBuwBLgwZeHkgFPlvqpopcdsQFLdfmDQQR9856n7nCSsb xBzDcZbp6Jt5ZpoZIxCwR1ZcmMyhrUvVe2D6wHPdlAAXXplcsOXsGhI489VEEYxbhz jJNxBZAL7CroR8cIbwFlNg7xs9Ws/NrH3XoVTKfiZSGZLCPlAarc9Z/CCfw1cS8nS9 joAx4V5ZKmf4kNxKoQo1fkEuXUHDEBfpP0D+jHrdL7iw35yvrGLPV85IDzi4EO7Snv AUpqGCePvBtBQ== From: Daniel Wagner Date: Wed, 26 Feb 2025 19:46:00 +0100 Subject: [PATCH 08/11] nvmet-fc: take tgtport reference only once Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250226-nvmet-fcloop-v1-8-c0bd83d43e6a@kernel.org> References: <20250226-nvmet-fcloop-v1-0-c0bd83d43e6a@kernel.org> In-Reply-To: <20250226-nvmet-fcloop-v1-0-c0bd83d43e6a@kernel.org> To: James Smart , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: Hannes Reinecke , Keith Busch , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Daniel Wagner X-Mailer: b4 0.14.2 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 --- drivers/nvme/target/fc.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index b807b4c05cac7fe4764df3df76f8fa50f4bab6ba..391917b4ce0115dbc0ad99d1fb3= 63b1af6ee0685 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1046,29 +1046,16 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tg= tport, void *hosthandle) if (!hosthandle) return NULL; =20 - /* - * 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 =3D nvmet_fc_match_hostport(tgtport, hosthandle); spin_unlock_irqrestore(&tgtport->lock, flags); =20 - if (match) { - /* no new allocation - release reference */ - nvmet_fc_tgtport_put(tgtport); + if (match) return match; - } =20 newhost =3D kzalloc(sizeof(*newhost), GFP_KERNEL); - if (!newhost) { - /* no new allocation - release reference */ - nvmet_fc_tgtport_put(tgtport); + if (!newhost) return ERR_PTR(-ENOMEM); - } =20 spin_lock_irqsave(&tgtport->lock, flags); match =3D nvmet_fc_match_hostport(tgtport, hosthandle); @@ -1077,6 +1064,7 @@ nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtp= ort, void *hosthandle) kfree(newhost); newhost =3D match; } else { + nvmet_fc_tgtport_get(tgtport); newhost->tgtport =3D tgtport; newhost->hosthandle =3D hosthandle; INIT_LIST_HEAD(&newhost->host_list); --=20 2.48.1