soc: apple: rtkit: Export non-devm init/free functions
authorAsahi Lina <lina@asahilina.net>
Sat, 21 Jan 2023 07:41:35 +0000 (16:41 +0900)
committerHector Martin <marcan@marcan.st>
Tue, 31 Jan 2023 11:40:14 +0000 (20:40 +0900)
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>
Reviewed-by: Eric Curtin <ecurtin@redhat.com>
Signed-off-by: Hector Martin <marcan@marcan.st>
drivers/soc/apple/rtkit.c
include/linux/soc/apple/rtkit.h

index efb1fa77dff2fa728a0cf13a7f2e147614dab1dc..35ec35aa500d67334a81231d87eaab3c6e7547d3 100644 (file)
@@ -699,7 +699,7 @@ static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
        return 0;
 }
 
-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)
 {
@@ -751,6 +751,7 @@ free_rtk:
        kfree(rtk);
        return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(apple_rtkit_init);
 
 static int apple_rtkit_wait_for_completion(struct completion *c)
 {
@@ -947,10 +948,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);
 
@@ -961,6 +960,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,
@@ -973,7 +978,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);
 
index 927b214ef1c6fa0c1df732b660281d63ef64f634..fc456f75c13192a82307b31d2926b789a33a6c2a 100644 (file)
@@ -79,6 +79,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.