From patchwork Mon Oct 24 11:34:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp554228wru; Mon, 24 Oct 2022 09:56:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Zp/Pj8LLOkBCsuWu4M1/P2BOs7UoXI2eInCydqEc4uwSodijERwORzDj5SuskFdph9WQT X-Received: by 2002:a17:90b:4a84:b0:20a:f497:6f5d with SMTP id lp4-20020a17090b4a8400b0020af4976f5dmr38694231pjb.213.1666630595354; Mon, 24 Oct 2022 09:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630595; cv=none; d=google.com; s=arc-20160816; b=YguumRyja73KBRiNTqNKVKl6RvQ/G+KKdcVLpXqqTNJWaRhkCGHQnPznwDvxiCZV3B 7kPBD1kWTvL02I5fmaFFXUzEGdr+JwHg5Ck99HIIVLvxW+ayQ8eqmBZhzetUXz1WGRcM G7azF151yN6wN8OtwRAl2+xM5YE6ChtOLjAyG/bvUuN41drjWeUkvibfsdmY8q/tpunQ Wcbbzj3twhiJoTdYs+kbcN+NVmeXNnCujk7N0IFghD35dG1N+5A/3usA1w9Lwl4u810u U7yNPW46UuM8CN0tXyRzoHaYFy0xsfpAX95xjG73XQcqs4wOFEFZi5fCuHLcJLkQR2qS fQew== 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=2hhka6MYWSjThNZLltYM64PUkF3y8FtQdiVdOvjBSwY=; b=pBauMIuVPUoU2HAYRSS2YYedJekymCW8mhHDsfu3+yRtDrijv4RC4F0DSL+ygE2aJx vXME45tKbQJQ/SL69y2Oc1Ax0gFUf8n3Rq3kY6L+OAOAuSXVKlbYhTff/fQHRa52G859 Jrt5DMAt53BvPOf7Qxd26b6Jrt7UJpyMYDYkYAP3ZcvbCjx4ZC+jX8UFnmteDnBx0ePk jUmmodxJw03mKNK4qUBxP3iEhZJ2Jxq0/y5ynMpLnEwPAo+QDRhxBFBODNBM+lhu5kl3 yhAXx5A+psDPa0I93wNuN9zwA/WvWZQTax3JMvAbKaBUoUK2NNrRm+/4B1/FaLQnTewi LgxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cDw50TlS; 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 b6-20020a170902d50600b00172c1c6abc1si16349plg.172.2022.10.24.09.56.17; Mon, 24 Oct 2022 09:56:35 -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=cDw50TlS; 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 S234539AbiJXQud (ORCPT + 99 others); Mon, 24 Oct 2022 12:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234842AbiJXQrP (ORCPT ); Mon, 24 Oct 2022 12:47:15 -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 04AAB1C2F04; Mon, 24 Oct 2022 08:31:37 -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 85143B81A24; Mon, 24 Oct 2022 12:56:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB0AFC433D7; Mon, 24 Oct 2022 12:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666616159; bh=u6bQ6shkJdvnR5gPrBU77s9UZD5wLmWhUJw1JoEnmAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDw50TlSwvlHXOXqepkPhAMXd5TML0Scx0eUlbFjIijK0GO/zn51ONZ/PX99Cy937 8oIldKP9a47rW9lSyhdDDUxkQmve1DLFV7e/R9BBnXE+5YmpFFTNz7M25mkqkfJyAG +AizjrbhX/imCX0DquDrOyuof/c4PQ8dogcCa01s= 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.15 496/530] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Mon, 24 Oct 2022 13:34:00 +0200 Message-Id: <20221024113107.500189062@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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?1747588843391137536?= X-GMAIL-MSGID: =?utf-8?q?1747588843391137536?= 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 b398d3fdabf6..02cd4d7c3e7e 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -642,7 +642,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); @@ -703,6 +703,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);