Message ID | 20230508085016.437836-1-liucong2@kylinos.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2015882vqo; Mon, 8 May 2023 02:16:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WAKkUieGanxmFnFUI9wzP/2dnIwRsvQP/QO/+o4GXygO+mcxNEBVVgYNJ8LEk88KZ3ld7 X-Received: by 2002:a17:90b:3ece:b0:24e:3413:c7ff with SMTP id rm14-20020a17090b3ece00b0024e3413c7ffmr17361991pjb.7.1683537389873; Mon, 08 May 2023 02:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683537389; cv=none; d=google.com; s=arc-20160816; b=FOlsa+1U4JU679EzNySZkHrnCYQmarnVc1rgxQ6NkgrDosn/3+hedYpPPDttUGWYzI ajxgZrBWdYTXUzSvEUR7b9WPO3XdrZJQ0AZtvvvBx+mMNZLqS/2klxQG1LAGkuV8KeuR 9gvAgATXxCJLEw0CE4ZWwZO7kO8PizibmBGIIcfSRe7EUsT9SeevT9XPCLxNsNryAuhs pcauAjTF7Kc8qAqoNVFAmyCEHkMXpV2U1cpCF9cddZ9brDGGFekKsbeag2TAXgt572du 3a5t+JnUc3MOl4ASqwELkknupsN71jWVhosfu3ltV9psarW4KB+Y2u0Rjk4/WD/tdWXH B5eg== 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=jkStybMbcHQhi8xDl5sfexe6s4uzWAZMC3rwsaRXkJk=; b=jdHQi0MB9my+aXsPsJPKahfgGYVwjQKQOfwEGE9g8LUy4YladtybOMDloJ7aE9eqdW 0+9jHkpuSU+sbwNBcoPLoFAoKeyIBkHrSdLNu9W42iDGnBe08x3zJ2NMvV34VsozVB78 Qxdl/orPU0KeQF1ZIzIBMfqeesNlrFhPX/YShJWq48Eo8fVDmnevxEWXcGonTQp3jMUz FxLDFrTIgzQoOKh7RcY2GuNtrvpsFiAK7k7ee9L5gTQCoivGPuhd+BRCqGbw+o03RRGG a5y/0ShuvhAWZDwTrjJuqFSQk5wdNeowxZxqkUoFpuZKlm3YuTd+cKgZyPKvcS0Ng35T 1VdA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a17090a074100b002470e893981si6024439pje.79.2023.05.08.02.16.14; Mon, 08 May 2023 02:16:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbjEHIv7 (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Mon, 8 May 2023 04:51:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbjEHIv6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 8 May 2023 04:51:58 -0400 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 963B740D1 for <linux-kernel@vger.kernel.org>; Mon, 8 May 2023 01:51:56 -0700 (PDT) X-UUID: 448e16397a6242399bf3f0072562a30b-20230508 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:6c58c0b9-9ae8-41b1-9b55-fb6474963e22,IP:15, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-INFO: VERSION:1.1.22,REQID:6c58c0b9-9ae8-41b1-9b55-fb6474963e22,IP:15,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:0 X-CID-META: VersionHash:120426c,CLOUDID:bfb91a6b-2f20-4998-991c-3b78627e4938,B ulkID:230508165141N0GP7D3I,BulkQuantity:0,Recheck:0,SF:38|24|17|19|44|102, TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-UUID: 448e16397a6242399bf3f0072562a30b-20230508 X-User: liucong2@kylinos.cn Received: from localhost.localdomain [(116.128.244.169)] by mailgw (envelope-from <liucong2@kylinos.cn>) (Generic MTA) with ESMTP id 812679255; Mon, 08 May 2023 16:51:40 +0800 From: Cong Liu <liucong2@kylinos.cn> To: Jani Nikula <jani.nikula@linux.intel.com>, Joonas Lahtinen <joonas.lahtinen@linux.intel.com>, Rodrigo Vivi <rodrigo.vivi@intel.com>, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch> Cc: Cong Liu <liucong2@kylinos.cn>, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/i915: Fix memory leaks in function live_nop_switch Date: Mon, 8 May 2023 16:50:15 +0800 Message-Id: <20230508085016.437836-1-liucong2@kylinos.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765316901852874857?= X-GMAIL-MSGID: =?utf-8?q?1765316901852874857?= |
Series |
drm/i915: Fix memory leaks in function live_nop_switch
|
|
Commit Message
Cong Liu
May 8, 2023, 8:50 a.m. UTC
Be sure to properly free the allocated memory before exiting
the live_nop_switch function.
Signed-off-by: Cong Liu <liucong2@kylinos.cn>
---
drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
On Mon, May 08, 2023 at 04:50:15PM +0800, Cong Liu wrote: > Be sure to properly free the allocated memory before exiting > the live_nop_switch function. > > Signed-off-by: Cong Liu <liucong2@kylinos.cn> > --- > drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c > index a81fa6a20f5a..54eddbe7f510 100644 > --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c > +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c > @@ -59,7 +59,8 @@ static int live_nop_switch(void *arg) > ctx = kcalloc(nctx, sizeof(*ctx), GFP_KERNEL); > if (!ctx) { > err = -ENOMEM; > - goto out_file; > + fput(file); This looks strange... > + return err; > } > > for (n = 0; n < nctx; n++) { > @@ -175,6 +176,7 @@ static int live_nop_switch(void *arg) > > out_file: > fput(file); > + kfree(ctx); You are right... we have a leak in this function... but the way to solve it is by adding a new goto point above kfree(ctx) ('free_ctx:' ... our 'out_ctx:') and calling it from any place below the succeeded allocation instead of the 'out_file:' Something like: --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -66,7 +66,7 @@ static int live_nop_switch(void *arg) ctx[n] = live_context(i915, file); if (IS_ERR(ctx[n])) { err = PTR_ERR(ctx[n]); - goto out_file; + goto out_ctx; } } @@ -82,7 +82,7 @@ static int live_nop_switch(void *arg) this = igt_request_alloc(ctx[n], engine); if (IS_ERR(this)) { err = PTR_ERR(this); - goto out_file; + goto out_ctx; } if (rq) { i915_request_await_dma_fence(this, &rq->fence); @@ -96,7 +96,7 @@ static int live_nop_switch(void *arg) intel_gt_set_wedged(engine->gt); i915_request_put(rq); err = -EIO; - goto out_file; + goto out_ctx; } i915_request_put(rq); @@ -107,7 +107,7 @@ static int live_nop_switch(void *arg) err = igt_live_test_begin(&t, i915, __func__, engine->name); if (err) - goto out_file; + goto out_ctx; end_time = jiffies + i915_selftest.timeout_jiffies; for_each_prime_number_from(prime, 2, 8192) { @@ -120,7 +120,7 @@ static int live_nop_switch(void *arg) this = igt_request_alloc(ctx[n % nctx], engine); if (IS_ERR(this)) { err = PTR_ERR(this); - goto out_file; + goto out_ctx; } if (rq) { /* Force submission order */ @@ -165,7 +165,7 @@ static int live_nop_switch(void *arg) err = igt_live_test_end(&t); if (err) - goto out_file; + goto out_ctx; pr_info("Switch latencies on %s: 1 = %lluns, %lu = %lluns\n", engine->name, @@ -173,6 +173,8 @@ static int live_nop_switch(void *arg) prime - 1, div64_u64(ktime_to_ns(times[1]), prime - 1)); } +out_ctx: + kfree(ctx); out_file: fput(file); return err; > return err; > } > > -- > 2.34.1 > > > No virus found > Checked by Hillstone Network AntiVirus
diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c index a81fa6a20f5a..54eddbe7f510 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c @@ -59,7 +59,8 @@ static int live_nop_switch(void *arg) ctx = kcalloc(nctx, sizeof(*ctx), GFP_KERNEL); if (!ctx) { err = -ENOMEM; - goto out_file; + fput(file); + return err; } for (n = 0; n < nctx; n++) { @@ -175,6 +176,7 @@ static int live_nop_switch(void *arg) out_file: fput(file); + kfree(ctx); return err; }