Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp561141ybj; Thu, 7 May 2020 02:15:19 -0700 (PDT) X-Google-Smtp-Source: APiQypJRggK2r3M7qNhPosOILQ11Gv8NHpfrkmedMyL1TlsskW5NqnckeMAEYtAuig2WhEyVFKmR X-Received: by 2002:a17:906:4dc8:: with SMTP id f8mr11345576ejw.23.1588842919392; Thu, 07 May 2020 02:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588842919; cv=none; d=google.com; s=arc-20160816; b=jKs2cpCGSxe9pF9Q2xPRk7ZR+CF5saZBPeRVkSFwgS3tHT0QFzdEFaeyRgjvJ3SS+m EgEsmrDnI0FQBfu6QAFNnzUOPaDLGwBdUv4e2kPe2cKzzQ5ZtVvUPvtF+5YmYIQYNOJO bP8EGqAgRATGmZhRoBhGbXhgkFA5Q1Ul+mbqYB+S8ELpbcFslGZ7nToz0N9NRq8x1uwO dqjNMCRGnpxvCoIxiCl85bgh5Wa3WuzL2pKZvb/8aVUIIEAD2spqHhtR3ip+0ZHr7pHY oF5MkWLA16cpnwmbu5OKZe8EXpRBbvxH3ioFtN2CjI/DQ13fif/nGII5v81BY2wsolcj YC0w== 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=nFL9eksHQbsrHzytEEwQU1S95XU6Q6K53XrRq8bpUY8=; b=vfBks6Zlun2aU6/wv3v6ks0idV+lWUY5wyPbeOXWYoFc7N6eaKbikQh4FGiy/r1kpX lUVrdoSwHUUDAO30phGY9uh6p4xLydBnUTjSvpNCH6tT4jFneEf5/Lpo3b75NVd4vLKu pPfJ3OAOywwDzMnu7Zg2AbFO+S6KUuju17868pKACwbtF+VreMuULYD2hllv15f/RA+m 1idKdb1qfprsh+VUqNwBFQanxVuon5MScdO8Z4scLTXTXkwjaAAck4jOzKoL8NNHg8lJ UeAKves4U0Nc2MIMLyHKKreWLk4p5XbWlGC/FFKgus6FgpSzvYkKWKj9nxhBzAYLuiGn J0yQ== 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 cm14si2631866edb.546.2020.05.07.02.14.56; Thu, 07 May 2020 02:15:19 -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 S1726007AbgEGJN1 (ORCPT + 99 others); Thu, 7 May 2020 05:13:27 -0400 Received: from mail-m17613.qiye.163.com ([59.111.176.13]:27804 "EHLO mail-m17613.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbgEGJN1 (ORCPT ); Thu, 7 May 2020 05:13:27 -0400 Received: from ubuntu.localdomain (unknown [157.0.31.122]) by mail-m17613.qiye.163.com (Hmail) with ESMTPA id EC5C5482B05; Thu, 7 May 2020 17:13:20 +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 , Sam Ravnborg , Ori Messinger , Bernard Zhao , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com Subject: [PATCH v2] drm/amd/amdgpu: cleanup coding style a bit Date: Thu, 7 May 2020 02:13:05 -0700 Message-Id: <20200507091311.10898-1-bernard@vivo.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZT1VPTklLS0tKT0pKT0hDWVdZKFlBSE 83V1ktWUFJV1kJDhceCFlBWTU0KTY6NyQpLjc#WQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Ojo6HQw*KDg9Pz88Pws#KgEC NT4KCjFVSlVKTkNDQ09JQ0tPSUJDVTMWGhIXVRkeCRUaCR87DRINFFUYFBZFWVdZEgtZQVlKTkxV S1VISlVKSUlZV1kIAVlBT05ITDcG X-HM-Tid: 0a71ee69284893bakuwsec5c5482b05 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is DEVICE_ATTR mechanism in separate attribute define. So this change is to use attr array, also use sysfs_create_files in init function & sysfs_remove_files in fini function. This maybe make the code a bit readable. Signed-off-by: Bernard Zhao Changes since V1: *Use DEVICE_ATTR mechanism Link for V1: *https://lore.kernel.org/patchwork/patch/1228076/ --- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 43 ++++++-------------- 1 file changed, 13 insertions(+), 30 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..57bbc70662ff 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -148,6 +148,15 @@ static DEVICE_ATTR(mem_info_vis_vram_used, S_IRUGO, static DEVICE_ATTR(mem_info_vram_vendor, S_IRUGO, amdgpu_mem_info_vram_vendor, NULL); +static struct attribute *amdgpu_vram_mgr_attributes[] = { + &dev_attr_mem_info_vram_total.attr, + &dev_attr_mem_info_vis_vram_total.attr, + &dev_attr_mem_info_vram_used.attr, + &dev_attr_mem_info_vis_vram_used.attr, + &dev_attr_mem_info_vram_vendor.attr, + NULL +}; + /** * amdgpu_vram_mgr_init - init VRAM manager and DRM MM * @@ -172,31 +181,9 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, man->priv = mgr; /* Add the two VRAM-related sysfs files */ - 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; - } - 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; - } - 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; - } - 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; - } - 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; - } + ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes); + if (ret) + DRM_ERROR("Failed to register sysfs\n"); return 0; } @@ -219,11 +206,7 @@ static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man) spin_unlock(&mgr->lock); kfree(mgr); man->priv = NULL; - device_remove_file(adev->dev, &dev_attr_mem_info_vram_total); - device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_total); - device_remove_file(adev->dev, &dev_attr_mem_info_vram_used); - device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_used); - device_remove_file(adev->dev, &dev_attr_mem_info_vram_vendor); + sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes); return 0; } -- 2.26.2