Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6743815rwi; Mon, 24 Oct 2022 05:41:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WHCEzbLoHDJjXqusFnmiM7J6CfHIc1H51SB9rAbsnQK5XPHRjjUh3kxAaNAGFjG0YvYZd X-Received: by 2002:a65:6a0f:0:b0:46e:f67c:bcee with SMTP id m15-20020a656a0f000000b0046ef67cbceemr6471554pgu.38.1666615262501; Mon, 24 Oct 2022 05:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615262; cv=none; d=google.com; s=arc-20160816; b=TreaJ/szsk6QMRGRIvS6wHfvALE5BGQVvnR0ug5Z+5ScZ64Jo7kT7x5ZQtrGw/tB6F A7OWIqltTtAUzq+AybjoX9DNFfoj92MnaOd0STifeIq8S+5dMsDA0WDUNIiGKlBkZzkh wXIkedzBitnyRaSIYP8MyQuEUJ1OH35dd1AYVYJAJt7jKjrEr+6G/aOnFRFXs3R0kzL/ MjJFx0OClwA3dVEQhndC9SFUy/+hLKbtBVHRWcMgXpG4gUSLevRPSKd2htGR+WkfpMOk v9oHM2UorYbLbF6IGne0I+wTSPYlIaTvkwC2JnYtiIVVWwzYxpMApqfUFXYlP/tomLTf HSyQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AEfKijShn3do2z+a7+bXLdnXu21SC7EAU5eSsLTLwFA=; b=OS9kC0SKuTAhN35odUnDLgFY3DWX7o3h+KmiKIiSmhd312KLaTj/4wt6VkPqfpowTd 0tsSdepfF0nccoKSMK0Ht6GQbl+9pAoiyZtX0OB70X8yt6qk8aYhQOHfaGRNDn3pv3UW 0nGgQ8GM5kQ8rRWVuUTo+iv+ekIUbQOIvnDhC7wDsEgxHRz1luLTL6CLRH6gunkrTRJX S+/A5bkVJ8neuF12XBB1sjzlpTYeZAG0ufFnKVpX1EiK9gp31THac1peD1CNYvYEKBXU uim3hYACCrqHkpYgTI0YkablxJInYDWfmx5lSIzlfOK6l38xDoEhpWisDRYRRlGWOkf7 f3vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tJUjH0FP; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020a6546cf000000b0046b2ec0de65si34522887pgr.789.2022.10.24.05.40.41; Mon, 24 Oct 2022 05:41:02 -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=@linuxfoundation.org header.s=korg header.b=tJUjH0FP; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232206AbiJXL6c (ORCPT + 99 others); Mon, 24 Oct 2022 07:58:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232321AbiJXL47 (ORCPT ); Mon, 24 Oct 2022 07:56:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFA267B581; Mon, 24 Oct 2022 04:47:08 -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 2FE66612B1; Mon, 24 Oct 2022 11:45:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F25AC433D7; Mon, 24 Oct 2022 11:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611917; bh=Xzjr1c31nVklNKmxLuRkYMncuBbqb1/Fpk/i6gX/Q0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tJUjH0FP+59CCxLyU51fCfpEt5t1FcSwm+8JHURrND3aEP7CpZ1tRckyQ5Za0nxay 2B+MiwvhVvcDCi9N66iDBV9XoX0Mmh2PBVRBjAUwFEJM+UfQGjgB0I8hPm5bb55P4U nLIk348eUrTwiQ5hFqMh+jj/t31Ik19vh1Vd3/20= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , Mathias Nyman , Sasha Levin Subject: [PATCH 4.9 149/159] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Mon, 24 Oct 2022 13:31:43 +0200 Message-Id: <20221024112954.860673461@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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 9b30936904da..0850d587683a 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -703,7 +703,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); @@ -764,6 +764,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