From patchwork Sat Oct 22 07:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1156628wrr; Sat, 22 Oct 2022 04:15:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55e/QMMAkl5J5Qy0OnyKLBbdUgNbVut9uTF2iEH/suXmyJNeiz7s9PhQVSqkCe/hn3DlyV X-Received: by 2002:a05:6402:8cc:b0:45c:a5c9:c0a with SMTP id d12-20020a05640208cc00b0045ca5c90c0amr21541252edz.135.1666437318750; Sat, 22 Oct 2022 04:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666437318; cv=none; d=google.com; s=arc-20160816; b=pkDsMRxnbkXohxTOAEdqBNFqFapmHnjVvolP21dQsPmIf69sVlNpA/s1UgIaf7i8n/ +ycshj9HoKdPNeu+8So40k0nGJ1mLQZ83pSmLa9ckhdMowDPjvC08/AjEWYiScgK4CpT /SD4tS61ZsateviRZYeEiddZXDApoypcNqNq+jw/DU21CvsBpiJOEvfW8iLAC8npoWdG UJLZfxgDKzhNRyzAGSlv7oF0IDlAragFrhpXU2jdgV8P6HMc+ebUSj0UjLw2G9MR6rIx Q9p+p/ufH7jUu5bHlOqe4sISQOP2ZyBhqNamoNI3km2wMEF5qPDIep1b+5kKXsIYtonU 5bLg== 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=uyr7uFQITT7cUiRiakbXxfBQAjTfnvRmynMmmSOTFiU=; b=Wv2mYRiSM3W2b5d1Vq2voMm9ZNSN9CJ6JVjSRhvYEIPpNpHCY3UjeUuW6zC9c1Kpw2 yuLT0kh9zSo66PnRGZ+CqoB1d88kJlNeXDsckQLMPj9BqA/taqOKm4hkw+tkzcz/UEVS pRvgDma39uIZjwAB0pAonCWeQtvEj35onfO1nhpHe9zkGizKw6QdQsxQnSlugvQui203 5cmFY959cKV0b6cyZznYHJnKS2ylC68+DunkaX4QQRmcyUSyrbaE1qN7C8vavC9lULdK 6NoKpYkn2ewFf2BDjMCJTdAKRvVEKvsFrAMQSiXkyB7tym8wYNaWiIG6O41YPSNLLA49 0mQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L95dKkbD; 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 n1-20020a17090625c100b007417c6edb0asi19053495ejb.402.2022.10.22.04.14.52; Sat, 22 Oct 2022 04:15:18 -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=L95dKkbD; 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 S230345AbiJVLO0 (ORCPT + 99 others); Sat, 22 Oct 2022 07:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbiJVLOH (ORCPT ); Sat, 22 Oct 2022 07:14:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C28502F79A2; Sat, 22 Oct 2022 03:36:12 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2E4AFB80E4D; Sat, 22 Oct 2022 08:06:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 783D4C433D6; Sat, 22 Oct 2022 08:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425970; bh=QmYPBt2tuHklhPv5OYIPoGItdJBIj0Kc3kuoPwcl3Q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L95dKkbDzvTH9EkX7y3JkUOjvvEZAF+1745g/LEpKe9IkcNtFq+k5xpjX8AwPJL3S YjSr7RyB0z142+xs6IoW5c2xjePx5tXWG+DD6kdQSvqloxOadGVP06Y4dUu3iMB1Vh WUAleLCf3C3JGz8ku3FlmgXzlKfdPuNBQxrj47pY= 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 5.19 675/717] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Sat, 22 Oct 2022 09:29:14 +0200 Message-Id: <20221022072528.297892220@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747386178208357563?= X-GMAIL-MSGID: =?utf-8?q?1747386178208357563?= 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);