Message ID | 20231204091416.3308430-1-alexious@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2639047vqy; Mon, 4 Dec 2023 01:15:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnKhxplL137HwWQqga6MXbHOLk9diad/4cpsCMf0XUKLW7jFnhCfSrjSzfXwLllQlEc7bF X-Received: by 2002:a05:6358:1083:b0:170:3e6a:66d2 with SMTP id j3-20020a056358108300b001703e6a66d2mr165132rwi.46.1701681303221; Mon, 04 Dec 2023 01:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701681303; cv=none; d=google.com; s=arc-20160816; b=R9ZUZ9mCnBieJ/AtGcWqHU2Dx1rwm7aK+viaFvzpJc1H/e3CypolTG7+PUUax4sfm1 hWDywaYaLJb62srXSKOiOMzkgFTNlsuJXDOvbwyFYuhW8/m/I3b4BtQXvJCO83ANXvxM 5PndNy4+gmUPZnTVvJHl9fAzcxxLaTsftCZ1iYuonWbWkwKS/SaV6ycsyXPlUwnm41gO w9OGvuI1yo5GckrtzLm9SFJTZLx8+YFNMrqljymir0PAo7yRFSotdl96NdPuKcv4hUGA YCwqY6i5d9fRMf/waTDyG+w5Yno56CpD2tGfq8KXHvrxm5XB88Cz5qm21EHWoSt9yEbw gBnw== 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 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x6-20020aa784c6000000b006cd9be7fc74si2829867pfn.355.2023.12.04.01.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 01:15:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 2EB42809E700; 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 <rfc822;chrisfriedt@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <alexious@zju.edu.cn> To: alexious@zju.edu.cn Cc: Zack Rusin <zackr@vmware.com>, VMware Graphics Reviewers <linux-graphics-maintainer@vmware.com>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Matthew Auld <matthew.auld@intel.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, 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: <linux-kernel.vger.kernel.org> 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:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784337947897884696 X-GMAIL-MSGID: 1784342174309679925 |
Series |
[v2] drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node
|
|
Commit Message
Zhipeng Lu
Dec. 4, 2023, 9:14 a.m. UTC
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 <alexious@zju.edu.cn>
---
Changelog:
v2: Adding {} to correct the if statement
---
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Mon, Dec 4, 2023 at 4:15 AM Zhipeng Lu <alexious@zju.edu.cn> wrote: > > 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 <alexious@zju.edu.cn> > --- > > 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); Thanks, I pushed it to drm-misc-next. z
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);