From patchwork Sat Oct 22 07:27:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1107658wrr; Sat, 22 Oct 2022 01:41:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jVv2b+j5ivJrXYJuDkWGVXNKG9K6MduTPOR5wMm60qznVdDrXamvY2XOV7fiejqXspf8M X-Received: by 2002:a17:906:8a58:b0:7a1:1c25:3e82 with SMTP id gx24-20020a1709068a5800b007a11c253e82mr1654135ejc.185.1666428097706; Sat, 22 Oct 2022 01:41:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428097; cv=none; d=google.com; s=arc-20160816; b=ltYFzKdIGCiZTVyoXCZ5NAyYMgCRP7Q6cRcMoi5esR4KaXGe57XBHmTUiUyJTCjFqz MzNI0+0srXrmWedWamMpWOgyDqH92WiILGKb5Iz3bVIzf4aFwfIFO2o2r324w6B7Z60Q 18JzJUXCHLrIz2FkKZcAsa4NyTM/KSm3H3j0woAQZIeL0OCcIPSE4v8gXYNltEnlOar+ wlR5YRy6+wWKwfNNr0vr4weRO9BCAtbbv9ns7f39yG+iS563rJ0TrUKs3WH/sNvgTeNk K3uVGoZvn/g5PEQmarc9N9pQ0eL4pRSaa/9bYIDSynspNspAfvu647ZsLQEGyO4ZE8sg 3t9g== 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=cm2Cbrlx9CimVZApLwOlsEj0o1/rhbQ4NGL5EXn5/m8=; b=LbqZoZfwp0YLtbySEU2EiPXRmbjMKen9iUZ+E1XrE9aEqfYVF9iTsf5WP8xnlfR1iN iRwUg9OTgxfaWI1yf2nzfPo1ClkfN/JvIcmMPSzszGKnkqBnSvWT9jYqxGFpQFx//uw/ Z7Thl22VjSFEJ4AUxyklobExXYSurSHglOilkEublPNNV1rs1YpqD+73PtIZ/lXsVN6m V7/nrANn3uEuXEQ5Ay+5wxMiYW583TOSdbuuegrpfGTVRO9h6Hl55wciWPPX0Pkq6PmD WxXPYRgWH6ogv07v7uLTJKmQcTt7u6TniFJ+qu9BBgTYycOkEF4rF7U5orozFUzOBlq1 pccg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Iia/AAgF"; 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 q14-20020a056402040e00b0045d8bff7b1asi13185861edv.403.2022.10.22.01.41.11; Sat, 22 Oct 2022 01:41:37 -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="Iia/AAgF"; 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 S234521AbiJVIjE (ORCPT + 99 others); Sat, 22 Oct 2022 04:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234391AbiJVIfO (ORCPT ); Sat, 22 Oct 2022 04:35:14 -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 4203636BF2; Sat, 22 Oct 2022 01:04:32 -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 3AEA260ADC; Sat, 22 Oct 2022 08:02:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BB9BC433D6; Sat, 22 Oct 2022 08:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425731; bh=Pn90kuPbeK/qdV/mITnz331Ur07Ew6mzmpWUpHOoTiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iia/AAgFpd8MOGLxdTYvP/OMRTIo7wwXmCiP7fR10v5J+MjOfb628CqCRUcvntcjv g1yQXuH1nlsSUfbMHHqushTfE+/iq2wWkISSWokDMMv8NGRicuv4Ofw5OxEHXyD0W2 8kHSSUuLVZbNxQMnTrW+m/QrbarZWgOnXSIT6RtU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , Lyude Paul , Sasha Levin Subject: [PATCH 5.19 598/717] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Sat, 22 Oct 2022 09:27:57 +0200 Message-Id: <20221022072524.907495788@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747376509291157190?= X-GMAIL-MSGID: =?utf-8?q?1747376509291157190?= From: Jianglei Nie [ Upstream commit 6dc548745d5b5102e3c53dc5097296ac270b6c69 ] nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc(). When some error occurs, "nvbo" should be released. But when WARN_ON(pi < 0)) equals true, the function return ERR_PTR without releasing the "nvbo", which will lead to a memory leak. We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true. Signed-off-by: Jianglei Nie Signed-off-by: Lyude Paul Reviewed-by: Lyude Paul Link: https://patchwork.freedesktop.org/patch/msgid/20220705094306.2244103-1-niejianglei2021@163.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nouveau_bo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index e29175e4b44c..07a327ad5e2a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -281,8 +281,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain, break; } - if (WARN_ON(pi < 0)) + if (WARN_ON(pi < 0)) { + kfree(nvbo); return ERR_PTR(-EINVAL); + } /* Disable compression if suitable settings couldn't be found. */ if (nvbo->comp && !vmm->page[pi].comp) {