Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp198538rwi; Wed, 12 Oct 2022 18:34:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54B1+c+rVx3tusP5amg6sBF9r5G/r5+yYsuJWVf31uTVN30Y9PplrkP82+gfGycmhviMRz X-Received: by 2002:a17:90a:f417:b0:20b:6d04:a502 with SMTP id ch23-20020a17090af41700b0020b6d04a502mr8626652pjb.76.1665624849148; Wed, 12 Oct 2022 18:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665624849; cv=none; d=google.com; s=arc-20160816; b=L4q4ZlW+YS/BoORhOHNn6JP4M1kR5zn+eToWakE5qKQgQ0TDe6vAQk8Y5dYABiLxrj YSxXXRr2abBk5WMDzastDJvQ+F1nI7YvRqEy88/6xl1zTo/OF6WBRqDemRm2odWh6pS1 w16+BEUCp5UK3W8TGx+RmocdfN8D+qEZZzMMG3zVu8uW5XW6xGf0Bia9IxBVGMKQJ+Eu nnqldYPuBUbLD7z09nU9Dhp8rLHUuNmfzgepMPSohHV6tHI0ZOXlt+R7rJDMF+kdj7zD 9xMT4DgqsvwgdKGk9114/IoGH4wEvdvyci8qlW8YqGstT0N5nuZDczXOliSt3qeOs6Ld N3Pg== 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=uyr7uFQITT7cUiRiakbXxfBQAjTfnvRmynMmmSOTFiU=; b=r5haMB5NlcmvkdiYP3Y1hDNPPV3ohXD41hG7L9F7zZI2gwuPQZ6JzspkFi+4CDbKCB +AoodKm7BPXnZxyS35IrFDi3YnuwzAp3NBV2i5QkzMr3xbw435jLnVIR8w+ICzMJcrud J3KZ6SapoeDVQw+QqgFbOJMC4vBguYc01Oyfg2AwGG3+/oj4EVFc5HbzApFNDeAnBD2/ FiAhrkyh7wvkWZwg6IEXmff40W2ppWPSD4knIZLOMBTnrI+ukR9EZYe5PBcc39eAJtwK w2VS3HLu0M2nM67j0f0gmLz1ajGmOeI/lPzW2pueU6oIVh0shg5LA5IX/v5cHVbdnPKE 84Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NaZIC5iy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a63d451000000b00462a6f64703si12518727pgj.376.2022.10.12.18.33.58; Wed, 12 Oct 2022 18:34:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NaZIC5iy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbiJMAUp (ORCPT + 99 others); Wed, 12 Oct 2022 20:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbiJMATa (ORCPT ); Wed, 12 Oct 2022 20:19:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27DE0171CD5; Wed, 12 Oct 2022 17:17:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 46F3D616CC; Thu, 13 Oct 2022 00:17:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD61DC4347C; Thu, 13 Oct 2022 00:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620243; bh=QmYPBt2tuHklhPv5OYIPoGItdJBIj0Kc3kuoPwcl3Q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NaZIC5iyryMGdgyqZCu2yDZBu7JJ98NS39QkCCThfzWLfVttnTGAtky8C8Icw4oXy RM5FqFiXNkm3XquxrHMzQQfb+bmVc0b6FAI53prfI9+qCTLh1xbLmXI0khF2kvhyAL vyqXzm3IXugFf0kqu3+QBElJ1TPzxi/jzVCuNrmcbgPmpRka4TAXg7+dUGbrMytD6W p+sTwBgBGavGORrbF3bEtnZNG0bjv+LVjYzgqL9QVC7ps74ECerVRSJwIscydMEVsX EtGAd7RpJGLT6bbpC77LVvzFMw1s+Mi6KBfqSseu0LJN5l2EzYxj79ycPW23u8ylcX 9HPpZu5DfT1gA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jianglei Nie , Mathias Nyman , Greg Kroah-Hartman , Sasha Levin , mathias.nyman@intel.com, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 37/67] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Wed, 12 Oct 2022 20:15:18 -0400 Message-Id: <20221013001554.1892206-37-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jianglei Nie [ Upstream commit 7e271f42a5cc3768cd2622b929ba66859ae21f97 ] xhci_alloc_stream_info() allocates stream context array for stream_info ->stream_ctx_array with xhci_alloc_stream_ctx(). When some error occurs, stream_info->stream_ctx_array is not released, which will lead to a memory leak. We can fix it by releasing the stream_info->stream_ctx_array with xhci_free_stream_ctx() on the error path to avoid the potential memory leak. Signed-off-by: Jianglei Nie Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220921123450.671459-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 8c19e151a945..9e56aa28efcd 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -641,7 +641,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, num_stream_ctxs, &stream_info->ctx_array_dma, mem_flags); if (!stream_info->stream_ctx_array) - goto cleanup_ctx; + goto cleanup_ring_array; memset(stream_info->stream_ctx_array, 0, sizeof(struct xhci_stream_ctx)*num_stream_ctxs); @@ -702,6 +702,11 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, } xhci_free_command(xhci, stream_info->free_streams_command); cleanup_ctx: + xhci_free_stream_ctx(xhci, + stream_info->num_stream_ctxs, + stream_info->stream_ctx_array, + stream_info->ctx_array_dma); +cleanup_ring_array: kfree(stream_info->stream_rings); cleanup_info: kfree(stream_info); -- 2.35.1