From patchwork Mon Dec 4 08:06:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 173121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2614514vqy; Mon, 4 Dec 2023 00:07:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7UCec7FjT38goninPYyzq83mgHHYrXU1NgyzvrJvheHZI532tSI+7Px5DigpANf05t+Wv X-Received: by 2002:a17:902:f54c:b0:1d0:6ffe:9ec with SMTP id h12-20020a170902f54c00b001d06ffe09ecmr4501200plf.74.1701677273000; Mon, 04 Dec 2023 00:07:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701677272; cv=none; d=google.com; s=arc-20160816; b=MhBAyYBOyGkUiKvctYiwO9ukvEVNquHvwj26L4fmG0ODiJI3RT527pBcmZw8cfpuaJ BN5ZkplcRlfwvTKOhN7Nk3n33i+TgWl96s0Vpoy3KjC1or366Gz2ZODQ12MqvB8QRm5Q JNI08P729o+uzrmDrLy7kX+Z2uUOYnpA5QEW+3QS4oMgEpQYC7L/BI/d45BlNPxCfUf5 rzrsqqGuYIzTQgfArYxZhJnewnJ2PsRT38x5X+z+TlR6qcB/H6OwqwwEH9uanFuplnY2 Dve77VhEw8sPy7HeBkeNCcdud8CJp4IjZj4L2mQHsL8YCG1JpvzMsdqBN09NwQwnAtEb 3e+Q== 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; bh=LX0qs8172aRk3FdDzAVeCO7aVxQIgL0RNMaA6Hvhdi8=; fh=5wn8w10TNNKg0T25di8BZvwFJVZARjawxPDr5mbd868=; b=tGMm82qkhgz29VYwMlJ7EAdziV0vfTpnJVIXhKibDDf88oeaSB6Gl7meIDjd/laPVh kLeAJTbTjcoZ8FgP/I+DKhcDYWs/eBEfc6IrucK07JLXwJFA7Qgl2n51QgzlGCczvcEC CAGFObYRHlZ0x4nlfk6QFNf03bSDh26XJ5RwV4qpk59Fzkiz3L/mdpQCvGtrQP/kmaYO VSQc8/5lkCcEPnfe1rnjEgMzh54z/AwDTtqT8MS4zU8iuKD1sHIy9tHRA3jKJT1snL4Z YAnXTd5/lObB156JziBRWPAgOhk2xoLojHJq46eIaBrDnuL2VvoF7xIxlSEvQPTY/KdT eL3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id iz21-20020a170902ef9500b001d0a9fdd8besi1044899plb.628.2023.12.04.00.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 00:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 788248083A90; Mon, 4 Dec 2023 00:07:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234699AbjLDIHi (ORCPT + 99 others); Mon, 4 Dec 2023 03:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjLDIHc (ORCPT ); Mon, 4 Dec 2023 03:07:32 -0500 Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E7CFA1A1 for ; Mon, 4 Dec 2023 00:07:26 -0800 (PST) Received: from luzhipeng.223.5.5.5 (unknown [115.200.230.188]) by mail-app3 (Coremail) with SMTP id cC_KCgCHjBmniG1lzaVqAA--.37252S2; Mon, 04 Dec 2023 16:07:04 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Zack Rusin , VMware Graphics Reviewers , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , Matthew Auld , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node Date: Mon, 4 Dec 2023 16:06:46 +0800 Message-Id: <20231204080646.3299620-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CM-TRANSID: cC_KCgCHjBmniG1lzaVqAA--.37252S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKr48WFykJw1fJF4xAFy5Arb_yoWfurc_ua yYqrn2q3y3CFn5uw12v3sxuF42ka1fuFs7uFs3ta43J3sIv340gry7ur98Xw4xWFsrCryD Wa1UGw1fArnrKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbV8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr1j 6rxdM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxa n2IY04v7MxkIecxEwVAFwVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvE x4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvj DU0xZFpf9x0JUhdbbUUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 04 Dec 2023 00:07:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784337947897884696 X-GMAIL-MSGID: 1784337947897884696 When ida_alloc_max fails, resources allocated before should be freed, including *res allocated by kmalloc and ttm_resource_init. Fixes: d3bcb4b02fe9 ("drm/vmwgfx: switch the TTM backends to self alloc") Signed-off-by: Zhipeng Lu --- drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c index ceb4d3d3b965..220561b73493 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c @@ -65,6 +65,8 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man, id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL); if (id < 0) + ttm_resource_fini(man, *res); + kfree(*res); return id; spin_lock(&gman->lock);