diff mbox series

[3/7] keys: Move key_get() out of line so a tracepoint can be added

Message ID 20240821123616.60401-4-dhowells@redhat.com (mailing list archive)
State New
Headers show
Series keys: Add tracepoints | expand

Commit Message

David Howells Aug. 21, 2024, 12:36 p.m. UTC
Move key_get() out of line so that a tracepoint can be added into it
without incurring circular header dependencies or overly expanding the
callers.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Jarkko Sakkinen <jarkko@kernel.org>
cc: keyrings@vger.kernel.org
cc: linux-security-module@vger.kernel.org
---
 include/linux/key.h |  6 +-----
 security/keys/key.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

Comments

Jarkko Sakkinen Aug. 27, 2024, 6:23 p.m. UTC | #1
On Wed Aug 21, 2024 at 3:36 PM EEST, David Howells wrote:
> Move key_get() out of line so that a tracepoint can be added into it
> without incurring circular header dependencies or overly expanding the
> callers.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Jarkko Sakkinen <jarkko@kernel.org>
> cc: keyrings@vger.kernel.org
> cc: linux-security-module@vger.kernel.org
> ---
>  include/linux/key.h |  6 +-----
>  security/keys/key.c | 14 ++++++++++++++
>  2 files changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/key.h b/include/linux/key.h
> index 943a432da3ae..08062b4f807c 100644
> --- a/include/linux/key.h
> +++ b/include/linux/key.h
> @@ -299,6 +299,7 @@ extern struct key *key_alloc(struct key_type *type,
>  
>  extern void key_revoke(struct key *key);
>  extern void key_invalidate(struct key *key);
> +struct key *key_get(struct key *key);
>  extern void key_put(struct key *key);
>  extern bool key_put_tag(struct key_tag *tag);
>  extern void key_remove_domain(struct key_tag *domain_tag);
> @@ -309,11 +310,6 @@ static inline struct key *__key_get(struct key *key)
>  	return key;
>  }
>  
> -static inline struct key *key_get(struct key *key)
> -{
> -	return key ? __key_get(key) : key;
> -}
> -
>  static inline void key_ref_put(key_ref_t key_ref)
>  {
>  	key_put(key_ref_to_ptr(key_ref));
> diff --git a/security/keys/key.c b/security/keys/key.c
> index 3d7d185019d3..14c7ee77ea15 100644
> --- a/security/keys/key.c
> +++ b/security/keys/key.c
> @@ -635,6 +635,20 @@ int key_reject_and_link(struct key *key,
>  }
>  EXPORT_SYMBOL(key_reject_and_link);
>  
> +/**
> + * key_get - Get a reference on a key
> + * @key: The key to get a reference on.
> + *
> + * Get a reference on a key, if not NULL, and return the parameter.
> + */
> +struct key *key_get(struct key *key)
> +{
> +	if (key)
> +		refcount_inc(&key->usage);
> +	return key;
> +}
> +EXPORT_SYMBOL(key_get);
> +
>  /**
>   * key_put - Discard a reference to a key.
>   * @key: The key to discard a reference from.


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko
diff mbox series

Patch

diff --git a/include/linux/key.h b/include/linux/key.h
index 943a432da3ae..08062b4f807c 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -299,6 +299,7 @@  extern struct key *key_alloc(struct key_type *type,
 
 extern void key_revoke(struct key *key);
 extern void key_invalidate(struct key *key);
+struct key *key_get(struct key *key);
 extern void key_put(struct key *key);
 extern bool key_put_tag(struct key_tag *tag);
 extern void key_remove_domain(struct key_tag *domain_tag);
@@ -309,11 +310,6 @@  static inline struct key *__key_get(struct key *key)
 	return key;
 }
 
-static inline struct key *key_get(struct key *key)
-{
-	return key ? __key_get(key) : key;
-}
-
 static inline void key_ref_put(key_ref_t key_ref)
 {
 	key_put(key_ref_to_ptr(key_ref));
diff --git a/security/keys/key.c b/security/keys/key.c
index 3d7d185019d3..14c7ee77ea15 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -635,6 +635,20 @@  int key_reject_and_link(struct key *key,
 }
 EXPORT_SYMBOL(key_reject_and_link);
 
+/**
+ * key_get - Get a reference on a key
+ * @key: The key to get a reference on.
+ *
+ * Get a reference on a key, if not NULL, and return the parameter.
+ */
+struct key *key_get(struct key *key)
+{
+	if (key)
+		refcount_inc(&key->usage);
+	return key;
+}
+EXPORT_SYMBOL(key_get);
+
 /**
  * key_put - Discard a reference to a key.
  * @key: The key to discard a reference from.