Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp53660rwi; Sun, 9 Oct 2022 18:20:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bBlYyuEnH4Sauq8BcEdFXrl5SvuQ4RA+RPHTLEvOr3d9CefN/Q4i9PeRoJ8nwW/V7YVRI X-Received: by 2002:a17:902:6bc7:b0:178:8305:392a with SMTP id m7-20020a1709026bc700b001788305392amr16181486plt.39.1665364818072; Sun, 09 Oct 2022 18:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665364818; cv=none; d=google.com; s=arc-20160816; b=hbRyUlTyTCaIyHlYLdUQrbb2GAawC660b++pMHoR7xATffqnhCln9w4L2dV4vit1bf OFDOXDJmi6rTUCr3WshwmLr9F5pkWSImITkiNCBvQey8uL/bX/bePCBO7VpK+Tp0Oqtv vB7guhWHnpcH5gFCcI0CsdT3Dyk++mbebF1s6ScUBilVJmprI/Mc2YC5unmh+2X/lEhl 0YBP2QKhtD+zM0qxTqaDneeqnFzkOBsCDd7mf7pf5WnzQ14DbEaalO7kTYOdsYIlPdKI QVW0eMn89kEjDWU3e1J1HAi0x5krsyjeSYS5qxoE8WSzh4Id51uNNSGmDpzn70MO3UJj AUaQ== 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=0DSIR9VEOb1DVcSp6oJRiRD9c18V5TvwafXardT/Pk4=; b=GMnRtBpURgMu27B2dxRABfc2ofODtg3OlbNSU1oRIdtSV41Uk/6F5O9+qyf9mcY2M5 MCNrznYGU/0xSBzY7UjQ+QoEUAPO5soo2XXQGcD5hDkPr9GkeSuKrq8r7OTLrjLXmWFO mmB6p3Cdaz4IbFpqtaQBYApPDTklphRsH2QA7a2FhDm0kUqeAtopG9yHDVZ8tdjPW226 +RAqvijqdtdiYX1K/jKE3BQ9Ie+2JQzNQEomEA/3iRutFrdTuZ+t0dLUUmR0n8G0yqnZ 8D0hve1+7EBgYLY4WNrUKorHSescVPpF+6wxwp/AOGBZOSJjhSatb4fc+e0EzCwsE4Se 0t2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bpKXRlEw; 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 u32-20020a056a0009a000b005251a2f06bbsi1603491pfg.59.2022.10.09.18.20.06; Sun, 09 Oct 2022 18:20:18 -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=bpKXRlEw; 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 S232190AbiJJAV3 (ORCPT + 99 others); Sun, 9 Oct 2022 20:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232417AbiJJAT7 (ORCPT ); Sun, 9 Oct 2022 20:19:59 -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 E16C211157; Sun, 9 Oct 2022 16:54:29 -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 7014260D17; Sun, 9 Oct 2022 23:54:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0723C43470; Sun, 9 Oct 2022 23:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359668; bh=c0nZxzjfGYuNMGZcJm+WxdQoa6sRFvDG8OlRqmeQcp8=; h=From:To:Cc:Subject:Date:From; b=bpKXRlEwu+80tbfJY86Xl/6YL4vIdrXNn6ZzLa9rbD5jlY11kzW47u0GG64BhHE0y 4LJ18VxGoJdX56p9v/k/H0V6XzI6sorb4MlUBBUFRne4hPqHZ34R71ZSe+yA/TKvS+ EYkTr+QKcjhtVOtfcOWxD1PIfVckVPhMItCO4fc03JZxxEw/yct3Ddq1S/BTAW3fHy WW2InOMvXmeU4ZYXfGEb2WRc2kbJ/f1aIaecH3i1Tzd16XZ6NmpLj9Lq2GH4VoGnmM JiQvUFOdz+CIrFV3F8y323TTGj5B0GlCUmmCe3Sv3Q2ivAnOlreMXP8Icz6/1lXFgx Yq9KncqbgZCpA== 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.15 01/25] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Sun, 9 Oct 2022 19:54:01 -0400 Message-Id: <20221009235426.1231313-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 511fb8dfb4c4..da58230bcb1f 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) { -- 2.35.1