Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp214690rwi; Wed, 12 Oct 2022 18:57:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6b0o7z1KiAyyxV4Ewhm2N1IPq3yasITNxy9jgFHBQgUP8JLwy9ns+vpbjk2337RlB21d/U X-Received: by 2002:a63:6a06:0:b0:439:cc64:50e6 with SMTP id f6-20020a636a06000000b00439cc6450e6mr27448267pgc.483.1665626221485; Wed, 12 Oct 2022 18:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665626221; cv=none; d=google.com; s=arc-20160816; b=r0ZsUBWLD4XUeMDRGSSwFGbQo46Y8qDlskJcgj37ZFm9IlllBq1tUffwrn0LhJpz4f 5wGsR1098R3et9flqD6PWI5S+F1F+91yNi3ywqSuWbEQCFd6aG9l/mG/5W+25DTl7Xae fB31/gZqnNvXstJsSP6/52B8fK5EE0mOLeEOUN6HdkgkVq+p/2HBKfuXyskEsifDBl63 BshEF6XfIMjfsBf/OFQoj1Y7vlNYzdd1/aRFt0wogrMMuaTy/RJZ9oqAQXZYJ0+3q1WT /ZJTJ6Vf+qSolfBq+tW0Z/Q8Oxca9/lLr+o8YQZD4zIoOol1nXUct1UYTRgiHHULB+6I 2zAA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2hhka6MYWSjThNZLltYM64PUkF3y8FtQdiVdOvjBSwY=; b=T+X5/AKX1uYunS7Zr6D6/LLa2Zh+muA+BUNbJX9NFxhWXsIDKHarxmcbaBEymqu5d/ MFXV+mgAyYgkPatqYVzVPExb71hJPAr3O7/ISgOikScuzAJmlWoOotVf2HVrOAvr01Ll ATA9/ylyKgVdFMRop+zUFWHPqqc0haU1fjm06sltcYplcqCSaZHMJ9phFntS99gnggZO zHmbzbrY/eGRgHykOSONGW8U9KNmAlyXSwNjDp5+A4kSZnnvBXa4z+7XMMvcRJ94uGwC Jc1ipfjKMdg0pqr0rC6WzioV78ZeX3i/mKtH+3GOTdrXr9v5ipbsz/0XisbW5qD+aJK4 aMvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rfPq601w; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020a170903121200b00178bd919d9esi25184603plh.253.2022.10.12.18.56.48; Wed, 12 Oct 2022 18:57:01 -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=@kernel.org header.s=k20201202 header.b=rfPq601w; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229798AbiJMB10 (ORCPT + 99 others); Wed, 12 Oct 2022 21:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbiJMB1Z (ORCPT ); Wed, 12 Oct 2022 21:27:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 717A010A6; Wed, 12 Oct 2022 18:27:24 -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 E2F8D6166F; Thu, 13 Oct 2022 00:22:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79DF0C433D6; Thu, 13 Oct 2022 00:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620562; bh=u6bQ6shkJdvnR5gPrBU77s9UZD5wLmWhUJw1JoEnmAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rfPq601wjIY6JGr5HKQfaBC2nGUZ1GAS5a979+3MtVEv2RwphiIZQx8698MD1rQFg pZVxisx7j7ac6LxzdRSFLHuuC+CRaEztRl6EJvrsx37DMWpYylgNG9/opuV9LZqwVs v6ajkZC+DZroMMLqtFKhbxKPHr7XFyK4DFFe/Vw/W5+xmPimxO7x/VuK8OKbG1SLHH ZyMaufucqNBOElC6ieoRoVZ4RP4zwd8f9111udgBSxgkngZWfVPVF06+T6XOomdbm3 NOYkZbOtEqE8TK/sm5FzGyKg+suhsfMILTuR0506XT+UFH2F0NTiIEUx+ock833STt US/IZWj7DjEqw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jianglei Nie , Mathias Nyman , Greg Kroah-Hartman , Sasha Levin , mathias.nyman@intel.com, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 29/47] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Wed, 12 Oct 2022 20:21:04 -0400 Message-Id: <20221013002124.1894077-29-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 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); -- 2.35.1