drm/amd/display: Use switch table for dc_to_smu_clock_type
Subsystems (3)
PATCH 1/1 drm/amd/display: Use switch table for dc_to_smu_clock_type
From: Leo Li <[email protected]>
Using a static int array will cause errors if the given dm_pp_clk_type is out-of-bounds. For robustness, use a switch table, with a default case to handle all invalid values.
--- .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +26 -12
@@ -152,18 +152,32 @@ static void get_default_clock_levels(static enum smu_clk_type dc_to_smu_clock_type (enum dm_pp_clock_type dm_pp_clk_type) { -#define DCCLK_MAP_SMUCLK (dcclk, smuclk) \ - [dcclk] = smuclk - -static int dc_clk_type_map[] = { -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DISPLAY_CLK ,SMU_DISPCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_ENGINE_CLK ,SMU_GFXCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_MEMORY_CLK ,SMU_MCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DCEFCLK ,SMU_DCEFCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_SOCCLK ,SMU_SOCCLK ), - }; - -return dc_clk_type_map[dm_pp_clk_type]; +enum smu_clk_type smu_clk_type =0 ; + +switch (dm_pp_clk_type) { +case DM_PP_CLOCK_TYPE_DISPLAY_CLK : + smu_clk_type =SMU_DISPCLK ; +break ; +case DM_PP_CLOCK_TYPE_ENGINE_CLK : + smu_clk_type =SMU_GFXCLK ; +break ; +case DM_PP_CLOCK_TYPE_MEMORY_CLK : + smu_clk_type =SMU_MCLK ; +break ; +case DM_PP_CLOCK_TYPE_DCEFCLK : + smu_clk_type =SMU_DCEFCLK ; +break ; +case DM_PP_CLOCK_TYPE_SOCCLK : + smu_clk_type =SMU_SOCCLK ; +break ; +default : +DRM_ERROR ("DM_PPLIB: invalid clock type: %d!\n" , + dm_pp_clk_type); + smu_clk_type =0 ; +break ; + } + +return smu_clk_type; } static enum amd_pp_clock_type dc_to_pp_clock_type(
Signature · 6 lines
2.22.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 22 lines · On 7/25/19 1:40 PM, [email protected] wrote:
From: Leo Li <[email protected]>
Using a static int array will cause errors if the given
dm_pp_clk_typeis out-of-bounds. For robustness, use a switch table, with a default case to handle all invalid values.Signed-off-by Leo Li <[email protected]>--- .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +0
-3@@ -152,18 +152,32 @@ static void get_default_clock_levels(static enum smu_clk_type dc_to_smu_clock_type (enum dm_pp_clock_type dm_pp_clk_type) { -#define DCCLK_MAP_SMUCLK (dcclk, smuclk) \ - [dcclk] = smuclk -
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c static void get_default_clock_levels( · line 155
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +1
-9-static int dc_clk_type_map[] = { -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DISPLAY_CLK ,SMU_DISPCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_ENGINE_CLK ,SMU_GFXCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_MEMORY_CLK ,SMU_MCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DCEFCLK ,SMU_DCEFCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_SOCCLK ,SMU_SOCCLK ), - }; - -return dc_clk_type_map[dm_pp_clk_type]; +enum smu_clk_type smu_clk_type =0 ;
This shouldn't be 0, but an actual value from the enum.
Right now this modifies GFX clock if the clock is invalid, but we should probably be returning SMU_CLK_COUNT instead.
Nicholas Kazlauskas
Quoted 19 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +18
-0+ +switch (dm_pp_clk_type) { +case DM_PP_CLOCK_TYPE_DISPLAY_CLK : + smu_clk_type =SMU_DISPCLK ; +break ; +case DM_PP_CLOCK_TYPE_ENGINE_CLK : + smu_clk_type =SMU_GFXCLK ; +break ; +case DM_PP_CLOCK_TYPE_MEMORY_CLK : + smu_clk_type =SMU_MCLK ; +break ; +case DM_PP_CLOCK_TYPE_DCEFCLK : + smu_clk_type =SMU_DCEFCLK ; +break ; +case DM_PP_CLOCK_TYPE_SOCCLK : + smu_clk_type =SMU_SOCCLK ; +break ; +default :
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c static void get_default_clock_levels( · line 183
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +7
-0+DRM_ERROR ("DM_PPLIB: invalid clock type: %d!\n" , + dm_pp_clk_type); + smu_clk_type =0 ; +break ; + } + +return smu_clk_type; } static enum amd_pp_clock_type dc_to_pp_clock_type(
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 1/1 drm/amd/display: Use switch table for dc_to_smu_clock_type
In reply to a message not in the archiveFrom: Leo Li <[email protected]>
Using a static int array will cause errors if the given dm_pp_clk_type is out-of-bounds. For robustness, use a switch table, with a default case to handle all invalid values.
v2: 0 is a valid clock type for smu_clk_type. Return SMU_CLK_COUNT
instead on invalid mapping.
--- .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +25 -12
@@ -152,18 +152,31 @@ static void get_default_clock_levels(static enum smu_clk_type dc_to_smu_clock_type (enum dm_pp_clock_type dm_pp_clk_type) { -#define DCCLK_MAP_SMUCLK (dcclk, smuclk) \ - [dcclk] = smuclk - -static int dc_clk_type_map[] = { -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DISPLAY_CLK ,SMU_DISPCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_ENGINE_CLK ,SMU_GFXCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_MEMORY_CLK ,SMU_MCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DCEFCLK ,SMU_DCEFCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_SOCCLK ,SMU_SOCCLK ), - }; - -return dc_clk_type_map[dm_pp_clk_type]; +enum smu_clk_type smu_clk_type =SMU_CLK_COUNT ; + +switch (dm_pp_clk_type) { +case DM_PP_CLOCK_TYPE_DISPLAY_CLK : + smu_clk_type =SMU_DISPCLK ; +break ; +case DM_PP_CLOCK_TYPE_ENGINE_CLK : + smu_clk_type =SMU_GFXCLK ; +break ; +case DM_PP_CLOCK_TYPE_MEMORY_CLK : + smu_clk_type =SMU_MCLK ; +break ; +case DM_PP_CLOCK_TYPE_DCEFCLK : + smu_clk_type =SMU_DCEFCLK ; +break ; +case DM_PP_CLOCK_TYPE_SOCCLK : + smu_clk_type =SMU_SOCCLK ; +break ; +default : +DRM_ERROR ("DM_PPLIB: invalid clock type: %d!\n" , + dm_pp_clk_type); +break ; + } + +return smu_clk_type; } static enum amd_pp_clock_type dc_to_pp_clock_type(
Signature · 6 lines
2.22.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Kazlauskas, Nicholas
Reviewed-by Nicholas KazlauskasQuoted 10 lines · On 7/25/19 1:57 PM, [email protected] wrote:
From: Leo Li <[email protected]>
Using a static int array will cause errors if the given
dm_pp_clk_typeis out-of-bounds. For robustness, use a switch table, with a default case to handle all invalid values.v2: 0 is a valid clock type for
smu_clk_type. ReturnSMU_CLK_COUNT
instead on invalid mapping.Signed-off-by Leo Li <[email protected]>
Quoted 43 lines
--- .../amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +18
-12@@ -152,18 +152,31 @@ static void get_default_clock_levels(static enum smu_clk_type dc_to_smu_clock_type (enum dm_pp_clock_type dm_pp_clk_type) { -#define DCCLK_MAP_SMUCLK (dcclk, smuclk) \ - [dcclk] = smuclk - -static int dc_clk_type_map[] = { -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DISPLAY_CLK ,SMU_DISPCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_ENGINE_CLK ,SMU_GFXCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_MEMORY_CLK ,SMU_MCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_DCEFCLK ,SMU_DCEFCLK ), -DCCLK_MAP_SMUCLK (DM_PP_CLOCK_TYPE_SOCCLK ,SMU_SOCCLK ), - }; - -return dc_clk_type_map[dm_pp_clk_type]; +enum smu_clk_type smu_clk_type =SMU_CLK_COUNT ; + +switch (dm_pp_clk_type) { +case DM_PP_CLOCK_TYPE_DISPLAY_CLK : + smu_clk_type =SMU_DISPCLK ; +break ; +case DM_PP_CLOCK_TYPE_ENGINE_CLK : + smu_clk_type =SMU_GFXCLK ; +break ; +case DM_PP_CLOCK_TYPE_MEMORY_CLK : + smu_clk_type =SMU_MCLK ; +break ; +case DM_PP_CLOCK_TYPE_DCEFCLK : + smu_clk_type =SMU_DCEFCLK ; +break ; +case DM_PP_CLOCK_TYPE_SOCCLK : + smu_clk_type =SMU_SOCCLK ; +break ;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c static void get_default_clock_levels( · line 182
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_pp_smu.c +7
-0+default : +DRM_ERROR ("DM_PPLIB: invalid clock type: %d!\n" , + dm_pp_clk_type); +break ; + } + +return smu_clk_type; } static enum amd_pp_clock_type dc_to_pp_clock_type(
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx