keys: Remove return variable and length check to simplify user_read
Subsystems (2)
PATCH 1/1 keys: Remove return variable and length check to simplify user_read
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]>
--- security/keys/user_defined.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
security/keys/user_defined.c +3 -9
@@ -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);
Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Jarkko Sakkinen
maintainerQuoted 5 lines · Thorsten Blum
In
user_read(), remove the unnecessary return variable 'ret' and return ->datalen directly. Drop the redundant 'buflen > 0' check and usemin()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.
Quoted 36 lines
--- security/keys/user_defined.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)security/keys/user_defined.c +3
-9@@ -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);Signature · 2 lines
Thorsten Blum <[email protected]> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
BR, Jarkko