linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] keys: Remove unnecessary local variable from proc_keys_show
       [not found] <20251023143231.2086-2-thorsten.blum@linux.dev>
@ 2025-10-23 14:32 ` Thorsten Blum
  2025-10-27 19:54   ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-10-23 14:32 UTC (permalink / raw)
  To: David Howells, Jarkko Sakkinen, Paul Moore, James Morris,
	Serge E. Hallyn
  Cc: Thorsten Blum, keyrings, linux-security-module, linux-kernel

The local variable 'rc' is only used to temporary store the result of
calling key_task_permission(). Use the result directly and remove the
local variable.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 security/keys/proc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/security/keys/proc.c b/security/keys/proc.c
index 4f4e2c1824f1..39af57af2aad 100644
--- a/security/keys/proc.c
+++ b/security/keys/proc.c
@@ -160,7 +160,6 @@ static int proc_keys_show(struct seq_file *m, void *v)
 	char xbuf[16];
 	short state;
 	u64 timo;
-	int rc;
 
 	struct keyring_search_context ctx = {
 		.index_key		= key->index_key,
@@ -188,8 +187,7 @@ static int proc_keys_show(struct seq_file *m, void *v)
 	}
 
 	/* check whether the current task is allowed to view the key */
-	rc = key_task_permission(key_ref, ctx.cred, KEY_NEED_VIEW);
-	if (rc < 0)
+	if (key_task_permission(key_ref, ctx.cred, KEY_NEED_VIEW) < 0)
 		return 0;
 
 	now = ktime_get_real_seconds();
-- 
2.51.0


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

* Re: [PATCH 2/2] keys: Remove unnecessary local variable from proc_keys_show
  2025-10-23 14:32 ` [PATCH 2/2] keys: Remove unnecessary local variable from proc_keys_show Thorsten Blum
@ 2025-10-27 19:54   ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2025-10-27 19:54 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: David Howells, Paul Moore, James Morris, Serge E. Hallyn,
	keyrings, linux-security-module, linux-kernel

On Thu, Oct 23, 2025 at 04:32:33PM +0200, Thorsten Blum wrote:
> The local variable 'rc' is only used to temporary store the result of
> calling key_task_permission(). Use the result directly and remove the
> local variable.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  security/keys/proc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/security/keys/proc.c b/security/keys/proc.c
> index 4f4e2c1824f1..39af57af2aad 100644
> --- a/security/keys/proc.c
> +++ b/security/keys/proc.c
> @@ -160,7 +160,6 @@ static int proc_keys_show(struct seq_file *m, void *v)
>  	char xbuf[16];
>  	short state;
>  	u64 timo;
> -	int rc;
>  
>  	struct keyring_search_context ctx = {
>  		.index_key		= key->index_key,
> @@ -188,8 +187,7 @@ static int proc_keys_show(struct seq_file *m, void *v)
>  	}
>  
>  	/* check whether the current task is allowed to view the key */
> -	rc = key_task_permission(key_ref, ctx.cred, KEY_NEED_VIEW);
> -	if (rc < 0)
> +	if (key_task_permission(key_ref, ctx.cred, KEY_NEED_VIEW) < 0)
>  		return 0;

I absolutely dislike combining return value check to the call.

The old version documents that we ignore the return value, which
is convoluted in the new version.

>  
>  	now = ktime_get_real_seconds();
> -- 
> 2.51.0
> 

BR, Jarkko

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

end of thread, other threads:[~2025-10-27 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20251023143231.2086-2-thorsten.blum@linux.dev>
2025-10-23 14:32 ` [PATCH 2/2] keys: Remove unnecessary local variable from proc_keys_show Thorsten Blum
2025-10-27 19:54   ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).