From patchwork Mon Oct 24 11:32:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp457507wru; Mon, 24 Oct 2022 06:36:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7YCBwK20xKzBGgnRU2MYCTg2b6v9EcZySEoS/Eo0AoSQkYxc/nEqLkPwObDIxBHX/nDHQS X-Received: by 2002:a17:907:320b:b0:780:280:7b72 with SMTP id xg11-20020a170907320b00b0078002807b72mr28624822ejb.146.1666618567745; Mon, 24 Oct 2022 06:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618567; cv=none; d=google.com; s=arc-20160816; b=vScRlIke1Q0J9a+Iz4h50Y5u5KZVvSb2oNXNbzhmWdKpvdUrZHYb3ZckaN53n0Cvm3 cIHWlXoTmgeHyZeUCc8riebR50vb9O8PWsNLtgrNrY9W9SKbA20KH2YAUGwh+jSZRY6o sm+vDDR1C7mhxq55d3BavTII17lRFpmxla6459TZ7ErD2CL00685BTDChcXiYVV+25bl dXHuY61lFPmpP/v5vsWhT23UQ3MsjoYtjYWspbqJ56j+YPtq7/0JxP+aqCp8OY+mcBbD 6IoI9A5585x+srx81SwdcMYDUao6Cv2sCKCeOptQ3KEfq8A5YUf3QLPTxCrgIhBiLIIf zoAw== 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=+N+0qTYKnkYrxYc/Z4kqH7nNe//IlOfhOFTYwumv7vY=; b=dsbE8s32no4y2HC8K0EUrDkdkKke2hYcwTA9P08R270bewPK2XtU86fbBzYEceFtGD 7DyCQIkihD/Ej/UNNOQMDA+QJxCYF4vCwlNm/ha1dwi6x6kDPhf8EQhOoPP+5v6UAtma eMUJrPoM8IAVqyzgqWowCdFJFAyE0ymFK5sdGSiQN5msdh2fzsmY/1NlzPnuhYSVfZ5O B/cGQBtvpBzJCJB37QBLKLi79tKqO8/wMSqUh7IaOCBfeMhpx0+9B5XhkLp+3Y+HNMS/ xxUe9mhSJtIwei86zNMOu/jxlR4N+bWCFBnm95VSPfv5HyrgTy0BLJHDo5MOI5+NqNsT pF/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L0eFR6gg; 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 i10-20020a1709064fca00b0078261e73261si33314328ejw.567.2022.10.24.06.35.27; Mon, 24 Oct 2022 06:36:07 -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=L0eFR6gg; 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 S231916AbiJXNV4 (ORCPT + 99 others); Mon, 24 Oct 2022 09:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236461AbiJXNUb (ORCPT ); Mon, 24 Oct 2022 09:20:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6C6B87092; Mon, 24 Oct 2022 05:29:15 -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 A68C4612FF; Mon, 24 Oct 2022 12:15:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3F94C433C1; Mon, 24 Oct 2022 12:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613703; bh=d7cJU7spTHf6ztf1HVsTpE8ruxo7YQj2hlsGHeF61lc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0eFR6ggWZL+NVYkI+cKtBU13Je3K3dut6Oul3is1Nmb3SOfXcbV+mYxUU62Z/UPU oMWda3iaPF/tBOe4xkpczPjAdg1EZOnfftmr+fE3PJyMcUVOnOWZ7powlmr+iRzjH2 EI3v5glZlBR22PX2+qJHFcTJChr2A6/BvzJ9hS0o= 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.4 238/255] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Mon, 24 Oct 2022 13:32:28 +0200 Message-Id: <20221024113011.121916223@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747576231396286961?= X-GMAIL-MSGID: =?utf-8?q?1747576231396286961?= 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 ef23a69c6553..6125a98ffbf5 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);