Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7278851rwi; Mon, 24 Oct 2022 12:16:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4f0pqB26v3ZOci0D2LzqE0kcPdUX4deIv3cd0VOeyuSpIXnptX3xtBgohjin74cFhURfcL X-Received: by 2002:a17:902:b281:b0:186:9596:742f with SMTP id u1-20020a170902b28100b001869596742fmr11232256plr.49.1666638993782; Mon, 24 Oct 2022 12:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638993; cv=none; d=google.com; s=arc-20160816; b=fDSMDqmHhWBZxGD9MjepEIbaSrRAYt4IXJ7puXUwXZgahbG9U/f67SYFYFA2muRk7G o3Sqfd8KNlhktURO6RKbHfZZJz5nGuJjhZqhq1HcFuEN7cBgHcseJ1Gx/EIelq+4RAS6 kpJJUsKRiO66MTaxZevV1fNN9AbkpJrtLkK1jrkHSdnCuz3WHUqJsEBh5s+BUVQH7XF3 EL52c3Z3c9Cq6LZNbPSjgbnt6SgK+7MyYPOUY2MeJedktv7x8w4DlDTM+pB8rThwkaES 2+cV0FoRCM63Wx/Pr0oJYvavqLtW2bEddCYqEXN+Ua4c3qnpIiAleJGqirbFf6foKvl6 fl+A== 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=GK0p8PSDvaT638jEruoYNUEYVj7GvKfWplXLw7oisLU=; b=zkBVdtgQ1mQI+ySWgjxEpL84JqWgSKA+/bIhI84xQoxfs23IGwfEVAvKqWenb2X6Gt 3ZNzjqhP1/dyKivqnut5Y0KRl9JEF7kMZf9Z12k+GI6kJdpXxZE5AuBU3m8l/pWUWeW2 kcAx23byjvpl5wxZ3Ano/uF4yEuUY8hFRrHrCBzyVdSULJ8/0FA18q7wF/V9DOs9xBgh dVQ8BFGvaZvhiohxU14FNwmE7x52xNejspu2Z3zhxlCacv4skFxF8IuXl4/qlSmBG5uM ZtEQRH4o79sjifqhzNq2J4UMPECYqd7dww8mtGbiys+5iBS4DRm5cWsf4PKxxk2qQkln lyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KM4FLZvh; 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 n5-20020a1709026a8500b001869e6efb8asi334987plk.59.2022.10.24.12.16.21; Mon, 24 Oct 2022 12:16:33 -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=KM4FLZvh; 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 S231901AbiJXTK1 (ORCPT + 99 others); Mon, 24 Oct 2022 15:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231915AbiJXTJx (ORCPT ); Mon, 24 Oct 2022 15:09:53 -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 1BE4AEE01; Mon, 24 Oct 2022 10:49: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 ams.source.kernel.org (Postfix) with ESMTPS id B2606B8118A; Mon, 24 Oct 2022 12:04:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1105AC433C1; Mon, 24 Oct 2022 12:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613043; bh=BN27ZtVKkJ3LHKlBDcv2Kvb9Ok07kbOCpdjRtHGbjVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KM4FLZvhVLo/SRcuGafTh3rI7bTvLsplNhDff9uj4qdboQQnnVMdxPsqZzKxk+vad lkXnD1SZtJ7ANlhuvgO2Fu4S48abAluJtQ0E1RMnI3INq5UySeJGecGHcbFq0MuhsH SGGv1Q7PjDUw1dP7eU6yjh57fCQ6f+GpTP629UW8= 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.19 215/229] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Mon, 24 Oct 2022 13:32:14 +0200 Message-Id: <20221024113006.173383163@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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 798823ce2b34..7de21722d455 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -650,7 +650,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); @@ -711,6 +711,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