From patchwork Mon Oct 24 11:31:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp416556wru; Mon, 24 Oct 2022 05:11:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7fJowvWlnDAcno0iGhHw0v4T5kshiZmntG0z1/ngZafbFdwIqBH52CWOxmmZ1s31jDEW0j X-Received: by 2002:a05:6402:5406:b0:452:1560:f9d4 with SMTP id ev6-20020a056402540600b004521560f9d4mr30719715edb.333.1666613513058; Mon, 24 Oct 2022 05:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613513; cv=none; d=google.com; s=arc-20160816; b=PFxTDcp4nC/iw0j3N1DsLjGc2YBhQ0A1P368J0O2ZAgLP2Xa5f1svw9pEEHamn0Mxi apb3sv4tLiOnfLzUT92Oq4atf4+9H6ihppFnPbQg/XItP//f5VvKakNzP/eG3SLAHAZH x/iGHhTRVPrCrUvDysuH257xK2QadRrQ0nrWh3ZHfHpVLOkQRL3xguwPbdsqfZW/T51w UpEVMuJnXw2XW/9Qby4S9BeEwBGIgvXMoowQPLvAJDEZ/3pWLAWGWK3nXgyhDazYy4bb trd0JVIqo9z8YsEB7YPQcSg3Y4cuVFbMWbDh8S06kfXdCs4DD5eXoWJBqq2ksroBs9fC ayfg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020a50fe96000000b0045beaf03ddesi23272216edt.411.2022.10.24.05.11.26; Mon, 24 Oct 2022 05:11:53 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747570930842794689?= X-GMAIL-MSGID: =?utf-8?q?1747570930842794689?= 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);