public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] keys: Remove return variable and length check to simplify user_read
@ 2026-02-28  9:44 Thorsten Blum
  2026-03-04  0:10 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-02-28  9:44 UTC (permalink / raw)
  To: David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
	Serge E. Hallyn
  Cc: Thorsten Blum, keyrings, linux-security-module, linux-kernel

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 <thorsten.blum@linux.dev>
---
 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 <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-04  0:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-28  9:44 [PATCH] keys: Remove return variable and length check to simplify user_read Thorsten Blum
2026-03-04  0:10 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox