Received: by 2002:ac0:c50a:0:0:0:0:0 with SMTP id y10csp996928imi; Fri, 1 Jul 2022 00:13:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sq4U2V01cM8647WgWlviX03uzs/beCzJCnVPxHratnx/XViZQwOtIWhc4XFQFlyvMqzMNt X-Received: by 2002:a17:902:f710:b0:167:7a06:b2ce with SMTP id h16-20020a170902f71000b001677a06b2cemr19861876plo.104.1656659583540; Fri, 01 Jul 2022 00:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656659583; cv=none; d=google.com; s=arc-20160816; b=J0pAlC41no7ICSo33j4izNlSexqXvrlphJyKFSdvEHHPAKYYFF7GfZccnQCbVcfjGD k6shOdcpPTzb5WAu+vikXe9F6DxmUqyC7jKCfu4hBzvRnj0VBCQ/5IewR8AF42Xdq0ta 8iwxQz5hpELmdX/MVhBI1mjGS2DUF4vfhrTkKxrsIl/ztZimyuL+Fcy+FZDbaETpmkEs ZJAjiNTY9n/4ewihekPJPunqNFCpc8J8uZ8k66Q7wHcsOPeM/tU140xQVNfnvXgCWRLe l69kqiFFf9yyBtf2NkfABk52l6dBeLi59W0hRqje2iosw//kEOXdwNdm2aFJmZKQGLsC W1tw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=sReSMhucH/qWbquMPkRNKaMOx4jB93wLhYEMfyfSQQE=; b=uQyC5OlJigalwZbf4fm78c0N1cZW2Aucvw6y+C/Ekp+YHsRy7L2uirn5et6G1ctiCM OAM24aWxdTZO0qIy47ZebdEUvNymUE4Yk02nnVqqaoyi1VPlwWlNOKa37XdR5KTU9CsU 2f4lddKJ9tWTf+iZVzwwhE7uyCvjjd8m4jJmfE9jE8VyxkUHqrRu/2V70oUdy36G/bkU bArwGp9neDU8gGA79kamoNFhmg+VPB82KpFrIiRc055Lug4hQkAeWlfOXm/D1jG1hfMQ Ix73+zC+M38Zk8J317JHNTZc9Berdh1uiX2mulrKOqjAR1uHTY2lLFZsXrqnneXAeRNQ bPDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jAoLAVq1; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a632c0f000000b0040d9515c0ffsi27228775pgs.355.2022.07.01.00.12.51; Fri, 01 Jul 2022 00:13:03 -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=@163.com header.s=s110527 header.b=jAoLAVq1; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233418AbiGAHK7 (ORCPT + 99 others); Fri, 1 Jul 2022 03:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbiGAHK5 (ORCPT ); Fri, 1 Jul 2022 03:10:57 -0400 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6E8568A0D; Fri, 1 Jul 2022 00:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=sReSM hucH/qWbquMPkRNKaMOx4jB93wLhYEMfyfSQQE=; b=jAoLAVq1zztmdfFCMevmf c3rvf1I6NJ6E1usPef8fcRR6ToqAKrqbzN32aXMFENkoNhP/b65yCEr5ssUbucTD Ntsh1X6FjDoEIiJ6EPP4sNcY/+fG9LJrE8CwrATkIah6aFKDXGVvgByEtdhLCMcg cr7yH0qYprT4AVUZ0lnNrU= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp4 (Coremail) with SMTP id HNxpCgBHItrOnb5i+Ue8MA--.60803S4; Fri, 01 Jul 2022 15:10:27 +0800 (CST) From: Jianglei Nie To: mathias.nyman@intel.com, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH v2] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Fri, 1 Jul 2022 15:10:02 +0800 Message-Id: <20220701071002.2184370-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgBHItrOnb5i+Ue8MA--.60803S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw48KFWxCF17WF1DuFy8Zrb_yoW8Xw1rpF yrZw1F9r43tFn7KF1DJa4Yvay8Kw18Ga4rKrZrJ34kur4DtF45XF1UCFW8urySvr1xWr10 yF98twn3JF4UGFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRxhLnUUUUU= X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbB0QQxjFzIBsedlQAAs1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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 --- 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.25.1