From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE51CC54FCB for ; Wed, 22 Apr 2020 15:52:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B58E22082E for ; Wed, 22 Apr 2020 15:52:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726827AbgDVPwF convert rfc822-to-8bit (ORCPT ); Wed, 22 Apr 2020 11:52:05 -0400 Received: from mga17.intel.com ([192.55.52.151]:6011 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726547AbgDVPwF (ORCPT ); Wed, 22 Apr 2020 11:52:05 -0400 IronPort-SDR: 8m2OxFzb3ldwl6XPo/9cO7OsNzpy/fMA3VIR/MvenoNprxf+vN1lOfsK+szpA6gIJ8w3Aej47N CwQG81G5Jy9A== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2020 08:52:04 -0700 IronPort-SDR: TjUAltXeCoo925sIJYL3sVkWXBBK96XchWNtkhSibXo8PV4Aq6G3f8oErs7mfdwIV7yW37IqQ5 bId691ZTbd4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,303,1583222400"; d="scan'208";a="259113020" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga006.jf.intel.com with ESMTP; 22 Apr 2020 08:52:02 -0700 Received: from fmsmsx125.amr.corp.intel.com (10.18.125.40) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 22 Apr 2020 08:51:27 -0700 Received: from fmsmsx108.amr.corp.intel.com ([169.254.9.13]) by FMSMSX125.amr.corp.intel.com ([169.254.2.138]) with mapi id 14.03.0439.000; Wed, 22 Apr 2020 08:51:27 -0700 From: "Ruhl, Michael J" To: Bernard Zhao , Alex Deucher , =?iso-8859-1?Q?Christian_K=F6nig?= , "David (ChunMing) Zhou" , David Airlie , Daniel Vetter , Tom St Denis , "Ori Messinger" , Sam Ravnborg , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" CC: "opensource.kernel@vivo.com" Subject: RE: [PATCH] amdgpu: fixes memleak issue when init failed Thread-Topic: [PATCH] amdgpu: fixes memleak issue when init failed Thread-Index: AQHWGHMwaB1WU0xlDki55E9Aceac76iFShmg Date: Wed, 22 Apr 2020 15:51:27 +0000 Message-ID: <14063C7AD467DE4B82DEDB5C278E8663010212C230@FMSMSX108.amr.corp.intel.com> References: <20200421111715.1231-1-bernard@vivo.com> In-Reply-To: <20200421111715.1231-1-bernard@vivo.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.1.200.107] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >-----Original Message----- >From: dri-devel On Behalf Of >Bernard Zhao >Sent: Tuesday, April 21, 2020 7:17 AM >To: Alex Deucher ; Christian König >; David (ChunMing) Zhou >; David Airlie ; Daniel Vetter >; Tom St Denis ; Ori Messinger >; Sam Ravnborg ; Bernard >Zhao ; amd-gfx@lists.freedesktop.org; dri- >devel@lists.freedesktop.org; linux-kernel@vger.kernel.org >Cc: opensource.kernel@vivo.com >Subject: [PATCH] amdgpu: fixes memleak issue when init failed > >VRAM manager and DRM MM when init failed, there is no operaction >to free kzalloc memory & remove device file. >This will lead to memleak & cause stability issue. > >Signed-off-by: Bernard Zhao >--- > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 >++++++++++++++++---- > 1 file changed, 19 insertions(+), 5 deletions(-) > >diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c >b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c >index 82a3299e53c0..4c5fb153e6b4 100644 >--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c >+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c >@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct >ttm_mem_type_manager *man, > ret = device_create_file(adev->dev, >&dev_attr_mem_info_vram_total); > if (ret) { > DRM_ERROR("Failed to create device file >mem_info_vram_total\n"); >- return ret; >+ goto VRAM_TOTAL_FAIL; > } > ret = device_create_file(adev->dev, >&dev_attr_mem_info_vis_vram_total); Have you looked at the DEVICE_ATTR mechanism? It is set up to add device files. You won't get the granularity of each file, but it has a lot more automatic-ness to setting this stuff up. Mike > if (ret) { > DRM_ERROR("Failed to create device file >mem_info_vis_vram_total\n"); >- return ret; >+ goto VIS_VRAM_TOTA_FAIL; > } > ret = device_create_file(adev->dev, >&dev_attr_mem_info_vram_used); > if (ret) { > DRM_ERROR("Failed to create device file >mem_info_vram_used\n"); >- return ret; >+ goto VRAM_USED_FAIL; > } > ret = device_create_file(adev->dev, >&dev_attr_mem_info_vis_vram_used); > if (ret) { > DRM_ERROR("Failed to create device file >mem_info_vis_vram_used\n"); >- return ret; >+ goto VIS_VRAM_USED_FAIL; > } > ret = device_create_file(adev->dev, >&dev_attr_mem_info_vram_vendor); > if (ret) { > DRM_ERROR("Failed to create device file >mem_info_vram_vendor\n"); >- return ret; >+ goto VRAM_VERDOR_FAIL; > } > > return 0; >+ >+VRAM_VERDOR_FAIL: >+ device_remove_file(adev->dev, >&dev_attr_mem_info_vis_vram_used); >+VIS_VRAM_USED_FAIL: >+ device_remove_file(adev->dev, &dev_attr_mem_info_vram_used); >+RVAM_USED_FAIL: >+ device_remove_file(adev->dev, >&dev_attr_mem_info_vis_vram_total); >+VIS_VRAM_TOTA_FAIL: >+ device_remove_file(adev->dev, &dev_attr_mem_info_vram_total); >+VRAM_TOTAL_FAIL: >+ kfree(mgr); >+ man->priv = NULL; >+ >+ return ret; > } > > /** >-- >2.26.2 > >_______________________________________________ >dri-devel mailing list >dri-devel@lists.freedesktop.org >https://lists.freedesktop.org/mailman/listinfo/dri-devel