Skip to contentSkip to conversation

drm/amd/display: remove oem i2c adapter on finish

PATCH In review Geoffrey McRae 2 participants 2 messages Aug 28, 2025

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

PATCH 1/1 drm/amd/display: remove oem i2c adapter on finish

Fixes a bug where unbinding of the GPU would leave the oem i2c adapter registered resuling in a null pointer dereference when applications try to access the invalid device.

Cc Harry Wentland <[email protected]>
Cc Alex Deucher <[email protected]>
Change-Id I9466b489859c3963653976e54818254596b5a13b
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +11 -1
index b944abea306d..ef7b59fe6f4d 100644
@@ -2957,6 +2957,16 @@ static int dm_oem_i2c_hw_init(struct amdgpu_device *adev)
 	return 0;
 }
 
+static void dm_oem_i2c_hw_fini(struct amdgpu_device *adev)
+{
+	struct amdgpu_display_manager *dm = &adev->dm;
+	if (dm->oem_i2c) {
+		i2c_del_adapter(&dm->oem_i2c->base);
+		kfree(dm->oem_i2c);
+		dm->oem_i2c = NULL;
+	}
+}
+
 /**
  * dm_hw_init() - Initialize DC device
  * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
@@ -3007,7 +3017,7 @@ static int dm_hw_fini(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
 
-	kfree(adev->dm.oem_i2c);
+	dm_oem_i2c_hw_fini(adev);
 
 	amdgpu_dm_hpd_fini(adev);
 

--
2.43.0

maintainer Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 8 lines

-----Original Message-----
From: McRae, Geoffrey <[email protected]>
Sent: Thursday, August 28, 2025 8:52 AM
To: Wentland, Harry <[email protected]>
Cc: Deucher, Alexander <[email protected]>; amd- [email protected]; McRae, Geoffrey <[email protected]>
Subject: [PATCH 1/1] drm/amd/display: remove oem i2c adapter on finish

Quoted 7 lines

Fixes a bug where unbinding of the GPU would leave the oem i2c adapter registered resuling in a null pointer dereference when applications try to access the invalid device.

Cc Harry Wentland <[email protected]>
Cc Alex Deucher <[email protected]>

Can you add a Fixes: tag? With that added,

Quoted 38 lines

Change-Id: I9466b489859c3963653976e54818254596b5a13b

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10 -2
index b944abea306d..ef7b59fe6f4d 100644
@@ -2957,6 +2957,16 @@ static int dm_oem_i2c_hw_init(struct amdgpu_device
 *adev)
      return 0;
 }
 
+static void dm_oem_i2c_hw_fini(struct amdgpu_device *adev) {
+     struct amdgpu_display_manager *dm = &adev->dm;
+     if (dm->oem_i2c) {
+             i2c_del_adapter(&dm->oem_i2c->base);
+             kfree(dm->oem_i2c);
+             dm->oem_i2c = NULL;
+     }
+}
+
 /**
  * dm_hw_init() - Initialize DC device
  * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
@@ -3007,7 +3017,7 @@ static int dm_hw_fini(struct amdgpu_ip_block *ip_block)
 {
      struct amdgpu_device *adev = ip_block->adev;
 
-     kfree(adev->dm.oem_i2c);
+     dm_oem_i2c_hw_fini(adev);
 
      amdgpu_dm_hpd_fini(adev);
 
--

2.43.0