Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1040925imw; Tue, 5 Jul 2022 02:44:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tQfjJvj1v05NsUxJNKNGIoO/ApekU2Eb50HN8TzQIYM4cIqrs17aFu4uWOp9AVOg8K6/nk X-Received: by 2002:a17:90b:2249:b0:1ef:2097:8448 with SMTP id hk9-20020a17090b224900b001ef20978448mr40219325pjb.97.1657014264107; Tue, 05 Jul 2022 02:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657014264; cv=none; d=google.com; s=arc-20160816; b=H68yIZbp7gsJ9EPj8q1uYWE5xjpVKhZgTcKDr4P2s3Vo6bQjP9CCN9O5fEss0XYi1A zvzcskoW8sA3Y6wsCWMMSPBEycc0FkIUe3xLKFrq6uM5FHSIc8pEzhh19L54JNspGX2j z1Y6hZimmr6GOjHzSKcSF3hdJFZCxOXfdLa5og59EErsulQnRBOtLFVMCO6g9d6FoF4y Z6Z8WOdSuGfGkoHb4PGTfTTVd8sRU+6gaiU/GzyPpQD12g8IoT2fimATa9cfxBcqrR4M nmmd0ZGXHPbvCrI1hbyeknRGZWouphUJ69izHdwI7nf3s+n+pra7sx1NqXEfdIsa5udo +XvQ== 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=vctMmaZ2jCBteIBCD7D0uyHlHM+0VSnNr88RsGWlQb4=; b=EcuX1ETjZ+WPBlc7rojH8FvdFVZhvWt5XmT9dW5JrJ2zjZpGVXgjUm2F7K/Su3UISk mJEo+qMWG2fJxq8b7yYIxfBsqFlryTlBT++dkSynraCSgr+lVHsLQZVRDTW9oDMGDsEb q4reLan6V0U3cY1vjGDMekO0ZqBENpN5VDrBOb29CP+baTPWNJt9yKddsKKTShq7Xpyc baOjWvJyF56i8vEMqYiqbFHNwCvCkTb+8kila04AtwFWEB423UL8dGx23dd6kD2yJO2E VB87BFW9I0YtG2sEKW/5NjMxWCSNlYBCD15ti/O9Zw4+nxuc+KvYiQbmay8ZBvmTW3U7 p+fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=pUITOL14; 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=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170902ec8100b0016bea2a24casi5161912plg.3.2022.07.05.02.44.11; Tue, 05 Jul 2022 02:44:24 -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=@163.com header.s=s110527 header.b=pUITOL14; 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=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbiGEJne (ORCPT + 99 others); Tue, 5 Jul 2022 05:43:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbiGEJnb (ORCPT ); Tue, 5 Jul 2022 05:43:31 -0400 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D193B10B8 for ; Tue, 5 Jul 2022 02:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=vctMm aZ2jCBteIBCD7D0uyHlHM+0VSnNr88RsGWlQb4=; b=pUITOL14hlFwwm209DVEZ EUktxKrGXxmWZ1GZm5R9a1j1W2kOWuTw6/BBujYn5+40cpltEYBD4Cc14Ws9q9IQ Coe8A2wi/6vAoMH6xrHnKV9od0RRf7+9O963QFsLwR2qSqI2tZ/UhHwKippcZero O2L6FDEPcFYLL5EFcDQA7A= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp3 (Coremail) with SMTP id G9xpCgAn4GmrB8Ri0an9NQ--.2574S4; Tue, 05 Jul 2022 17:43:16 +0800 (CST) From: Jianglei Nie To: bskeggs@redhat.com, kherbst@redhat.com, lyude@redhat.com, airlied@linux.ie, daniel@ffwll.ch Cc: ri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Tue, 5 Jul 2022 17:43:06 +0800 Message-Id: <20220705094306.2244103-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: G9xpCgAn4GmrB8Ri0an9NQ--.2574S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrZw1kXrWDJF17Xw4DZr13Jwb_yoWDtrg_uF 4IqF17Wr9Ykrs8tw4qyw1jvFWSkw4kuFWkZF95ta4SqrW7Jw13Wr4UXry3Wry7AFWjgr9x ZanYvFyakwnFgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREs2-3UUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/xtbB0RQ1jFzIBxqqrgAAsx X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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 --- 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 05076e530e7d..d0887438b07e 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.25.1