Skip to content

Commit 70246f8

Browse files
superm1ij-intel
authored andcommitted
ACPI: platform_profile: Check all profile handler to calculate next
As multiple platform profile handlers might not all support the same profile, cycling to the next profile could have a different result depending on what handler are registered. Check what is active and supported by all handlers to decide what to do. Reviewed-by: Armin Wolf <[email protected]> Tested-by: Mark Pearson <[email protected]> Reviewed-by: Mark Pearson <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent e836b7d commit 70246f8

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

drivers/acpi/platform_profile.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,37 @@ EXPORT_SYMBOL_GPL(platform_profile_notify);
418418

419419
int platform_profile_cycle(void)
420420
{
421-
enum platform_profile_option profile;
422-
enum platform_profile_option next;
421+
enum platform_profile_option next = PLATFORM_PROFILE_LAST;
422+
enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
423+
unsigned long choices[BITS_TO_LONGS(PLATFORM_PROFILE_LAST)];
423424
int err;
424425

426+
set_bit(PLATFORM_PROFILE_LAST, choices);
425427
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
426-
if (!cur_profile)
427-
return -ENODEV;
428+
err = class_for_each_device(&platform_profile_class, NULL,
429+
&profile, _aggregate_profiles);
430+
if (err)
431+
return err;
428432

429-
err = cur_profile->profile_get(cur_profile, &profile);
433+
if (profile == PLATFORM_PROFILE_CUSTOM ||
434+
profile == PLATFORM_PROFILE_LAST)
435+
return -EINVAL;
436+
437+
err = class_for_each_device(&platform_profile_class, NULL,
438+
choices, _aggregate_choices);
430439
if (err)
431440
return err;
432441

433-
next = find_next_bit_wrap(cur_profile->choices, PLATFORM_PROFILE_LAST,
442+
/* never iterate into a custom if all drivers supported it */
443+
clear_bit(PLATFORM_PROFILE_CUSTOM, choices);
444+
445+
next = find_next_bit_wrap(choices,
446+
PLATFORM_PROFILE_LAST,
434447
profile + 1);
435448

436-
if (WARN_ON(next == PLATFORM_PROFILE_LAST))
437-
return -EINVAL;
449+
err = class_for_each_device(&platform_profile_class, NULL, &next,
450+
_store_and_notify);
438451

439-
err = cur_profile->profile_set(cur_profile, next);
440452
if (err)
441453
return err;
442454
}

0 commit comments

Comments
 (0)