Let drivers dynamically refresh selected choices safely, while holding `profile_lock`. Signed-off-by: Kurt Borja <kuurtb@xxxxxxxxx> --- drivers/acpi/platform_profile.c | 23 +++++++++++++++++++++++ include/linux/platform_profile.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c index ec749c2d0695..087280d786b1 100644 --- a/drivers/acpi/platform_profile.c +++ b/drivers/acpi/platform_profile.c @@ -459,6 +459,29 @@ int platform_profile_cycle(void) } EXPORT_SYMBOL_GPL(platform_profile_cycle); +int platform_profile_refresh_choices(struct platform_profile_handler *pprof) +{ + unsigned long backup[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)]; + int err; + + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) { + bitmap_copy(backup, pprof->choices, PLATFORM_PROFILE_LAST); + + err = pprof->ops->choices(pprof); + if (err) { + bitmap_copy(pprof->choices, backup, PLATFORM_PROFILE_LAST); + return err; + } + + _notify_class_profile(pprof->class_dev, NULL); + } + + sysfs_notify(acpi_kobj, NULL, "platform_profile"); + + return 0; +} +EXPORT_SYMBOL_GPL(platform_profile_refresh_choices); + int platform_profile_register(struct platform_profile_handler *pprof) { int err; diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h index 7f266a60b41a..7d543dd8c164 100644 --- a/include/linux/platform_profile.h +++ b/include/linux/platform_profile.h @@ -50,6 +50,7 @@ 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); +int platform_profile_refresh_choices(struct platform_profile_handler *pprof); void platform_profile_notify(struct platform_profile_handler *pprof); #endif /*_PLATFORM_PROFILE_H_*/ -- 2.47.1