Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp3165088qtb; Mon, 24 Oct 2022 07:11:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM447faCgeoiQwbuDXSBRSZUHttyH1U0LCFOy6csXcE4zKSfKKSDdf5irlNclpdZplo+QRYI X-Received: by 2002:a05:6402:1f84:b0:455:27b8:27aa with SMTP id c4-20020a0564021f8400b0045527b827aamr30356581edc.243.1666620701686; Mon, 24 Oct 2022 07:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666620701; cv=none; d=google.com; s=arc-20160816; b=CwxlopDDNH2qJ0ttq6wdIHtuaue8xexzVAwZo5ZBuTaC07USPFu8joOhJBw1uD6BXV 9CStnDX6fcQ24eZMQnLVCGxrQlS96cWAzbYBvAqCiHbWGSf16WhDKh40Gs5U1+6qY8oa waJ9tuc3l5qOQJ4QAboYm8OTaXBmvnpRqKLW5D4529d+QbjXt8wIaDXGCK7AkrNOqh5W NOiaU/6xPU5r2ZmB2QvpDsiPMksDarht7ohIGV2LrJmpBeHQWxLhuc/iBocBZySEt/W/ ucLNp6HKU/7qv/lncu8JYlqJa7deDVlOqLF8z2DFmfUkBIGE5D/Q9hNR226yF4ZA3flH tLuQ== 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=+aXhYVLC9nqCPPfvcbC8UrYRKPKXOJHBeLJuLDwH8RQ=; b=qq84UStvGtMe19vyQ4PINqpFjNqM49RI1LN2CsnX21++uktRtbrRmLiNn1y3VdZNdS tm3P/6ho7y6lNbs4uRvmJJ7I/AO9bPWWZ8mBJPynEXj6EQrKXjzD49jsx1MVIkvzlZss RwGqtuzbCzUF2DXSulK00F0X/dWlPdSNrKy0Wo+unij1vbyMMguPFsXqlIQ4ycjU/Lzr OZBniiJiF0Y6TVTfO7SP+cR6Wf28/jhWLUy/YOYlsyuMpbSokYYB4SMyu4NI/bMCm7PW mDP864s3+80bRarEWgVy+AAElaVJud/Y9uxMa4OZvL1C3Mpof2RU1BDhIzCwDpC0Ih69 C4UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QBCSsuzv; 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 sb11-20020a1709076d8b00b0078d450cbb02si28040819ejc.452.2022.10.24.07.11.16; Mon, 24 Oct 2022 07:11:41 -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=QBCSsuzv; 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 S234066AbiJXMd2 (ORCPT + 99 others); Mon, 24 Oct 2022 08:33:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234086AbiJXM3S (ORCPT ); Mon, 24 Oct 2022 08:29:18 -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 4E76B88A0B; Mon, 24 Oct 2022 05:03:14 -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 988BA612CD; Mon, 24 Oct 2022 11:54:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A70A5C433D6; Mon, 24 Oct 2022 11:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612460; bh=rIg2dTzgThn+dS3MU0ennADYE3Yj0Vem1J2NhhjSi+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QBCSsuzvuNUn4dzI5mrCKWTlcYvruLi863D5KuC+riKBCH11Z5uiinbu9+cUI8Sxg Usj1u74iWy36eNVOedOlo3NKc68kUsY4fs1yFmL0D4vD7uDzB9sDfImiT+i/D1K0XY ppCzLFLZCWa8HfBuRcObX5MhV5tL/gWwSWQQqkTg= 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.14 199/210] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Mon, 24 Oct 2022 13:31:56 +0200 Message-Id: <20221024113003.434828631@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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 e930e2777c87..ae724460c8f2 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -657,7 +657,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); @@ -718,6 +718,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