[PATCH] drm/amdgpu: Fix crashes in enforce_isolation sysfs handling on non-supported systems

Srinivasan Shanmugam srinivasan.shanmugam at amd.com
Thu Feb 13 17:50:12 UTC 2025


By adding these NULL pointer checks and improving error handling, we can
prevent crashes when the enforce_isolation sysfs file is accessed on
non-supported systems.

Cc: Christian König <christian.koenig at amd.com>
Cc: Alex Deucher <alexander.deucher at amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 27f5318c3a26..bf0bf6382b65 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -1777,20 +1777,27 @@ static int amdgpu_gfx_sysfs_isolation_shader_init(struct amdgpu_device *adev)
 {
 	int r;
 
+	if (!adev->gfx.enable_cleaner_shader)
+		return -EINVAL;
+
 	r = device_create_file(adev->dev, &dev_attr_enforce_isolation);
 	if (r)
 		return r;
-	if (adev->gfx.enable_cleaner_shader)
-		r = device_create_file(adev->dev, &dev_attr_run_cleaner_shader);
 
-	return r;
+	r = device_create_file(adev->dev, &dev_attr_run_cleaner_shader);
+	if (r)
+		return r;
+
+	return 0;
 }
 
 static void amdgpu_gfx_sysfs_isolation_shader_fini(struct amdgpu_device *adev)
 {
+	if (!adev->gfx.enable_cleaner_shader)
+		return;
+
 	device_remove_file(adev->dev, &dev_attr_enforce_isolation);
-	if (adev->gfx.enable_cleaner_shader)
-		device_remove_file(adev->dev, &dev_attr_run_cleaner_shader);
+	device_remove_file(adev->dev, &dev_attr_run_cleaner_shader);
 }
 
 static int amdgpu_gfx_sysfs_reset_mask_init(struct amdgpu_device *adev)
-- 
2.34.1



More information about the amd-gfx mailing list