From patchwork Mon Oct 24 11:31:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp431540wru; Mon, 24 Oct 2022 05:44:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67QrRB97S5KmG4dzEQrTSbNcVJ7TKd7Jl/fLi+jSkwDmOciOA3sa7213vtyZ8vsiGXWsem X-Received: by 2002:a63:6b09:0:b0:453:88a9:1d18 with SMTP id g9-20020a636b09000000b0045388a91d18mr27754421pgc.41.1666615448543; Mon, 24 Oct 2022 05:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615448; cv=none; d=google.com; s=arc-20160816; b=yl00XNVPWaHpSYHIu7T4uQVI4r5l2vTM28jAA/bfKQ3v7PWIttrx7BcjKJcTHLHAiD x9SoOBrt6q0wbnA7Jn98w/yWElTxXOXSh6eL3NtobJT0QJXA2QUp3rot373YBPpz1MCa zxKIQ1cnzLAnMezNdsvmG0bN0SQFhGbZSdC89QWmRVN9Lf30gM7yyWzFQTqOb80LaSFz 77AkQeb3Z2pMPh7zp/fi2q2P6psR49KkoPst+cNbxuW3t0XnMh/NJXt0XXtZFnPR+P53 uXW3bOiIwIl/OBDQ3JQSI70J9+Yg7z63dP5EGnhy//5JcevQluUfn0xjf0DycrTFa459 Spcg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a17090a784700b00212eb5485afsi6430274pjl.77.2022.10.24.05.43.55; Mon, 24 Oct 2022 05:44:08 -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 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?1747572960353214333?= X-GMAIL-MSGID: =?utf-8?q?1747572960353214333?= 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);