KEYS: remove unnecessary get/put of explicit dest_keyring
Subsystems (2)
PATCH 1/1 KEYS: remove unnecessary get/put of explicit dest_keyring
From: Eric Biggers <[email protected]>
In request_key_and_link(), in the case where the dest_keyring was explicitly specified, there is no need to get another reference to dest_keyring before calling key_link(), then drop it afterwards. This is because by definition, we already have a reference to dest_keyring.
This change is useful because we'll be making construct_get_dest_keyring() able to return an error code, and we don't want to have to handle that error here for no reason.
--- security/keys/request_key.c | 2 -- 1 file changed, 2 deletions(-)
security/keys/request_key.c +0 -2
@@ -546,9 +546,7 @@ struct key *request_key_and_link(struct key_type *type,if (!IS_ERR (key_ref)) { key =key_ref_to_ptr (key_ref);if (dest_keyring) { -construct_get_dest_keyring (&dest_keyring); ret =key_link (dest_keyring, key); -key_put (dest_keyring);if (ret <0 ) {key_put (key); key =ERR_PTR (ret);
Signature · 1 line
2.15.0.448.gf294e3d99a-goog
David Howells
maintainersecurity/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549
Quoted 1 line · Eric Biggers
security/keys/request_key.c +0
-1-construct_get_dest_keyring (&dest_keyring);
This will break. construct_get_dest_keyring() does other things than just getting a ref on whatever dest_keyring points to.
David
Quoted 7 lines · David Howells
security/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549
Quoted 1 line · Eric Biggers
security/keys/request_key.c +0
-1-construct_get_dest_keyring (&dest_keyring);This will break.
construct_get_dest_keyring()does other things than just getting a ref on whateverdest_keyringpoints to.
Not if dest_keyring is non-NULL (i.e. explicitly specified), which it is in this case.
Eric
David Howells
maintainerQuoted 8 lines · Eric Biggers
Quoted 5 lines
security/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549
Quoted 1 line
security/keys/request_key.c +0
-1-construct_get_dest_keyring (&dest_keyring);This will break.
construct_get_dest_keyring()does other things than just getting a ref on whateverdest_keyringpoints to.Not if
dest_keyringis non-NULL (i.e. explicitly specified), which it is in this case.
Actually, you're right.
David
David Howells
maintainersecurity/keys/request_key.c struct key *request_key_and_link(struct key_type *type, · line 549
Quoted 2 lines · Eric Biggers
security/keys/request_key.c +0
-1if (dest_keyring) { -construct_get_dest_keyring (&dest_keyring);
Actually, I think I have the order of these lines inverted. construct_get_dest_keyring() can actually return without setting dest_keyring to anything. This didn't used to be the case, but now that the user-session keyring is made lazily, there's no guaranteed fallback.
David