Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7312179rwi; Mon, 24 Oct 2022 12:46:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52ZOwykT0CiYvz9jJQ+nujYnSIXFram5yeWvXu/+hSNG3Tr3MAGyd5YIC7KcPXJSYQVHsv X-Received: by 2002:a17:906:9b93:b0:78d:eb36:1ce7 with SMTP id dd19-20020a1709069b9300b0078deb361ce7mr29460367ejc.621.1666640818026; Mon, 24 Oct 2022 12:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666640818; cv=none; d=google.com; s=arc-20160816; b=sGDQp9ujNfogSRvJEaQey+KGGFKRuKr49eBlPpoyYSHmD1pMRYOI7Uk1VQO0QZQqyd 48amO+mD0EFZehegH8lxcA6et/72m+v+B6tCjqmkW4dXwFQvzUxc2nS8jY1YByzvlMVm M092ty6Fa+6AxZu3nQqX32Dh5wHcRS6kB0A9PROEnwa/bsad/l2EHkmJoh+n/qMSsqQD OXm66TTrVVZOSQ8Bhjd7bCyBPD6ZVVW7kA7vBIeDoqo8ut6bpCldUfpsiwjlnEPNtpNE MG6iTR4StbQUxtHZYVyT9WbyMGoC8/SJoDxKF6AtpR5a5uGpI00lVjVYSbxWfo0TGosR yeyQ== 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=0DSIR9VEOb1DVcSp6oJRiRD9c18V5TvwafXardT/Pk4=; b=oIzHtYReAikxrmFZ+yB9tPKLIFji5jgRzY0rXwX5Jhx/tPBxbwFOdvr213S/2cyAxb EUMLY+/KfCptf7E0+Lh3KqaeRBE59/A8zhcCd5Jn4nGTDK2yt4MQsjj0bUQDZJUCFlJL DD05ru0w1uaAACJ7/7Zkwitak+QjyHGIwt8CrVFiOXmVFbUMO2Bc6zJVw+NT6BJ3ZAlG VJCNaxKrmmv7hFTiuAcCeH11bGIaoj6/pRJoT01E6x/iSzsBo7dbHzMZ4LL1Xd76lZzR OfkBUxu+mMQwswzb+7aQAl+HZ/cYVaXUOtIxwuShQUQBx9xf7wsrSDTAT1miwKxuCGy+ MI5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qfbhi4OO; 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 l22-20020aa7c3d6000000b00458e87a1d83si539143edr.54.2022.10.24.12.46.29; Mon, 24 Oct 2022 12:46:58 -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=Qfbhi4OO; 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 S231219AbiJXTnK (ORCPT + 99 others); Mon, 24 Oct 2022 15:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233520AbiJXTlg (ORCPT ); Mon, 24 Oct 2022 15:41:36 -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 4B0F0BE15; Mon, 24 Oct 2022 11:11:28 -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 EEDCDB81889; Mon, 24 Oct 2022 12:52:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45F62C433D6; Mon, 24 Oct 2022 12:52:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615944; bh=c0nZxzjfGYuNMGZcJm+WxdQoa6sRFvDG8OlRqmeQcp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qfbhi4OOn8Ix7WGb+zc5kdearL4gghg2jdt7+D7HxJZKmfs8ppZXdnBUZrVhta1D2 rT/pFQ4cqMHCMgpTRqxpJFu7Lbbp41Btd9brExW8RKdPbCpm191JJ6WfVGyV5ZMrpR E0fpR2SjrgI5OPNIkiQzqhl8zXt7nU1fckHe0v/c= 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.15 443/530] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Mon, 24 Oct 2022 13:33:07 +0200 Message-Id: <20221024113105.105974628@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@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.6 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