Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2969690rdb; Mon, 4 Dec 2023 12:35:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbwWByzmVMunjczm6/f77Oxp4DK4o19qCDr/O9gT+iL92yHIyH8Umbvb4bN8B41d8WMtUj X-Received: by 2002:a05:6a20:dd8f:b0:18f:97c:4f4a with SMTP id kw15-20020a056a20dd8f00b0018f097c4f4amr2027893pzb.86.1701722149733; Mon, 04 Dec 2023 12:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701722149; cv=none; d=google.com; s=arc-20160816; b=rJ7keTjYxA7K5OV+6hU3IhqQVHHVg1HoIiKTAQnCoqUqt98lJV7w1QksiY5jPdAFrx 0YVVhKlvOftc+BeXJ7vcC2r7kGJq1O8rDUnteYVnLdsuzXwhCBdZtKL/rfpTS1QRaNlF pjr1U5wP8SG7VPGqwMF0bkNICicW5gwLjJgBzzTRnKlWXX/ogtWyphCe2X78g27BQiiP Umy30TjP4haoYwO1nFd3ps005a3wh2E6TGqpSLWrZGZf8D7/308USFfNtj0LoBeLkFyS RpzELHoO2PYBVZ/SsEixS9Q/GzQE55BdYnbGy5f9RCSdo4CZEf5dAKgkzJDTvGDYsZvw ZYgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y3dQK/4SI4uKBoyoixXgNBT4eBRRVpPRrR9Ivd3efDU=; fh=YAyqxq+i/mHOtZSYOIqYY+MGFks0Ua4uPZkFCoLFRuE=; b=oimPsprWY60Hp7PCI/2C00hYFTojQJSaPA8VP50FTcMb9V/8Qpyo+6ygedPWvZffxq 3NLdFT3KoFe0H6lDNZHRgasVec2lGjdlumJ/rHrNZ0asy+tNVscvj9sd3MFO8WTaQEi1 m9PhjPqCEh1IWDFecXV/719/wmqc1O10+GpVlcXvuij7JBVhGdkqa3MIicTEpL5rIQ7s ejn4iL2/YlQPMiINwElxOHfB1sLz4/SO+dbE4jSidlQnZQHqvKciRldbNOyWrFPe04pK xzZcgWR4mflSGiE2WWqbb23PeDgq2xfVMeQ5ldTRVVwdkd/aKkoxCH90uq1CfP8RuSHe J+YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="SikVv5/l"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id by1-20020a056a02058100b005c65dc887dbsi4496811pgb.557.2023.12.04.12.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:35:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="SikVv5/l"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 8A535805CDA3; Mon, 4 Dec 2023 12:35:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345809AbjLDUfJ (ORCPT + 99 others); Mon, 4 Dec 2023 15:35:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346353AbjLDUeo (ORCPT ); Mon, 4 Dec 2023 15:34:44 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73C801BE7 for ; Mon, 4 Dec 2023 12:34:08 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAD05C433B6; Mon, 4 Dec 2023 20:34:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701722048; bh=eTg1VInLU4qMeGqYVspdg5OJ9xCuQsygjmP3eMfpLw0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SikVv5/lKGTVVs0ZQoPjUxLchz13rMa+0NbQE8AuYKGceATteFqAE1XW5JFTCOF61 BdGdK6Rk4PxkiOBczkwRmE5F7tDqZ187i5wD4vsvrmEhrU8zT8iOamEVdqyTWfftcT ZEY8L8LCgigUqTOy4wA4bjdSxwjOU3v2uKcRbPYMCaVYNgxtZd9tZk/eIiOeQkfE3C sPYiSHj/7+ad4DnEegVr01mG8s8kHgtowoBUDP+3v61bQ+lIM+iQcgSReOZy1OO+C+ qdh6TLO5ECW+iKOjja+y9BZiC6DbH8MDfdz5kHKakuIunN59CkQOsY7RkKkmI7ecpB LT5SZxmD+3WRg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maurizio Lombardi , Sagi Grimberg , Kanchan Joshi , Keith Busch , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.6 20/32] nvme-core: fix a memory leak in nvme_ns_info_from_identify() Date: Mon, 4 Dec 2023 15:32:40 -0500 Message-ID: <20231204203317.2092321-20-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231204203317.2092321-1-sashal@kernel.org> References: <20231204203317.2092321-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.4 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 04 Dec 2023 12:35:42 -0800 (PST) From: Maurizio Lombardi [ Upstream commit e3139cef8257fcab1725441e2fd5fd0ccb5481b1 ] In case of error, free the nvme_id_ns structure that was allocated by nvme_identify_ns(). Signed-off-by: Maurizio Lombardi Reviewed-by: Sagi Grimberg Reviewed-by: Kanchan Joshi Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 21783aa2ee8e1..b4521deb1c716 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1479,7 +1479,8 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, if (id->ncap == 0) { /* namespace not allocated or attached */ info->is_removed = true; - return -ENODEV; + ret = -ENODEV; + goto error; } info->anagrpid = id->anagrpid; @@ -1497,8 +1498,10 @@ static int nvme_ns_info_from_identify(struct nvme_ctrl *ctrl, !memchr_inv(ids->nguid, 0, sizeof(ids->nguid))) memcpy(ids->nguid, id->nguid, sizeof(ids->nguid)); } + +error: kfree(id); - return 0; + return ret; } static int nvme_ns_info_from_id_cs_indep(struct nvme_ctrl *ctrl, -- 2.42.0