]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/amd/pm: Use devm_i2c_add_adapter() in the V13_0_6 smu
authorRodrigo Siqueira <siqueira@igalia.com>
Wed, 10 Sep 2025 17:39:42 +0000 (11:39 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 16 Sep 2025 21:47:40 +0000 (17:47 -0400)
The I2C init for V13_0_6 uses i2c_add_adapter() and i2c_del_adapter(),
this commit replaces the use of these two functions with
devm_i2c_add_adapter(). Notice that V13_0_6 init initializes multiple
I2C buses in a loop; if something goes wrong, the previous adapters are
removed, and the amdgpu load is interrupted. Since I2C init is required
for the correct load of amdgpu, it is safe to rely on
devm_i2c_add_adapter() to handle any previously initialized I2C adapter.

Signed-off-by: Rodrigo Siqueira <siqueira@igalia.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c

index bcd6525ca5e91ebd47d5f0b19df19795f796fc8f..fd1d8e48273f7c9d6a94c3a42c6e55692041f865 100644 (file)
@@ -2494,10 +2494,10 @@ static int smu_v13_0_6_i2c_control_init(struct smu_context *smu)
                control->quirks = &smu_v13_0_6_i2c_control_quirks;
                i2c_set_adapdata(control, smu_i2c);
 
-               res = i2c_add_adapter(control);
+               res = devm_i2c_add_adapter(adev->dev, control);
                if (res) {
                        DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
-                       goto Out_err;
+                       return res;
                }
        }
 
@@ -2505,27 +2505,12 @@ static int smu_v13_0_6_i2c_control_init(struct smu_context *smu)
        adev->pm.fru_eeprom_i2c_bus = &adev->pm.smu_i2c[0].adapter;
 
        return 0;
-Out_err:
-       for ( ; i >= 0; i--) {
-               struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
-               struct i2c_adapter *control = &smu_i2c->adapter;
-
-               i2c_del_adapter(control);
-       }
-       return res;
 }
 
 static void smu_v13_0_6_i2c_control_fini(struct smu_context *smu)
 {
        struct amdgpu_device *adev = smu->adev;
-       int i;
 
-       for (i = 0; i < MAX_SMU_I2C_BUSES; i++) {
-               struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
-               struct i2c_adapter *control = &smu_i2c->adapter;
-
-               i2c_del_adapter(control);
-       }
        adev->pm.ras_eeprom_i2c_bus = NULL;
        adev->pm.fru_eeprom_i2c_bus = NULL;
 }