Skip to contentSkip to conversation

drm/i915/gvt: Replace DEFINE_SIMPLE_ATTRIBUTE by DEFINE_DEBUGFS_ATTRIBUTE

PATCH In review Deepak R Varma 1 participant 2 messages Dec 16, 2022 – Dec 23, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/gvt: Replace DEFINE_SIMPLE_ATTRIBUTE by DEFINE_DEBUGFS_ATTRIBUTE

The DEFINE_DEBUGFS_ATTRIBUTE macro has implementation for protecting the read/write file operations from removal race conditions. This further enables using debugfs_create_file_unsafe() function since there is no need for a proxy file operations struct for protection. Hence replace the DEFINE_SIMPLE_ATTRIBUTE macro by DEFINE_DEBUGFS_ATTRIBUTE and the debugfs_create_file() by the lightweight debugfs_create_file_unsafe() versions.

This issue was identified using the coccinelle debugfs_simple_attr.cocci semantic patch.

---
Please note: The changes are compile tested only.

 drivers/gpu/drm/i915/gvt/debugfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gvt/debugfs.c +5 -5
index 9f1c209d9251..a45a43c35a6b 100644
@@ -147,9 +147,9 @@ vgpu_scan_nonprivbb_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
-			vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
-			"0x%llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
+			 vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
+			 "0x%llx\n");
 
 /**
  * intel_gvt_debugfs_add_vgpu - register debugfs entries for a vGPU
@@ -165,8 +165,8 @@ void intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
 	debugfs_create_bool("active", 0444, vgpu->debugfs, &vgpu->active);
 	debugfs_create_file("mmio_diff", 0444, vgpu->debugfs, vgpu,
 			    &vgpu_mmio_diff_fops);
-	debugfs_create_file("scan_nonprivbb", 0644, vgpu->debugfs, vgpu,
-			    &vgpu_scan_nonprivbb_fops);
+	debugfs_create_file_unsafe("scan_nonprivbb", 0644, vgpu->debugfs, vgpu,
+				   &vgpu_scan_nonprivbb_fops);
 }
 
 /**

--
2.34.1

#1 lore raw
Quoted 8 lines · Deepak R Varma

The DEFINE_DEBUGFS_ATTRIBUTE macro has implementation for protecting the read/write file operations from removal race conditions. This further enables using debugfs_create_file_unsafe() function since there is no need for a proxy file operations struct for protection. Hence replace the DEFINE_SIMPLE_ATTRIBUTE macro by DEFINE_DEBUGFS_ATTRIBUTE and the debugfs_create_file() by the lightweight debugfs_create_file_unsafe() versions.

Quoted 4 lines

This issue was identified using the coccinelle debugfs_simple_attr.cocci semantic patch.

Hello,
May I please request a review and feedback on this change proposal?

Thank you,
./drv

Quoted 37 lines

---
Please note: The changes are compile tested only.

 drivers/gpu/drm/i915/gvt/debugfs.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gvt/debugfs.c +5 -6
index 9f1c209d9251..a45a43c35a6b 100644
@@ -147,9 +147,9 @@ vgpu_scan_nonprivbb_set(void *data, u64 val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
-			vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
-			"0x%llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
+			 vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
+			 "0x%llx\n");
 
 /**
  * intel_gvt_debugfs_add_vgpu - register debugfs entries for a vGPU
@@ -165,8 +165,8 @@ void intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
 	debugfs_create_bool("active", 0444, vgpu->debugfs, &vgpu->active);
 	debugfs_create_file("mmio_diff", 0444, vgpu->debugfs, vgpu,
 			    &vgpu_mmio_diff_fops);
-	debugfs_create_file("scan_nonprivbb", 0644, vgpu->debugfs, vgpu,
-			    &vgpu_scan_nonprivbb_fops);
+	debugfs_create_file_unsafe("scan_nonprivbb", 0644, vgpu->debugfs, vgpu,
+				   &vgpu_scan_nonprivbb_fops);
 }
 
 /**
--

2.34.1