drm/amdgpu: Fix memcpy() in sienna_cichlid_append_powerplay_table function.
authorSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Fri, 9 Jun 2023 08:36:43 +0000 (14:06 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 15 Jun 2023 14:45:39 +0000 (10:45 -0400)
Fixes the following gcc with W=1:

In file included from ./include/linux/string.h:253,
                 from ./include/linux/bitmap.h:11,
                 from ./include/linux/cpumask.h:12,
                 from ./arch/x86/include/asm/cpumask.h:5,
                 from ./arch/x86/include/asm/msr.h:11,
                 from ./arch/x86/include/asm/processor.h:22,
                 from ./arch/x86/include/asm/cpufeature.h:5,
                 from ./arch/x86/include/asm/thread_info.h:53,
                 from ./include/linux/thread_info.h:60,
                 from ./arch/x86/include/asm/preempt.h:7,
                 from ./include/linux/preempt.h:78,
                 from ./include/linux/spinlock.h:56,
                 from ./include/linux/mmzone.h:8,
                 from ./include/linux/gfp.h:7,
                 from ./include/linux/firmware.h:7,
                 from drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:26:
In function ‘fortify_memcpy_chk’,
    inlined from ‘sienna_cichlid_append_powerplay_table’ at drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:444:2,
    inlined from ‘sienna_cichlid_setup_pptable’ at drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:506:8,
    inlined from ‘sienna_cichlid_setup_pptable’ at drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/sienna_cichlid_ppt.c:494:12:
./include/linux/fortify-string.h:413:4: warning: call to ‘__read_overflow2_field’ declared with attribute warning: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning]
  413 |    __read_overflow2_field(q_size_field, size);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the compiler complains about the size calculation in the memcpy() -
"sizeof(*smc_dpm_table) - sizeof(smc_dpm_table->table_header)" is much
larger than what fits into table_member.

Hence, reuse 'smu_memcpy_trailing' for nv1x

Fixes: 7077b19a38240 ("drm/amd/pm: use macro to get pptable members")
Suggested-by: Evan Quan <Evan.Quan@amd.com>
Cc: Evan Quan <Evan.Quan@amd.com>
Cc: Chengming Gui <Jack.Gui@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Evan Quan <evan.quan@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

index 85d5359..f7ed3e6 100644 (file)
@@ -431,7 +431,13 @@ static int sienna_cichlid_append_powerplay_table(struct smu_context *smu)
 {
        struct atom_smc_dpm_info_v4_9 *smc_dpm_table;
        int index, ret;
-       I2cControllerConfig_t *table_member;
+       PPTable_beige_goby_t *ppt_beige_goby;
+       PPTable_t *ppt;
+
+       if (smu->adev->ip_versions[MP1_HWIP][0] == IP_VERSION(11, 0, 13))
+               ppt_beige_goby = smu->smu_table.driver_pptable;
+       else
+               ppt = smu->smu_table.driver_pptable;
 
        index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
                                            smc_dpm_info);
@@ -440,9 +446,13 @@ static int sienna_cichlid_append_powerplay_table(struct smu_context *smu)
                                      (uint8_t **)&smc_dpm_table);
        if (ret)
                return ret;
-       GET_PPTABLE_MEMBER(I2cControllers, &table_member);
-       memcpy(table_member, smc_dpm_table->I2cControllers,
-                       sizeof(*smc_dpm_table) - sizeof(smc_dpm_table->table_header));
+
+       if (smu->adev->ip_versions[MP1_HWIP][0] == IP_VERSION(11, 0, 13))
+               smu_memcpy_trailing(ppt_beige_goby, I2cControllers, BoardReserved,
+                                   smc_dpm_table, I2cControllers);
+       else
+               smu_memcpy_trailing(ppt, I2cControllers, BoardReserved,
+                                   smc_dpm_table, I2cControllers);
 
        return 0;
 }