Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp15423rwi; Sun, 9 Oct 2022 17:31:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM66/2rk4cO2yoX9PP/urfU0X4Kda1ogMbkPUWkVPCjaQ5Cb9w7uVnio3LXo2O9gzgRNDsBR X-Received: by 2002:a17:907:d90:b0:78d:48b1:496d with SMTP id go16-20020a1709070d9000b0078d48b1496dmr12885281ejc.665.1665361904443; Sun, 09 Oct 2022 17:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665361904; cv=none; d=google.com; s=arc-20160816; b=uDJWxUqwve9VQutyOh0Rz++5HmIDMdy83fckPNauL1qqOMqiP5m9tWCtru1Hu18+EL eQ/iPFSkggbQ+nNO6Sdw00mSxP3Jx9lNydKrZj2c8/QwIDSKnZ5l4eUd+ZL1oFgD08gm ZhC1vzTSHt3uC4olOHdZ2l3Q/zvYfPCMwpJy4kCodIq2ErKYrVL6rVX5p4KJis+HwgPR YAzMQcmWG7JOG1J7PiXX+HRr7q22921YaAzVGIFm8moT1rNTgdySV2qFnmaCfx0l5RL0 kEw3lIrH/osCsrBuGKJ6raYe8DG7l06GGt3DN9hMuybz5w5+O50Xt+jS6Kgb4X14evss R29g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=q+CBtv6NcSQDVsxrogK9hL4Zb85iewuSYeYXJMt2AW4=; b=DH39m1MCItRczZusV5JhKrYgBdjzNEQvhMPEMHxW49PPfQHkh2sNkGC4lBUVZvJsh1 CQ0V/Ox5n0QnY+Z74LIAhHKFmFkbp0++JA8OS3zX/QkT1vzkR3bgdclf/bZku3h74bt/ Oqer+HLgmBR8Dxk65mK0GB9Fw9WfBwjgjvCUU3qTPmEoetLyrod3RUu8t+NBolYmi38e 1sOYxWNkhieTrx5I9oMg4wwxsdUx96xgQXgJBdNM4ek16KEupk2kcZbsohWMt059rCuD TvPYWJNKy6jvZv9TTygu/+bbbeaS1cQShI8N5mnYm/obdAtwZRD3mCzahz/hO7T1hUAU 3f9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="IBN1Z/dF"; 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 ho36-20020a1709070ea400b00787d08d5ff4si10746800ejc.695.2022.10.09.17.31.17; Sun, 09 Oct 2022 17:31:44 -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="IBN1Z/dF"; 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 S232942AbiJJA1l (ORCPT + 99 others); Sun, 9 Oct 2022 20:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232873AbiJJAXt (ORCPT ); Sun, 9 Oct 2022 20:23:49 -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 2A52A237F5; Sun, 9 Oct 2022 16:57:16 -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 D5ABFB80C74; Sun, 9 Oct 2022 23:57:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DE9DC433C1; Sun, 9 Oct 2022 23:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359833; bh=0vd4xZ6Gi6rBTeetuM7DB7G4THSGHgYqtg00cEzXFEk=; h=From:To:Cc:Subject:Date:From; b=IBN1Z/dFTVyOhd35I8DjJLBu2pp27XfEmHT+GGobPtfwNZy+vLyjP5XQ0oMcqwy1M Ttj22UPVdbeqegtFWMpeLktRbZg+v1PjO+aKoOrcpOF9EiMk5Rux9R2u6OlR3++UjO BDubuNUz9cdlruMbyvdbl6czTeUGhZKXizizoxAuj3/+HOcH+2kwR7DrO/slEV4xwH lWBfqXzbUJfoIOh2FH3g9dJc44p1gf2SAn0xNzivtKBAntg6O80HrquK/iTRbQaRYP Ys3QmqDmXRSkHx4jf2ltRsat4cZmcUiqczC4TzoaroeUmNjiQXkGxnBQvjJeYioELo A8abNsrz2tnMQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jianglei Nie , Lyude Paul , Sasha Levin , bskeggs@redhat.com, kherbst@redhat.com, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.4 01/14] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Sun, 9 Oct 2022 19:56:57 -0400 Message-Id: <20221009235710.1231937-1-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 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 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 f7603be569fc..9f9c70734180 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -276,8 +276,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 flags, 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) { -- 2.35.1