[PATCH] drm/amdgpu: Declare array with strings as pointers constant

Christian König ckoenig.leichtzumerken at gmail.com
Mon Sep 4 08:43:21 UTC 2023


Am 03.09.23 um 08:05 schrieb Srinivasan Shanmugam:
> This warning is for the declaration of a static array, and it is
> recommended to declare it as type "static const char * const" instead of
> "static const char *".
>
> an array pointer declared as type "static const char *" can point to a
> different character constant because the pointer is mutable. However, if
> it is declared as type "static const char * const", the pointer will
> point to an immutable character constant, preventing it from being
> modified which can better ensure the safety and stability of the
> program.
>
> Fixes the below:
>
> WARNING: static const char * array should probably be static const char * const
>
> Cc: Christian König <christian.koenig at amd.com>
> Cc: Alex Deucher <alexander.deucher at amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan at amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>

Reviewed-by: Christian König <christian.koenig at amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 6 +++---
>   drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c | 4 ++--
>   2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> index 458faf657042..5c85ac34360f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> @@ -6454,7 +6454,7 @@ static int gfx_v9_0_ras_error_inject(struct amdgpu_device *adev,
>   	return ret;
>   }
>   
> -static const char *vml2_mems[] = {
> +static const char * const vml2_mems[] = {
>   	"UTC_VML2_BANK_CACHE_0_BIGK_MEM0",
>   	"UTC_VML2_BANK_CACHE_0_BIGK_MEM1",
>   	"UTC_VML2_BANK_CACHE_0_4K_MEM0",
> @@ -6473,7 +6473,7 @@ static const char *vml2_mems[] = {
>   	"UTC_VML2_BANK_CACHE_3_4K_MEM1",
>   };
>   
> -static const char *vml2_walker_mems[] = {
> +static const char * const vml2_walker_mems[] = {
>   	"UTC_VML2_CACHE_PDE0_MEM0",
>   	"UTC_VML2_CACHE_PDE0_MEM1",
>   	"UTC_VML2_CACHE_PDE1_MEM0",
> @@ -6483,7 +6483,7 @@ static const char *vml2_walker_mems[] = {
>   	"UTC_VML2_RDIF_LOG_FIFO",
>   };
>   
> -static const char *atc_l2_cache_2m_mems[] = {
> +static const char * const atc_l2_cache_2m_mems[] = {
>   	"UTC_ATCL2_CACHE_2M_BANK0_WAY0_MEM",
>   	"UTC_ATCL2_CACHE_2M_BANK0_WAY1_MEM",
>   	"UTC_ATCL2_CACHE_2M_BANK1_WAY0_MEM",
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c
> index 63f6843a069e..e7ae37233234 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c
> @@ -1548,8 +1548,8 @@ static void gfx_v9_4_2_log_utc_edc_count(struct amdgpu_device *adev,
>   					 uint32_t ded_cnt)
>   {
>   	uint32_t bank, way, mem;
> -	static const char *vml2_way_str[] = { "BIGK", "4K" };
> -	static const char *utcl2_rounter_str[] = { "VMC", "APT" };
> +	static const char * const vml2_way_str[] = { "BIGK", "4K" };
> +	static const char * const utcl2_rounter_str[] = { "VMC", "APT" };
>   
>   	mem = instance % blk->num_mem_blocks;
>   	way = (instance / blk->num_mem_blocks) % blk->num_ways;



More information about the amd-gfx mailing list