linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] security: keys: remove redundant assignment to key_ref
@ 2017-12-04 18:14 Colin King
  2017-12-05  0:18 ` James Morris
  2017-12-06 14:50 ` David Howells
  0 siblings, 2 replies; 5+ messages in thread
From: Colin King @ 2017-12-04 18:14 UTC (permalink / raw)
  To: David Howells, James Morris, Serge E . Hallyn, keyrings,
	linux-security-module
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Variable key_ref is being assigned a value that is never read;
key_ref is being re-assigned a few statements later.  Hence this
assignment is redundant and can be removed.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 security/keys/key.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/security/keys/key.c b/security/keys/key.c
index 66049183ad89..d97c9394b5dd 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -833,7 +833,6 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
 
 	key_check(keyring);
 
-	key_ref = ERR_PTR(-EPERM);
 	if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION))
 		restrict_link = keyring->restrict_link;
 
-- 
2.14.1

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

* Re: [PATCH] security: keys: remove redundant assignment to key_ref
  2017-12-04 18:14 [PATCH] security: keys: remove redundant assignment to key_ref Colin King
@ 2017-12-05  0:18 ` James Morris
  2017-12-06 14:50 ` David Howells
  1 sibling, 0 replies; 5+ messages in thread
From: James Morris @ 2017-12-05  0:18 UTC (permalink / raw)
  To: Colin King
  Cc: David Howells, Serge E . Hallyn, keyrings, linux-security-module,
	kernel-janitors, linux-kernel

On Mon, 4 Dec 2017, Colin King wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> Variable key_ref is being assigned a value that is never read;
> key_ref is being re-assigned a few statements later.  Hence this
> assignment is redundant and can be removed.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

I think a general cleanup in that function to make all of these follow the 
pattern:

	if (something) {
		key_ref = ERR_PTR(-error);
		goto error;
	}

rather than unconditionally setting the error first, would be better, but 
this is a clear enough fix on its own.

Reviewed-by: James Morris <james.l.morris@oracle.com>


-- 
James Morris
<james.l.morris@oracle.com>

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

* Re: [PATCH] security: keys: remove redundant assignment to key_ref
  2017-12-04 18:14 [PATCH] security: keys: remove redundant assignment to key_ref Colin King
  2017-12-05  0:18 ` James Morris
@ 2017-12-06 14:50 ` David Howells
  2017-12-06 14:53   ` Julia Lawall
  1 sibling, 1 reply; 5+ messages in thread
From: David Howells @ 2017-12-06 14:50 UTC (permalink / raw)
  To: James Morris
  Cc: dhowells, Colin King, Serge E . Hallyn, keyrings,
	linux-security-module, kernel-janitors, linux-kernel

James Morris <james.l.morris@oracle.com> wrote:

> I think a general cleanup in that function to make all of these follow the 
> pattern:
> 
> 	if (something) {
> 		key_ref = ERR_PTR(-error);
> 		goto error;
> 	}
> 
> rather than unconditionally setting the error first, would be better, but 
> this is a clear enough fix on its own.

There's a preference in Linux to use:

	key_ref = ERR_PTR(-error);
 	if (something)
 		goto error;

instead because it uses less vertical space.  It might originally have been
promulgated by Linus, but I don't remember.  Though you do have a point - your
way makes error handling less subject breakage from code rearrangement.

David

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

* Re: [PATCH] security: keys: remove redundant assignment to key_ref
  2017-12-06 14:50 ` David Howells
@ 2017-12-06 14:53   ` Julia Lawall
  2017-12-07  0:49     ` James Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2017-12-06 14:53 UTC (permalink / raw)
  To: David Howells
  Cc: James Morris, Colin King, Serge E . Hallyn, keyrings,
	linux-security-module, kernel-janitors, linux-kernel



On Wed, 6 Dec 2017, David Howells wrote:

> James Morris <james.l.morris@oracle.com> wrote:
>
> > I think a general cleanup in that function to make all of these follow the
> > pattern:
> >
> > 	if (something) {
> > 		key_ref = ERR_PTR(-error);
> > 		goto error;
> > 	}
> >
> > rather than unconditionally setting the error first, would be better, but
> > this is a clear enough fix on its own.
>
> There's a preference in Linux to use:
>
> 	key_ref = ERR_PTR(-error);
>  	if (something)
>  		goto error;
>
> instead because it uses less vertical space.  It might originally have been
> promulgated by Linus, but I don't remember.  Though you do have a point - your
> way makes error handling less subject breakage from code rearrangement.

I have the impression that there are many examples of both approaches.

julia

>
> David
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH] security: keys: remove redundant assignment to key_ref
  2017-12-06 14:53   ` Julia Lawall
@ 2017-12-07  0:49     ` James Morris
  0 siblings, 0 replies; 5+ messages in thread
From: James Morris @ 2017-12-07  0:49 UTC (permalink / raw)
  To: Julia Lawall
  Cc: David Howells, Colin King, Serge E . Hallyn, keyrings,
	linux-security-module, kernel-janitors, linux-kernel

On Wed, 6 Dec 2017, Julia Lawall wrote:

> > There's a preference in Linux to use:
> >
> > 	key_ref = ERR_PTR(-error);
> >  	if (something)
> >  		goto error;
> >
> > instead because it uses less vertical space.  It might originally have been
> > promulgated by Linus, but I don't remember.  Though you do have a point - your
> > way makes error handling less subject breakage from code rearrangement.
> 
> I have the impression that there are many examples of both approaches.

I thought this was mainly to set a default error condition once and then 
some call during the function sets it to zero on success.


-- 
James Morris
<james.l.morris@oracle.com>

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

end of thread, other threads:[~2017-12-07  0:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-04 18:14 [PATCH] security: keys: remove redundant assignment to key_ref Colin King
2017-12-05  0:18 ` James Morris
2017-12-06 14:50 ` David Howells
2017-12-06 14:53   ` Julia Lawall
2017-12-07  0:49     ` James Morris

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).