linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: apple: rtkit: Export non-devm init/free functions
@ 2023-01-21  7:41 Asahi Lina
  2023-01-22 10:18 ` Sven Peter
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Asahi Lina @ 2023-01-21  7:41 UTC (permalink / raw)
  To: Hector Martin, Sven Peter
  Cc: Alyssa Rosenzweig, asahi, linux-arm-kernel, linux-kernel, Asahi Lina

While we normally encourage devm usage by drivers, some consumers (and
in particular the upcoming Rust abstractions) might want to manually
manage memory. Export the raw functions to make this possible.

Signed-off-by: Asahi Lina <lina@asahilina.net>
---
 drivers/soc/apple/rtkit.c       | 15 ++++++++++-----
 include/linux/soc/apple/rtkit.h | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
index fa3cda831d2b..bb33f3cd4efd 100644
--- a/drivers/soc/apple/rtkit.c
+++ b/drivers/soc/apple/rtkit.c
@@ -686,7 +686,7 @@ static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
 	return mbox_start_channel(rtk->mbox_chan);
 }
 
-static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
+struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
 					    const char *mbox_name, int mbox_idx,
 					    const struct apple_rtkit_ops *ops)
 {
@@ -739,6 +739,7 @@ static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
 	kfree(rtk);
 	return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(apple_rtkit_init);
 
 static int apple_rtkit_wait_for_completion(struct completion *c)
 {
@@ -922,10 +923,8 @@ int apple_rtkit_wake(struct apple_rtkit *rtk)
 }
 EXPORT_SYMBOL_GPL(apple_rtkit_wake);
 
-static void apple_rtkit_free(void *data)
+void apple_rtkit_free(struct apple_rtkit *rtk)
 {
-	struct apple_rtkit *rtk = data;
-
 	mbox_free_channel(rtk->mbox_chan);
 	destroy_workqueue(rtk->wq);
 
@@ -936,6 +935,12 @@ static void apple_rtkit_free(void *data)
 	kfree(rtk->syslog_msg_buffer);
 	kfree(rtk);
 }
+EXPORT_SYMBOL_GPL(apple_rtkit_free);
+
+static void apple_rtkit_free_wrapper(void *data)
+{
+	apple_rtkit_free(data);
+}
 
 struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
 					  const char *mbox_name, int mbox_idx,
@@ -948,7 +953,7 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
 	if (IS_ERR(rtk))
 		return rtk;
 
-	ret = devm_add_action_or_reset(dev, apple_rtkit_free, rtk);
+	ret = devm_add_action_or_reset(dev, apple_rtkit_free_wrapper, rtk);
 	if (ret)
 		return ERR_PTR(ret);
 
diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h
index 2d837aa7b91f..62bfa37b5adb 100644
--- a/include/linux/soc/apple/rtkit.h
+++ b/include/linux/soc/apple/rtkit.h
@@ -77,6 +77,25 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
 					  const char *mbox_name, int mbox_idx,
 					  const struct apple_rtkit_ops *ops);
 
+/*
+ * Non-devm version of devm_apple_rtkit_init. Must be freed with
+ * apple_rtkit_free.
+ *
+ * @dev:         Pointer to the device node this coprocessor is assocated with
+ * @cookie:      opaque cookie passed to all functions defined in rtkit_ops
+ * @mbox_name:   mailbox name used to communicate with the co-processor
+ * @mbox_idx:    mailbox index to be used if mbox_name is NULL
+ * @ops:         pointer to rtkit_ops to be used for this co-processor
+ */
+struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
+					  const char *mbox_name, int mbox_idx,
+					  const struct apple_rtkit_ops *ops);
+
+/*
+ * Free an instance of apple_rtkit.
+ */
+void apple_rtkit_free(struct apple_rtkit *rtk);
+
 /*
  * Reinitialize internal structures. Must only be called with the co-processor
  * is held in reset.
-- 
2.35.1


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

* Re: [PATCH] soc: apple: rtkit: Export non-devm init/free functions
  2023-01-21  7:41 [PATCH] soc: apple: rtkit: Export non-devm init/free functions Asahi Lina
@ 2023-01-22 10:18 ` Sven Peter
  2023-01-22 12:16 ` Eric Curtin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sven Peter @ 2023-01-22 10:18 UTC (permalink / raw)
  To: Asahi Lina, Hector Martin
  Cc: Alyssa Rosenzweig, asahi, linux-arm-kernel, linux-kernel

On Sat, Jan 21, 2023, at 08:41, Asahi Lina wrote:
> While we normally encourage devm usage by drivers, some consumers (and
> in particular the upcoming Rust abstractions) might want to manually
> manage memory. Export the raw functions to make this possible.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>

Reviewed-by: Sven Peter <sven@svenpeter.dev>

thanks,

Sven

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

* Re: [PATCH] soc: apple: rtkit: Export non-devm init/free functions
  2023-01-21  7:41 [PATCH] soc: apple: rtkit: Export non-devm init/free functions Asahi Lina
  2023-01-22 10:18 ` Sven Peter
