Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2579711rdb; Mon, 4 Dec 2023 01:15:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQQ3zv7T1Ja7yO77sBt/xRX3Imj296j5cjucHgp5Yvs3dk+ehLBswhkSHrxI55E+AE5UdY X-Received: by 2002:a17:90b:3805:b0:285:a209:3413 with SMTP id mq5-20020a17090b380500b00285a2093413mr1533777pjb.9.1701681304406; Mon, 04 Dec 2023 01:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701681304; cv=none; d=google.com; s=arc-20160816; b=kbH3aJfc7WQNdU4i+WxMx+9aigQypywZUxnl8bJ9vvLeCMqVUn4wEaPt/t/6FJ5aez Iee1YqQyXipDCXaZGXFlEgpe7mbv3Pp6MsAkXFXJr9x1ZD2fU6pbODaldsvT1Gj4TOJ6 irhIaT/EU3lrndSkaNHGPYy6cOsOIbaAGBslVghVHrbdeITQJwHOEnxEsErljjzQL/w1 d7AYk52yWnqqQ/QVRDVCa8bkMtw6ufOLTFo7HMfbV9BNhfaIpcIu+epOhr7iaanKupZL WTBN/kVilHCZGnF9S1AnQsGoUL/JxP0xlarYHuX6zB158EFD2JTo4qHLboOLp6zbk0Wz lmzg== 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=uBw0okcWxzGxTUPxTuQAu/2cFXCfkpn3ihsY4e9UTCM=; fh=BLauCf5kx55FuwbFft95qstjg/spdyP/0fmmNNfAu0Y=; b=UJaNDeQSgfFyuPol1fOywz1xqD0T1LinJB8M2+/dDTGwA5QDwnaKswqdYtdoPHcBRJ 6R/chYzFothP+QUkU9u8icHmWRkqxiM0d4qYavP6LlEc0jOh1wiuB6wJPsM/+idd0T0V oxAJE9eUKFd/VJu25CksdL5+vNXyqlbWo4vpapPccszQ30q7vO02TT7YG9ZB4d3xb79g Ud9foDCtvozhox8T+l9TEeXKwrj2No2Cc4bKXMIKtn4R3zO2Mw/XiqGlJpHPNeDnELUR mJcV5rMmSbzPz7FOWJ++L3u9ErLg3KxCS6N/AfhJRUinBBwL2Mq62SduMmBI5vQGjyOS tDug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id lk9-20020a17090b33c900b0028526216f31si226680pjb.106.2023.12.04.01.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 01:15:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id C56EC809E709; Mon, 4 Dec 2023 01:15:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbjLDJOx (ORCPT + 99 others); Mon, 4 Dec 2023 04:14:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjLDJOw (ORCPT ); Mon, 4 Dec 2023 04:14:52 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D85D101 for ; Mon, 4 Dec 2023 01:14:55 -0800 (PST) Received: from luzhipeng.223.5.5.5 (unknown [125.120.155.9]) by mail-app4 (Coremail) with SMTP id cS_KCgBn8tV3mG1l9ZVIAA--.54758S2; Mon, 04 Dec 2023 17:14:31 +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 , Matthew Auld , =?UTF-8?q?Christian=20K=C3=B6nig?= , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node Date: Mon, 4 Dec 2023 17:14:16 +0800 Message-Id: <20231204091416.3308430-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cS_KCgBn8tV3mG1l9ZVIAA--.54758S2 X-Coremail-Antispam: 1UD129KBjvdXoWrKr48WFykJw1fJF4xAFy5Arb_yoWDtrc_ua yjqr1vq3y3uFn5uwnIv3s8ua12kw4ruFs7uFs5ta43J3sIqrykWry7Wr98Xw4xWFsrCryD ua1UGw1fArnI9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbV8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_GcCE 3s1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s 1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0 cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8Jw ACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka 0xkIwI1lc2xSY4AK67AK6r4fMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvj DU0xZFpf9x0JUhNVgUUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 01:15:03 -0800 (PST) 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 --- Changelog: v2: Adding {} to correct the if statement --- drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c index ceb4d3d3b965..a0b47c9b33f5 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c @@ -64,8 +64,11 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man, ttm_resource_init(bo, place, *res); id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL); - if (id < 0) + if (id < 0) { + ttm_resource_fini(man, *res); + kfree(*res); return id; + } spin_lock(&gman->lock); -- 2.34.1