[PATCH] powerpc/powernv/idle: Fix build error

Michael Ellerman mpe at ellerman.id.au
Fri Aug 10 17:10:45 AEST 2018


"Aneesh Kumar K.V" <aneesh.kumar at linux.ibm.com> writes:

> Fix the below build error using strlcpy instead of strncpy
>
> In function 'pnv_parse_cpuidle_dt',
>     inlined from 'pnv_init_idle_states' at arch/powerpc/platforms/powernv/idle.c:840:7,
>     inlined from '__machine_initcall_powernv_pnv_init_idle_states' at arch/powerpc/platforms/powernv/idle.c:870:1:
> arch/powerpc/platforms/powernv/idle.c:820:3: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation]
>    strncpy(pnv_idle_states[i].name, temp_string[i],
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     PNV_IDLE_NAME_LEN);

I'm curious why I haven't seen this? What compiler are you using?

cheers

> diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
> index ecb002c5db83..35f699ebb662 100644
> --- a/arch/powerpc/platforms/powernv/idle.c
> +++ b/arch/powerpc/platforms/powernv/idle.c
> @@ -817,7 +817,7 @@ static int pnv_parse_cpuidle_dt(void)
>  		goto out;
>  	}
>  	for (i = 0; i < nr_idle_states; i++)
> -		strncpy(pnv_idle_states[i].name, temp_string[i],
> +		strlcpy(pnv_idle_states[i].name, temp_string[i],
>  			PNV_IDLE_NAME_LEN);
>  	nr_pnv_idle_states = nr_idle_states;
>  	rc = 0;
> -- 
> 2.17.1


More information about the Linuxppc-dev mailing list