@ 2023-01-22 12:16 ` Eric Curtin
  2023-01-22 18:05 ` Eric Curtin
  2023-01-31 11:44 ` Hector Martin
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Curtin @ 2023-01-22 12:16 UTC (permalink / raw)
  To: Asahi Lina
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, asahi,
	linux-arm-kernel, linux-kernel

On Sat, 21 Jan 2023 at 07:48, Asahi Lina <lina@asahilina.net> wrote:
>
> While we normally encourage devm usage by drivers, some consumers (and
> in particular the upcoming Rust abstractions) might want to manually
> manage memory. Export the raw functions to make this possible.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---

Signed-off-by: Eric Curtin <ecurtin@redhat.com>

Is mise le meas/Regards,

Eric Curtin

>  drivers/soc/apple/rtkit.c       | 15 ++++++++++-----
>  include/linux/soc/apple/rtkit.h | 19 +++++++++++++++++++
>  2 files changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
> index fa3cda831d2b..bb33f3cd4efd 100644
> --- a/drivers/soc/apple/rtkit.c
> +++ b/drivers/soc/apple/rtkit.c
> @@ -686,7 +686,7 @@ static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
>         return mbox_start_channel(rtk->mbox_chan);
>  }
>
> -static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
> +struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
>                                             const char *mbox_name, int mbox_idx,
>                                             const struct apple_rtkit_ops *ops)
>  {
> @@ -739,6 +739,7 @@ static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
>         kfree(rtk);
>         return ERR_PTR(ret);
>  }
> +EXPORT_SYMBOL_GPL(apple_rtkit_init);
>
>  static int apple_rtkit_wait_for_completion(struct completion *c)
>  {
> @@ -922,10 +923,8 @@ int apple_rtkit_wake(struct apple_rtkit *rtk)
>  }
>  EXPORT_SYMBOL_GPL(apple_rtkit_wake);
>
> -static void apple_rtkit_free(void *data)
> +void apple_rtkit_free(struct apple_rtkit *rtk)
>  {
> -       struct apple_rtkit *rtk = data;
> -
>         mbox_free_channel(rtk->mbox_chan);
>         destroy_workqueue(rtk->wq);
>
> @@ -936,6 +935,12 @@ static void apple_rtkit_free(void *data)
>         kfree(rtk->syslog_msg_buffer);
>         kfree(rtk);
>  }
> +EXPORT_SYMBOL_GPL(apple_rtkit_free);
> +
> +static void apple_rtkit_free_wrapper(void *data)
> +{
> +       apple_rtkit_free(data);
> +}
>
>  struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
>                                           const char *mbox_name, int mbox_idx,
> @@ -948,7 +953,7 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
>         if (IS_ERR(rtk))
>                 return rtk;
>
> -       ret = devm_add_action_or_reset(dev, apple_rtkit_free, rtk);
> +       ret = devm_add_action_or_reset(dev, apple_rtkit_free_wrapper, rtk);
>         if (ret)
>                 return ERR_PTR(ret);
>
> diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h
> index 2d837aa7b91f..62bfa37b5adb 100644
> --- a/include/linux/soc/apple/rtkit.h
> +++ b/include/linux/soc/apple/rtkit.h
> @@ -77,6 +77,25 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
>                                           const char *mbox_name, int mbox_idx,
>                                           const struct apple_rtkit_ops *ops);
>
> +/*
> + * Non-devm version of devm_apple_rtkit_init. Must be freed with
> + * apple_rtkit_free.
> + *
> + * @dev:         Pointer to the device node this coprocessor is assocated with
> + * @cookie:      opaque cookie passed to all functions defined in rtkit_ops
> + * @mbox_name:   mailbox name used to communicate with the co-processor
> + * @mbox_idx:    mailbox index to be used if mbox_name is NULL
> + * @ops:         pointer to rtkit_ops to be used for this co-processor
> + */
> +struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
> +                                         const char *mbox_name, int mbox_idx,
> +                                         const struct apple_rtkit_ops *ops);
> +
> +/*
> + * Free an instance of apple_rtkit.
> + */
> +void apple_rtkit_free(struct apple_rtkit *rtk);
> +
>  /*
>   * Reinitialize internal structures. Must only be called with the co-processor
>   * is held in reset.
> --
> 2.35.1
>
>


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

* Re: [PATCH] soc: apple: rtkit: Export non-devm init/free functions
  2023-01-21  7:41 [PATCH] soc: apple: rtkit: Export non-devm init/free functions Asahi Lina
  2023-01-22 10:18 ` Sven Peter
  2023-01-22 12:16 ` Eric Curtin
@ 2023-01-22 18:05 ` Eric Curtin
  2023-01-31 11:44 ` Hector Martin
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Curtin @ 2023-01-22 18:05 UTC (permalink / raw)
  To: Asahi Lina
  Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, asahi,
	linux-arm-kernel, linux-kernel

On Sat, 21 Jan 2023 at 07:48, Asahi Lina <lina@asahilina.net> wrote:
>
> While we normally encourage devm usage by drivers, some consumers (and
> in particular the upcoming Rust abstractions) might want to manually
> manage memory. Export the raw functions to make this possible.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---

Reviewed-by: Eric Curtin <ecurtin@redhat.com>

Is mise le meas/Regards,

Eric Curtin


>  drivers/soc/apple/rtkit.c       | 15 ++++++++++-----
>  include/linux/soc/apple/rtkit.h | 19 +++++++++++++++++++
>  2 files changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
> index fa3cda831d2b..bb33f3cd4efd 100644
> --- a/drivers/soc/apple/rtkit.c
> +++ b/drivers/soc/apple/rtkit.c
> @@ -686,7 +686,7 @@ static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
>         return mbox_start_channel(rtk->mbox_chan);
>  }
>
> -static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
> +struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
>                                             const char *mbox_name, int mbox_idx,
>                                             const struct apple_rtkit_ops *ops)
>  {
> @@ -739,6 +739,7 @@ static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
>         kfree(rtk);
>         return ERR_PTR(ret);
>  }
> +EXPORT_SYMBOL_GPL(apple_rtkit_init);
>
>  static int apple_rtkit_wait_for_completion(struct completion *c)
>  {
> @@ -922,10 +923,8 @@ int apple_rtkit_wake(struct apple_rtkit *rtk)
>  }
>  EXPORT_SYMBOL_GPL(apple_rtkit_wake);
>
> -static void apple_rtkit_free(void *data)
> +void apple_rtkit_free(struct apple_rtkit *rtk)
>  {
> -       struct apple_rtkit *rtk = data;
> -
>         mbox_free_channel(rtk->mbox_chan);
>         destroy_workqueue(rtk->wq);
>
> @@ -936,6 +935,12 @@ static void apple_rtkit_free(void *data)
>         kfree(rtk->syslog_msg_buffer);
>         kfree(rtk);
>  }
> +EXPORT_SYMBOL_GPL(apple_rtkit_free);
> +
> +static void apple_rtkit_free_wrapper(void *data)
> +{
> +       apple_rtkit_free(data);
> +}
>
>  struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
>                                           const char *mbox_name, int mbox_idx,
> @@ -948,7 +953,7 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
>         if (IS_ERR(rtk))
>                 return rtk;
>
> -       ret = devm_add_action_or_reset(dev, apple_rtkit_free, rtk);
> +       ret = devm_add_action_or_reset(dev, apple_rtkit_free_wrapper, rtk);
>         if (ret)
>                 return ERR_PTR(ret);
>
> diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h
> index 2d837aa7b91f..62bfa37b5adb 100644
> --- a/include/linux/soc/apple/rtkit.h
> +++ b/include/linux/soc/apple/rtkit.h
> @@ -77,6 +77,25 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
>                                           const char *mbox_name, int mbox_idx,
>                                           const struct apple_rtkit_ops *ops);
>
> +/*
> + * Non-devm version of devm_apple_rtkit_init. Must be freed with
> + * apple_rtkit_free.
> + *
> + * @dev:         Pointer to the device node this coprocessor is assocated with
> + * @cookie:      opaque cookie passed to all functions defined in rtkit_ops
> + * @mbox_name:   mailbox name used to communicate with the co-processor
> + * @mbox_idx:    mailbox index to be used if mbox_name is NULL
> + * @ops:         pointer to rtkit_ops to be used for this co-processor
> + */
> +struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
> +                                         const char *mbox_name, int mbox_idx,
> +                                         const struct apple_rtkit_ops *ops);
> +
> +/*
> + * Free an instance of apple_rtkit.
> + */
> +void apple_rtkit_free(struct apple_rtkit *rtk);
> +
>  /*
>   * Reinitialize internal structures. Must only be called with the co-processor
>   * is held in reset.
> --
> 2.35.1
>
>


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

* Re: [PATCH] soc: apple: rtkit: Export non-devm init/free functions
  2023-01-21  7:41 [PATCH] soc: apple: rtkit: Export non-devm init/free functions Asahi Lina
                   ` (2 preceding siblings ...)
  2023-01-22 18:05 ` Eric Curtin
@ 2023-01-31 11:44 ` Hector Martin
  3 siblings, 0 replies; 5+ messages in thread
