Skip to content

Commit 97488b9

Browse files
committed
Merge tag 'acpi-6.10-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI fix from Rafael Wysocki: "Fix the sorting of _CST output data in the ACPI processor idle driver (Kuan-Wei Chiu)" * tag 'acpi-6.10-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: ACPI: processor_idle: Fix invalid comparison with insertion sort for latency
2 parents 130abfe + 233323f commit 97488b9

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

drivers/acpi/processor_idle.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <linux/acpi.h>
1717
#include <linux/dmi.h>
1818
#include <linux/sched.h> /* need_resched() */
19-
#include <linux/sort.h>
2019
#include <linux/tick.h>
2120
#include <linux/cpuidle.h>
2221
#include <linux/cpu.h>
@@ -386,25 +385,24 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
386385
acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 1);
387386
}
388387

389-
static int acpi_cst_latency_cmp(const void *a, const void *b)
388+
static void acpi_cst_latency_sort(struct acpi_processor_cx *states, size_t length)
390389
{
391-
const struct acpi_processor_cx *x = a, *y = b;
390+
int i, j, k;
392391

393-
if (!(x->valid && y->valid))
394-
return 0;
395-
if (x->latency > y->latency)
396-
return 1;
397-
if (x->latency < y->latency)
398-
return -1;
399-
return 0;
400-
}
401-
static void acpi_cst_latency_swap(void *a, void *b, int n)
402-
{
403-
struct acpi_processor_cx *x = a, *y = b;
392+
for (i = 1; i < length; i++) {
393+
if (!states[i].valid)
394+
continue;
404395

405-
if (!(x->valid && y->valid))
406-
return;
407-
swap(x->latency, y->latency);
396+
for (j = i - 1, k = i; j >= 0; j--) {
397+
if (!states[j].valid)
398+
continue;
399+
400+
if (states[j].latency > states[k].latency)
401+
swap(states[j].latency, states[k].latency);
402+
403+
k = j;
404+
}
405+
}
408406
}
409407

410408
static int acpi_processor_power_verify(struct acpi_processor *pr)
@@ -449,10 +447,7 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
449447

450448
if (buggy_latency) {
451449
pr_notice("FW issue: working around C-state latencies out of order\n");
452-
sort(&pr->power.states[1], max_cstate,
453-
sizeof(struct acpi_processor_cx),
454-
acpi_cst_latency_cmp,
455-
acpi_cst_latency_swap);
450+
acpi_cst_latency_sort(&pr->power.states[1], max_cstate);
456451
}
457452

458453
lapic_timer_propagate_broadcast(pr);

0 commit comments

Comments
 (0)