]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ACPI: platform_profile: Add devm_platform_profile_register()
authorKurt Borja <kuurtb@gmail.com>
Tue, 24 Dec 2024 14:01:32 +0000 (09:01 -0500)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Sun, 29 Dec 2024 16:27:22 +0000 (18:27 +0200)
Platform profile's lifetime is usually tied to a device's lifetime,
therefore add a device managed version of platform_profile_register().

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20241224140131.30362-4-kuurtb@gmail.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/acpi/platform_profile.c
include/linux/platform_profile.h

index 75a1415190ace5cbe2bca203f7b705069bf69571..4c4200a0b1a6852b1e3a005084cad262548256af 100644 (file)
@@ -519,6 +519,35 @@ int platform_profile_remove(struct platform_profile_handler *pprof)
 }
 EXPORT_SYMBOL_GPL(platform_profile_remove);
 
+static void devm_platform_profile_release(struct device *dev, void *res)
+{
+       struct platform_profile_handler **pprof = res;
+
+       platform_profile_remove(*pprof);
+}
+
+int devm_platform_profile_register(struct platform_profile_handler *pprof)
+{
+       struct platform_profile_handler **dr;
+       int ret;
+
+       dr = devres_alloc(devm_platform_profile_release, sizeof(*dr), GFP_KERNEL);
+       if (!dr)
+               return -ENOMEM;
+
+       ret = platform_profile_register(pprof);
+       if (ret) {
+               devres_free(dr);
+               return ret;
+       }
+
+       *dr = pprof;
+       devres_add(pprof->dev, dr);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(devm_platform_profile_register);
+
 static int __init platform_profile_init(void)
 {
        int err;
index 0682bb4c57e5d690faa211bf205b4f4f5ef15794..f1cd4b65e351441db46a334875aa211a8e200807 100644 (file)
@@ -41,6 +41,7 @@ struct platform_profile_handler {
 
 int platform_profile_register(struct platform_profile_handler *pprof);
 int platform_profile_remove(struct platform_profile_handler *pprof);
+int devm_platform_profile_register(struct platform_profile_handler *pprof);
 int platform_profile_cycle(void);
 void platform_profile_notify(struct platform_profile_handler *pprof);