Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp42242ybz; Tue, 21 Apr 2020 04:22:15 -0700 (PDT) X-Google-Smtp-Source: APiQypKDEEjdQ4rn8jih6GR3CxTFllclFpm4GEzn0wIrwwo5sw8BMNl8zlUjimjdmtBPjhOOfcjO X-Received: by 2002:a50:f61b:: with SMTP id c27mr17099678edn.256.1587468135505; Tue, 21 Apr 2020 04:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587468135; cv=none; d=google.com; s=arc-20160816; b=huneg91cdoqPs4bRudVDg0majJ4dILwQ+HNTRxCWdSHMd9fsT3fj6QzSkoseFVYtni Gyer67WzSerVPBo5Zhw7asBLmuOqQ+HOCmZQOdhmgSRH/Fhbdco+QTtDFZ9uEGTAUuH0 HBxN5wx++nxWu5N/FG1IT4PQ3dKixd8wdtdH1ZBXTxWNYX4xXAF5WxvUZUyKls8KzsPE 9ye4z7TgIfSynP0wLSYMDSwAupJeD5FqsCU+LDkR8yv4zRbzPcjj9CUy1iYGYuBeR80N ZnG0RqlraPMn/IXp22VwCj7qo82NHA8j2sv9/wnCA9+XhVbtjOeha2MdIA/YOOMYzIcs gGyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=GCQDWS1c83N6Axq+oVWqGdra35hUUAZRWinrBpSZBaU=; b=iRy75vyBcgnvrj4BmfP48ZeJaTaIPGkfepxJsQZvQhYUferqwuUI1kFu3vx9DUztiM oTATJ8qeX6O6h/nDdkAx5kuNwaUdU5zn670JEIYeixQloGN+UnyTfB5XUKE9TVOehQfC uy0+qzsBmXv5GEObg1tV1igu3gKwwTwf/+05TSk4fwXORqqF5FTvdd2cfqktS/WMWmTO VSa5+izYF3h+cQ7YGfmmuhlHnZhS1WpyXblcXzxFQObns1scnkuhBkdMWQa4d4xbWZFY VpQZfWaEqTmL+Rv8kvQdiWQ8GEh6rMKt5iRcm+UsD6wm8p5E5mwAyOW8VnZGGF9Q4/Yv G9dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l4si1384062ede.294.2020.04.21.04.21.52; Tue, 21 Apr 2020 04:22:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728717AbgDULR2 (ORCPT + 99 others); Tue, 21 Apr 2020 07:17:28 -0400 Received: from m176115.mail.qiye.163.com ([59.111.176.115]:11456 "EHLO m176115.mail.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgDULR1 (ORCPT ); Tue, 21 Apr 2020 07:17:27 -0400 Received: from ubuntu.localdomain (unknown [157.0.31.122]) by m176115.mail.qiye.163.com (Hmail) with ESMTPA id 78102664787; Tue, 21 Apr 2020 19:17:24 +0800 (CST) From: Bernard Zhao To: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "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 Date: Tue, 21 Apr 2020 04:17:13 -0700 Message-Id: <20200421111715.1231-1-bernard@vivo.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZT1VJTklCQkJMQ0lOTUlJTVlXWShZQU hPN1dZLVlBSVdZCQ4XHghZQVk1NCk2OjckKS43PlkG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Pio6HAw5KDg1PAMQTE43MSFK SSIaCgJVSlVKTkNMT01MQ09PQ0tOVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSUlZV1kIAVlBSE1ISzcG X-HM-Tid: 0a719c74fc629373kuws78102664787 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); 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