From patchwork Mon Oct 24 11:32: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: 9960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp609552wru; Mon, 24 Oct 2022 12:11:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DG62Qrn5gYl1PsZNmDWI4KcXDroardISWs48qz3geibyJ+svzICsiPiGaAWrl5ZjoVNw9 X-Received: by 2002:aa7:9f0c:0:b0:56b:c0a0:6ab with SMTP id g12-20020aa79f0c000000b0056bc0a006abmr2518235pfr.7.1666638672197; Mon, 24 Oct 2022 12:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666638672; cv=none; d=google.com; s=arc-20160816; b=nHggRrv8TAQQsaEQsSaH6bkR88Y1oP2MaGpPpvAK30KdtBZrER1bNPmLQ0HOrkYzKD xnKJYKeQboYxfR9cG223Jdo5IlTZak/eXSZDZsXga7DrjNm9A8r5xfJg4OwjJzowXOFo QVtAnmoYUKhhKg9hibkp0kHgyzGzLrzm6uUrkCmAwodcOVHG87gKQt+od6m9aNp3PL2A WJXXqywKZiouMVxOqWBOXLux/XrW/BFgOlTP4gOmnKyTvVcNN/W9bg0Yx80n9GORhEEr oi5kxon2f5QMdUOIEDDyA+rKsq/cgZorZ6lo1eIT+6fLktDa92MGe4E2ZqOQPm4cttW3 2bjA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a6541c8000000b004554963e1d2si339854pgq.172.2022.10.24.12.10.57; Mon, 24 Oct 2022 12:11:12 -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 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?1747597312233207646?= X-GMAIL-MSGID: =?utf-8?q?1747597312233207646?= 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);