Re: [PATCH] keys: Remove return variable and length check to simplify user_read

Jarkko Sakkinen <[email protected]>
Newsgroups org.kernel.vger.keyrings,org.kernel.vger.linux-kernel,org.kernel.vger.linux-security-module
Message-ID <[email protected]>
On Sat, Feb 28, 2026 at 10:44:46AM +0100, Thorsten Blum wrote:
> In user_read(), remove the unnecessary return variable 'ret' and return
> ->datalen directly. Drop the redundant 'buflen > 0' check and use min()
> to determine the number of bytes to copy.  No functional changes.
> 
> Signed-off-by: Thorsten Blum <[email protected]>

Trivial cleanup commits with no function are not feasible. They only do
harm e.g., for backporting actual bug fixes.

> ---
>  security/keys/user_defined.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/security/keys/user_defined.c b/security/keys/user_defined.c
> index 6f88b507f927..b53e063272c2 100644
> --- a/security/keys/user_defined.c
> +++ b/security/keys/user_defined.c
> @@ -171,20 +171,14 @@ EXPORT_SYMBOL_GPL(user_describe);
>  long user_read(const struct key *key, char *buffer, size_t buflen)
>  {
>  	const struct user_key_payload *upayload;
> -	long ret;
>  
>  	upayload = user_key_payload_locked(key);
> -	ret = upayload->datalen;
>  
>  	/* we can return the data as is */
> -	if (buffer && buflen > 0) {
> -		if (buflen > upayload->datalen)
> -			buflen = upayload->datalen;
> +	if (buffer)
> +		memcpy(buffer, upayload->data, min(buflen, upayload->datalen));
>  
> -		memcpy(buffer, upayload->data, buflen);
> -	}
> -
> -	return ret;
> +	return upayload->datalen;
>  }
>  
>  EXPORT_SYMBOL_GPL(user_read);
> -- 
> Thorsten Blum <[email protected]>
> GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
> 

BR, Jarkko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.