Skip to contentSkip to conversation

drm: Tear down AMD display I2C adapters with their channels

PATCH New Guangshuo Li 1 participant 3 messages Nov 26

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

cover drm: Tear down AMD display I2C adapters with their channels

Unregister the display I2C adapters as their backing channels are torn down in amdgpu and radeon.

Guangshuo Li (2):
drm/amdgpu: Unregister I2C adapters when tearing down their channels drm/radeon: Unregister I2C adapters when tearing down their channels

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

#1 lore raw

PATCH 1/2 drm/amdgpu: Unregister I2C adapters when tearing down their channels

The bit-banged adapters have no managed unregister action, and the I2C channels are allocated separately. Clearing the bus array leaves both the bit-banged adapters and channel storage behind. Register hardware adapters explicitly and unregister each adapter before freeing its channel.

This issue was found by our static analysis tool under development.

Fixes 0f36a3c6af9e ("drm/amdgpu/amdgpu_i2c: Use devm_i2c_add_adapter instead of i2c_add_adapter")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +12 -4
index c576e103a783..af3d4f9b12c7 100644
@@ -184,7 +184,7 @@ struct amdgpu_i2c_chan *amdgpu_i2c_create(struct drm_device *dev,
 		snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
 			 "AMDGPU i2c hw bus %s", name);
 		i2c->adapter.algo = &amdgpu_atombios_i2c_algo;
-		ret = devm_i2c_add_adapter(dev->dev, &i2c->adapter);
+		ret = i2c_add_adapter(&i2c->adapter);
 		if (ret)
 			goto out_free;
 	} else {
@@ -239,9 +239,17 @@ void amdgpu_i2c_fini(struct amdgpu_device *adev)
 {
 	int i;
 
-	for (i = 0; i < AMDGPU_MAX_I2C_BUS; i++)
-		if (adev->i2c_bus[i])
-			adev->i2c_bus[i] = NULL;
+	for (i = 0; i < AMDGPU_MAX_I2C_BUS; i++) {
+		struct amdgpu_i2c_chan *i2c = adev->i2c_bus[i];
+
+		if (!i2c)
+			continue;
+
+		WARN_ON(i2c->has_aux);
+		i2c_del_adapter(&i2c->adapter);
+		kfree(i2c);
+		adev->i2c_bus[i] = NULL;
+	}
 }
 
 /* looks up bus based on id */
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 drm/radeon: Unregister I2C adapters when tearing down their channels

In reply to Guangshuo Li

Only one hardware adapter path uses managed registration. Clearing the bus array leaves the other adapters registered and leaks every channel. Use explicit registration throughout and unregister each adapter before freeing its channel.

This issue was found by our static analysis tool under development.

Fixes 2e01c96d8e6c ("drm/radeon : Use devm_i2c_add_adapter instead of i2c_add_adapter")
---
 drivers/gpu/drm/radeon/radeon_i2c.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon_i2c.c +10 -3
index 13a091ec797b..4dad5c446482 100644
@@ -931,7 +931,7 @@ struct radeon_i2c_chan *radeon_i2c_create(struct drm_device *dev,
 		snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
 			 "Radeon i2c hw bus %s", name);
 		i2c->adapter.algo = &radeon_i2c_algo;
-		ret = devm_i2c_add_adapter(dev->dev, &i2c->adapter);
+		ret = i2c_add_adapter(&i2c->adapter);
 		if (ret)
 			goto out_free;
 	} else if (rec->hw_capable &&
@@ -990,8 +990,15 @@ void radeon_i2c_fini(struct radeon_device *rdev)
 	int i;
 
 	for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
-		if (rdev->i2c_bus[i])
-			rdev->i2c_bus[i] = NULL;
+		struct radeon_i2c_chan *i2c = rdev->i2c_bus[i];
+
+		if (!i2c)
+			continue;
+
+		WARN_ON(i2c->has_aux);
+		i2c_del_adapter(&i2c->adapter);
+		kfree(i2c);
+		rdev->i2c_bus[i] = NULL;
 	}
 }
 
Signature · 1 line
2.43.0