Subject: Re: [PATCH] devlink/param: replace deprecated strcpy() with strscpy()

From: David Laight <[email-masked]>
Date: Thu, 7 May 2026 09:04:45 +0100

On Wed,  6 May 2026 18:14:11 -0300
Álvaro Costa <[email-masked]> wrote:

> Replace strcpy() call used to extract a string parameter from param_data
> with strscpy(). Since strscpy() already performs bounds checking and
> ensures the destination string is NUL-terminated, remove the string
> length check as well.
> 
> Signed-off-by: Álvaro Costa <[email-masked]>
> ---
>  net/devlink/param.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/net/devlink/param.c b/net/devlink/param.c
> index cf95268da5b0..26695b7e2861 100644
> --- a/net/devlink/param.c
> +++ b/net/devlink/param.c
> @@ -536,11 +536,9 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
>  		value->vu64 = nla_get_u64(param_data);
>  		break;
>  	case DEVLINK_PARAM_TYPE_STRING:
> -		len = strnlen(nla_data(param_data), nla_len(param_data));
> -		if (len == nla_len(param_data) ||
> -		    len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
> +		len = strscpy(value->vstr, nla_data(param_data));
> +		if (len < 0)
>  			return -EINVAL;
> -		strcpy(value->vstr, nla_data(param_data));

The only sensible thing here is to replace the strcpy() with:
		memcpy(value->vstr, nla_data(param_data), len + 1);

-- David

>  		break;
>  	case DEVLINK_PARAM_TYPE_BOOL:
>  		if (param_data && nla_len(param_data))