From patchwork Mon Oct 24 11:32:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp544195wru; Mon, 24 Oct 2022 09:31:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7IqeKmmZ16PLwEfbLIoC7jFKS/+3aLFHZ8OV+SYvmdHKYrAFBpbuWIig/t1Fp9TkhYMmQE X-Received: by 2002:a17:907:320c:b0:77b:6f08:9870 with SMTP id xg12-20020a170907320c00b0077b6f089870mr28428580ejb.249.1666629093817; Mon, 24 Oct 2022 09:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666629093; cv=none; d=google.com; s=arc-20160816; b=W4xoPka6J4R36ze5exrC6+pnRBBjH/KewS1Th2X3SsqsjKwse7Wc+LSOcgmxoFC1VB utJ/dOnk0Hsd+HVAWDlPZlyM494TGp7QMSltheaFQBPV+HXz6rFPXNh+9ZlWPCF+0yWV IZI/yQFPYOA+nXV/WWTHuVt3DE6aaQw54YgwkIb59z5SQh9bvPwrkOs+k/Y4Vf9Ii5GK XMfwEzymL+zSjbj19KpxyI7XtKmk6RsZ8D5vXls7R4vXrEJcQ5yaDhtRb2+v3rlU+kP6 ZFWA9G/GHNiyyrH1YJ63Gijb9s/0bbkMP51TX63CbNEnykWB4J3KJOxhQFDeadcCcWsM Qovw== 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=q+CBtv6NcSQDVsxrogK9hL4Zb85iewuSYeYXJMt2AW4=; b=Hn7MK9FmftBRWyH2xzmmGdJn3TKh7aDvW73lEYjXtB8p/BQ2z3xKiR70HKjJITlvf+ bht1vC/lPEjaaXnV7N30943gqztY5sI2jzaY10OfHyffiWuYPrGQLrEzbDlpwQu655x6 drR86ChtBUpoainEratHZ1OtVURgm1LGiRDnW//gly7NG5GdtZB7Crb8IRNsUWUNnbR7 zbwwi9Tawr8yMaL6XoYoBtH2yiOyD/z4qViGHJm2gDTqtwlEwUY6/gq6NUw0M2CTwZS/ nz3ckz/fZwt+pa28CBR0QtDI2fAZkysRP8yBlqf8TtlaKTCePndiKMBurmJ7odDyvCb9 CAng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v9SFwBsD; 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 dd21-20020a1709069b9500b00781a32fd847si158621ejc.917.2022.10.24.09.31.09; Mon, 24 Oct 2022 09:31:33 -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=v9SFwBsD; 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 S232346AbiJXQQx (ORCPT + 99 others); Mon, 24 Oct 2022 12:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234708AbiJXQPH (ORCPT ); Mon, 24 Oct 2022 12:15:07 -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 8CB741839D; Mon, 24 Oct 2022 08:02:49 -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 9D04FB8160E; Mon, 24 Oct 2022 12:13:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED952C433C1; Mon, 24 Oct 2022 12:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613632; bh=0vd4xZ6Gi6rBTeetuM7DB7G4THSGHgYqtg00cEzXFEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v9SFwBsD28tk6/fDxDja7+4CTOEhzoa1wJv2DZKuFVSnPcMb6weN0ertFl1k0WsOT RKh46r7bSDBf9/QSsx6flenwFwzkbYJmS69HW0Wr/TVsvH+0m8eu1SWuw/uFxnm8r8 CTCGmCgn2mgpjeIiO9n7jx2ZM0NggECt9nZslpdw= 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.4 210/255] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Mon, 24 Oct 2022 13:32:00 +0200 Message-Id: <20221024113010.021220312@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747587268227967995?= X-GMAIL-MSGID: =?utf-8?q?1747587268227967995?= 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) {