From patchwork Mon Oct 24 11:32:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp460902wru; Mon, 24 Oct 2022 06:42:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4M+IVNgVcxig7ePrMAxEm2F1nlEjTbIGTvZGo5FSUCrQDWrElkDRwTNVgBb30kz+5Sa4fn X-Received: by 2002:a05:6a00:1505:b0:56b:6d78:3304 with SMTP id q5-20020a056a00150500b0056b6d783304mr14491315pfu.44.1666618962467; Mon, 24 Oct 2022 06:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618962; cv=none; d=google.com; s=arc-20160816; b=EwIWpO8GDpg6fyIXX7RWoi10yPta9vfrir/C1AaeIzN5xMtudpt5lOBqmkqhkKB9Pp TnqxuWyR017M9oG8X3pX/ISFoKCiFFi4yHzsWL2JkeMnaeBtMmj/6mgPwhUwAPbZ2nXe 9iw3SfAjK8nwBEOjrpgOz0iI2rwuIR4fzHyRQpyD979iibIkqvcERm7OIShBJR2dHACs EUzQHoq17gXSF7uYnhubjIe28s+FglgR5dp09H6xUg0vzCMYk2N0wHfb0l7FrJYtfBYi wpiP4B8d8KxoqFVEXfOfsonoPcoGMV9ZivNn1y/cUtx+pL8lM9GMgStKZIljE2hqBljo cPxA== 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=8KGx8gzHH05/DhXjVKcnsb/CjFEqOl9FTlG2T+IUcdg=; b=UeaBs8JxRFJ7LwCnib9LXc4zPo9vH4XMvaKcQE1QwqvniQpLCE2WNIw9x4cfgYonEA 1GuQSCNtJz9Jfv2g7xuYW+MNPgrlasP5IJ2SQSN9xFC1oPQSSNj5mJufcSe5qq+Uc6RL 48zfUG9wF34Y7UVAtfJuGRS2x/Uxz+TImvMiQxHjOjLsW0MlT6e9kSGjB4OTB57krIVZ ZB9IQGWnQnrRTes6Y8aVCx9/CLVTJvrRwZpY8UlkxBAu5d9v4rdRD2NuJ7NQX7t8KkHv YfsbThJ/L+qbuXjBePvK6hTS5yAHQb3tm3S7cE5Wat2O4g91zEnetu4AHoqVXrNNa4iq AxTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wGZqH7xd; 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 j3-20020a170903028300b0017d2311af5dsi9172006plr.69.2022.10.24.06.42.26; Mon, 24 Oct 2022 06:42:42 -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=wGZqH7xd; 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 S235989AbiJXNhU (ORCPT + 99 others); Mon, 24 Oct 2022 09:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbiJXNcX (ORCPT ); Mon, 24 Oct 2022 09:32:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB7DA6302; Mon, 24 Oct 2022 05:34:39 -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 D7C2B6132D; Mon, 24 Oct 2022 12:32:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAC23C433D7; Mon, 24 Oct 2022 12:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614720; bh=Wnt1e56a265JEkQ4o4iV0N8uiQJ92I/u9tYnSpq0WhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wGZqH7xdYHGJcqSbv199Ar80ARgfJtBcBYU8TxhMZ46PA/dkqloKg1PLQD7e2IMaf ZZgv5okNXuDhQNDhuu8/NRZwUgYRimkTmgFKi6FoMGrfrku9q8M9yPJDB4OOvZCsJ9 bmvpWbLpcl9n+9pLAJGhJYTpYTbvG+S09Lx6/WbE= 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.10 368/390] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Mon, 24 Oct 2022 13:32:45 +0200 Message-Id: <20221024113038.675947689@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747576645318205496?= X-GMAIL-MSGID: =?utf-8?q?1747576645318205496?= 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 024e8911df34..1fba5605a88e 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -659,7 +659,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); @@ -720,6 +720,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);