[bug report] drm/amd/pm: add the parameters of power profiles for vangogh

Dan Carpenter dan.carpenter at oracle.com
Tue Jan 12 09:10:22 UTC 2021


Hello Xiaojian Du,

The patch 307f049bfcad: "drm/amd/pm: add the parameters of power
profiles for vangogh" from Jan 7, 2021, leads to the following static
checker warning:

	drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/vangogh_ppt.c:801 vangogh_get_power_profile_mode()
	error: buffer overflow 'profile_name' 5 <= 6

drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu11/vangogh_ppt.c
   773  static int vangogh_get_power_profile_mode(struct smu_context *smu,
   774                                             char *buf)
   775  {
   776          static const char *profile_name[] = {
   777                                          "FULL_SCREEN_3D",
   778                                          "VIDEO",
   779                                          "VR",
   780                                          "COMPUTE",
   781                                          "CUSTOM"};

This list leaves out DEFAULT and POWERSAVING profiles, so I don't think
it's correct.

   782          uint32_t i, size = 0;
   783          int16_t workload_type = 0;
   784  
   785          if (!buf)
   786                  return -EINVAL;
   787  
   788          for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
   789                  /*
   790                   * Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT
   791                   * Not all profile modes are supported on vangogh.
   792                   */
   793                  workload_type = smu_cmn_to_asic_specific_index(smu,
   794                                                                 CMN2ASIC_MAPPING_WORKLOAD,
   795                                                                 i);
   796  
   797                  if (workload_type < 0)
   798                          continue;
   799  
   800                  size += sprintf(buf + size, "%2d %14s%s\n",
   801                          i, profile_name[i], (i == smu->power_profile_mode) ? "*" : " ");
                                   ^^^^^^^^^^^^^^^
Also it leads to an array overflow.

   802          }
   803  
   804          return size;
   805  }

regards,
dan carpenter


More information about the amd-gfx mailing list