drm/radeon/ci_dpm: Remove needless NULL checks of dpm tables
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Tue, 14 Jan 2025 13:58:56 +0000 (05:58 -0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 13 Feb 2025 02:02:56 +0000 (21:02 -0500)
This patch removes useless NULL pointer checks in functions like
ci_set_private_data_variables_based_on_pptable() and
ci_setup_default_dpm_tables().

The pointers in question are initialized as addresses to existing
structures such as rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk by
utilizing & operator and therefore are not in danger of being NULL.

Fix this by removing extra checks thus cleaning the code a tiny bit.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: cc8dbbb4f62a ("drm/radeon: add dpm support for CI dGPUs (v2)")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/ci_dpm.c

index abe9d65cc4605ec0c37335a41d424ac34022bc67..7c3a960f486a0eef7f8f764732ecd7e4878a9ced 100644 (file)
@@ -3405,12 +3405,8 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
                &rdev->pm.dpm.dyn_state.cac_leakage_table;
        u32 i;
 
-       if (allowed_sclk_vddc_table == NULL)
-               return -EINVAL;
        if (allowed_sclk_vddc_table->count < 1)
                return -EINVAL;
-       if (allowed_mclk_table == NULL)
-               return -EINVAL;
        if (allowed_mclk_table->count < 1)
                return -EINVAL;
 
@@ -3468,24 +3464,20 @@ static int ci_setup_default_dpm_tables(struct radeon_device *rdev)
        pi->dpm_table.vddc_table.count = allowed_sclk_vddc_table->count;
 
        allowed_mclk_table = &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
-       if (allowed_mclk_table) {
-               for (i = 0; i < allowed_mclk_table->count; i++) {
-                       pi->dpm_table.vddci_table.dpm_levels[i].value =
-                               allowed_mclk_table->entries[i].v;
-                       pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
-               }
-               pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
+       for (i = 0; i < allowed_mclk_table->count; i++) {
+               pi->dpm_table.vddci_table.dpm_levels[i].value =
+                       allowed_mclk_table->entries[i].v;
+               pi->dpm_table.vddci_table.dpm_levels[i].enabled = true;
        }
+       pi->dpm_table.vddci_table.count = allowed_mclk_table->count;
 
        allowed_mclk_table = &rdev->pm.dpm.dyn_state.mvdd_dependency_on_mclk;
-       if (allowed_mclk_table) {
-               for (i = 0; i < allowed_mclk_table->count; i++) {
-                       pi->dpm_table.mvdd_table.dpm_levels[i].value =
-                               allowed_mclk_table->entries[i].v;
-                       pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
-               }
-               pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
+       for (i = 0; i < allowed_mclk_table->count; i++) {
+               pi->dpm_table.mvdd_table.dpm_levels[i].value =
+                       allowed_mclk_table->entries[i].v;
+               pi->dpm_table.mvdd_table.dpm_levels[i].enabled = true;
        }
+       pi->dpm_table.mvdd_table.count = allowed_mclk_table->count;
 
        ci_setup_default_pcie_tables(rdev);
 
@@ -4880,16 +4872,10 @@ static int ci_set_private_data_variables_based_on_pptable(struct radeon_device *
        struct radeon_clock_voltage_dependency_table *allowed_mclk_vddci_table =
                &rdev->pm.dpm.dyn_state.vddci_dependency_on_mclk;
 
-       if (allowed_sclk_vddc_table == NULL)
-               return -EINVAL;
        if (allowed_sclk_vddc_table->count < 1)
                return -EINVAL;
-       if (allowed_mclk_vddc_table == NULL)
-               return -EINVAL;
        if (allowed_mclk_vddc_table->count < 1)
                return -EINVAL;
-       if (allowed_mclk_vddci_table == NULL)
-               return -EINVAL;
        if (allowed_mclk_vddci_table->count < 1)
                return -EINVAL;