Received: by 2002:a05:622a:251a:b0:39a:b4a2:e86 with SMTP id cm26csp316138qtb; Wed, 19 Oct 2022 02:42:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7O+mWVt3/iNkd0ldxGeQHcPhbW7iWSpsL/mh6fe6LnaqgtNXOlaiDm9KWA/nRs2MdZ8G5z X-Received: by 2002:a17:902:a5c9:b0:182:3c47:6e86 with SMTP id t9-20020a170902a5c900b001823c476e86mr7475961plq.152.1666172565392; Wed, 19 Oct 2022 02:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172565; cv=none; d=google.com; s=arc-20160816; b=O1BnIz/t/GEDrnImgV1qCRMOwRisxpB2gCCiYts3o2mlPPOrEamYhoVYU4crqRoTKE ZB+3RhsVA4e56gCw44kh38PX/Z9NgaLtWJD4Pf4BEifDke90xjN2bw48XrshviP+fL+r hEm952w9/StzCx5VzE/cohwu+DHBVAyPk6ZotwFl2TDYJURw4MVi6PL8WmUH+959gA/K qF5p4Q/l9e+EFVgBqfnmwW++4rQSCy3GCmLhpZMnqBj1uqFm71Abbb/ji8WvSB7iIumb EGtOhpLy6RxyYCDX9t7jYXDUQrU/+JNeCrBmSkoy78vJWX4StxFWUaOLBJmTer7YNylK fNsg== 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=VfWleHouCWquF6bB/zblOph/97E2uV0sGCzBAG5UPGalocQ648OqKRRoXT0rHJugG/ xekdbC+DXI2hBiBHIFQM6lYRCILuMBNXaD9h3IhcIYMIfv2L1r1xPc0hA5iEH4Y1lrmO h5HxRyB0B1ss7hDehWqEYEzEWlzmt9Pjn/7PZyEQfnUhikyIdEPyz9LoS/GCRfvFmXLX 2Vp3QyFxQWTWiIj2eYeDIvGNjWN7BhCqDD3H/c5ctxWm+HMFu6N+2x8uOPMKcyg2YhTb DTPrg72HU+VFZtQhhTShvgjon00sxdHJekb9vyejMiHotlQULvYS9YR9arAT37l0MBgP LSRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hDtaTrfT; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10-20020a170902da8a00b0017f97fe778dsi19896116plx.126.2022.10.19.02.42.32; Wed, 19 Oct 2022 02:42:45 -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=hDtaTrfT; 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 S233424AbiJSJav (ORCPT + 99 others); Wed, 19 Oct 2022 05:30:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231578AbiJSJ1R (ORCPT ); Wed, 19 Oct 2022 05:27:17 -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 24C05E6F58; Wed, 19 Oct 2022 02:12:12 -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 7B66061807; Wed, 19 Oct 2022 09:10:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93925C433D6; Wed, 19 Oct 2022 09:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170631; bh=Pn90kuPbeK/qdV/mITnz331Ur07Ew6mzmpWUpHOoTiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hDtaTrfTX5s5HVvw9yojzucV9cM0XDJ7rwixJu7Fx4NVl2HpkREhdL4SlyLS96iTM p84leraiXaexKpAdhdrNUSOGFWBausy0MJ5ysLt27QTaW3oHearTNIrE+IcLVGKttR g5k+GydlHANQmCplEcVjE4JH34BJC9X8wu+M9HdQ= 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 6.0 728/862] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Wed, 19 Oct 2022 10:33:35 +0200 Message-Id: <20221019083322.097159643@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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) { -- 2.35.1