Commit 233323f
ACPI: processor_idle: Fix invalid comparison with insertion sort for latency
The acpi_cst_latency_cmp() comparison function currently used for
sorting C-state latencies does not satisfy transitivity, causing
incorrect sorting results.
Specifically, if there are two valid acpi_processor_cx elements A and B
and one invalid element C, it may occur that A < B, A = C, and B = C.
Sorting algorithms assume that if A < B and A = C, then C < B, leading
to incorrect ordering.
Given the small size of the array (<=8), we replace the library sort
function with a simple insertion sort that properly ignores invalid
elements and sorts valid ones based on latency. This change ensures
correct ordering of the C-state latencies.
Fixes: 65ea8f2 ("ACPI: processor idle: Fix up C-state latency if not ordered")
Reported-by: Julian Sikorski <[email protected]>
Closes: https://lore.kernel.org/lkml/[email protected]
Signed-off-by: Kuan-Wei Chiu <[email protected]>
Tested-by: Julian Sikorski <[email protected]>
Cc: All applicable <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Rafael J. Wysocki <[email protected]>1 parent 22a40d1 commit 233323f
1 file changed
+16
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
386 | 385 | | |
387 | 386 | | |
388 | 387 | | |
389 | | - | |
| 388 | + | |
390 | 389 | | |
391 | | - | |
| 390 | + | |
392 | 391 | | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
404 | 395 | | |
405 | | - | |
406 | | - | |
407 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
408 | 406 | | |
409 | 407 | | |
410 | 408 | | |
| |||
449 | 447 | | |
450 | 448 | | |
451 | 449 | | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
| 450 | + | |
456 | 451 | | |
457 | 452 | | |
458 | 453 | | |
| |||
0 commit comments