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 B6168284662; Mon, 14 Apr 2025 13:27:12 +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=1744637232; cv=none; b=dhsV7qIWRB3OnBOvRyEEjV0VrMLYXXITycxCe3bDQoydnxqJRvkFTjtHG3TCbYgHB//z3c4gF/k06anCXmvkZ/kUSdYqNPPSWvO8jRU6bZVdKdfsBfncJNxjYEJum7YoMNT/RqrCrwD1y7ImWAOFRfOpwg4RwyDXmggDyO/sBws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744637232; c=relaxed/simple; bh=zoAf7BIuluC1txZ4yjQEbLP0gHpfXijkojicAkawmCM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U/Iz8C8JHEK4l2cVmu8dp2JvKbYTu8nUu2CFZc6hJ7n1x2NQ+yuxa79XIcXnYLPX/VQjbuen88Pd+y5pV61aeHgHynB5kWKbPKUV2lEMqZ0QCrtFmyx5TQNxzPkWSbCCZzYIXekJccf9Rj3k0oC/zGoqzpcBa/yIUqB+RJxopGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NAP7EW30; 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="NAP7EW30" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7BD2C4CEE9; Mon, 14 Apr 2025 13:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744637232; bh=zoAf7BIuluC1txZ4yjQEbLP0gHpfXijkojicAkawmCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NAP7EW30SE3nJGotBTbW+jXUmTaTyIpAd8QfV8q6yoiRge0Rx4j+NQFIiNerygyTz mEJccVEQwOxUWPfhFeSX++zvIgK+6HK23ETYKcOVMsGDK/Yb+37deOCrpQI8Chm/0X aCVXm/MB9zAVBLT9wQJeRGrQMKZX7T87j1PyJOmDDvNK+akjSPHYuaw9N7n1il//HN sIOgNhXgKBE0VGWkS6+Bsg7+78Uq2NTD1RgZYtOZoOQtG+UIdJ/kqI/ttAIjHmw5VJ yG4dQBguFT7jfy+ETJj1gRCw8Z+iwSAXImtjJc9AbrRnINKZQrSN7rOXZg28n0shVx P/+LChaA7Se8A== 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.14 26/34] nvmet-fc: take tgtport reference only once Date: Mon, 14 Apr 2025 09:26:02 -0400 Message-Id: <20250414132610.677644-26-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250414132610.677644-1-sashal@kernel.org> References: <20250414132610.677644-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.14.2 Content-Transfer-Encoding: 8bit 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