From: Hector Martin @ 2023-01-31 11:44 UTC (permalink / raw)
  To: Asahi Lina, Sven Peter
  Cc: Alyssa Rosenzweig, asahi, linux-arm-kernel, linux-kernel

On 21/01/2023 16.41, Asahi Lina wrote:
> While we normally encourage devm usage by drivers, some consumers (and
> in particular the upcoming Rust abstractions) might want to manually
> manage memory. Export the raw functions to make this possible.
> 
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
>  drivers/soc/apple/rtkit.c       | 15 ++++++++++-----
>  include/linux/soc/apple/rtkit.h | 19 +++++++++++++++++++
>  2 files changed, 29 insertions(+), 5 deletions(-)
> 

Thanks, applied to asahi-soc/soc!

> diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
> index fa3cda831d2b..bb33f3cd4efd 100644
> --- a/drivers/soc/apple/rtkit.c
> +++ b/drivers/soc/apple/rtkit.c
> @@ -686,7 +686,7 @@ static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
>  	return mbox_start_channel(rtk->mbox_chan);
>  }
>  
> -static struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
> +struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
>  					    const char *mbox_name, int mbox_idx,
>  					    const struct apple_rtkit_ops *ops)
>  {

FYI: This hunk didn't apply cleanly on the upstream tree due to a
context difference in apple_rtkit_request_mbox_chan (I think you based
this on some other change), but it was easy enough to fix.

- Hector

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

end of thread, other threads:[~2023-01-31 11:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21  7:41 [PATCH] soc: apple: rtkit: Export non-devm init/free functions Asahi Lina
2023-01-22 10:18 ` Sven Peter
2023-01-22 12:16 ` Eric Curtin
2023-01-22 18:05 ` Eric Curtin
2023-01-31 11:44 ` Hector Martin

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