From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0B8CC369A2 for ; Mon, 14 Apr 2025 13:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hzCq3un4gjLQgOBJc/Whk6CDN7BbFqovKFQl1LIiFjY=; b=g4/LErnG+3x/utBbR5QbIn2FDE wuzExQub66Gm8O/pSOCNwnZGRvXyIbMT+R797GSQX7DSjxaNLibcKnT+h8z5uXXyrHOZb5b5j/Q0k sZmyYVGW0ED0rrdAKoYX1VUbfEiayIOjvLvq99s7o45b3GTuqCVRdA8UvYrP7yEtA7mVKVZgUFc2l EGNhzmSLHLpXV0Uv6SSNbP+uUVfV65+MvPueC0Q7oR7yRb79HOR9tNCR6FFtHPpGbGvFmqsnOFD+L 73LmubU/5cVy0eVcwd20gpBikawUQJzabaZ4oGv9wLjCwfwxYiJ5wQzrUrSoO6j9A568XsnW2YFHB C23maWcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4JtC-000000028iM-367I; Mon, 14 Apr 2025 13:30:18 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4JrT-000000028Ev-1B6o for linux-nvme@lists.infradead.org; Mon, 14 Apr 2025 13:28:32 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 00CE24A574; Mon, 14 Apr 2025 13:28:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F908C4CEE2; Mon, 14 Apr 2025 13:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744637310; bh=zoAf7BIuluC1txZ4yjQEbLP0gHpfXijkojicAkawmCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rbrt1NmO+TulMelJ0ZCEKEFvpdN72txBczNvw7z9wsuUTCDX6Ad1fWv1F++V14pRs ckf4FvBF8NrEfrmTXoFXuAuIl8gk4k8T0gE6BTqRH7mwc/2g9AyScE6Gle98xGt84c /b26utShCqPELo8W5g/if61Nv/Exjb4lt7DOCVZhc7HZ+jc5iIhCggA9LEqWNSjHZz ScwjSc6ByypGOMH8XfppYMIbl1OEoOJeA3DP/8mLVdKaYrTF5Yn0B7B44zjhKFNKqo 8rG1HUSGIqOXkIwuPQHT4XABP3Uft/0p3EE9dxvZ+tH5uLvLY7dWa305+bKG4C2KpX y06VNC/hTYfig== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniel Wagner , Hannes Reinecke , Christoph Hellwig , Sasha Levin , james.smart@broadcom.com, sagi@grimberg.me, kch@nvidia.com, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.13 26/34] nvmet-fc: take tgtport reference only once Date: Mon, 14 Apr 2025 09:27:20 -0400 Message-Id: <20250414132729.679254-26-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250414132729.679254-1-sashal@kernel.org> References: <20250414132729.679254-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.13.11 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_062831_334888_6DDBE3F6 X-CRM114-Status: GOOD ( 13.97 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org 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 3ef4beacde325..a3a6dfe98d6fc 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1042,33 +1042,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); @@ -1077,6 +1068,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