[merged mm-nonmm-stable] lib-sort-clarify-comparison-function-requirements-in-sort_r.patch removed from -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The quilt patch titled
     Subject: lib/sort: clarify comparison function requirements in sort_r()
has been removed from the -mm tree.  Its filename was
     lib-sort-clarify-comparison-function-requirements-in-sort_r.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch
of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Kuan-Wei Chiu <visitorckw@xxxxxxxxx>
Subject: lib/sort: clarify comparison function requirements in sort_r()
Date: Tue, 7 Jan 2025 01:01:03 +0800

Patch series "lib: clarify comparison function requirements", v2.

Add a detailed explanation in the sort_r/list_sort kernel doc comment
specifying that the comparison function must satisfy antisymmetry and
transitivity.  These properties are essential for the sorting algorithm to
produce correct results.

Issues have arisen in the past [1][2][3][4] where comparison functions
violated the transitivity property, causing sorting algorithms to fail to
correctly order elements.  While these requirements may seem
straightforward, they are commonly misunderstood or overlooked, leading to
bugs.  Highlighting these properties in the documentation will help
prevent such mistakes in the future.

Link: https://lore.kernel.org/lkml/20240701205639.117194-1-visitorckw@xxxxxxxxx [1]
Link: https://lore.kernel.org/lkml/20241203202228.1274403-1-visitorckw@xxxxxxxxx [2]
Link: https://lore.kernel.org/lkml/20241209134226.1939163-1-visitorckw@xxxxxxxxx [3]
Link: https://lore.kernel.org/lkml/20241209145728.1975311-1-visitorckw@xxxxxxxxx [4]


This patch (of 2):

Add a detailed explanation in the sort_r() kernel doc comment specifying
that the comparison function must satisfy antisymmetry and transitivity. 
These properties are essential for the sorting algorithm to produce
correct results.

Issues have arisen in the past [1][2][3][4] where comparison functions
violated the transitivity property, causing sorting algorithms to fail to
correctly order elements.  While these requirements may seem
straightforward, they are commonly misunderstood or overlooked, leading to
bugs.  Highlighting these properties in the documentation will help
prevent such mistakes in the future.

Link: https://lkml.kernel.org/r/20250106170104.3137845-1-visitorckw@xxxxxxxxx
Link: https://lore.kernel.org/lkml/20240701205639.117194-1-visitorckw@xxxxxxxxx [1]
Link: https://lore.kernel.org/lkml/20241203202228.1274403-1-visitorckw@xxxxxxxxx [2]
Link: https://lore.kernel.org/lkml/20241209134226.1939163-1-visitorckw@xxxxxxxxx [3]
Link: https://lore.kernel.org/lkml/20241209145728.1975311-1-visitorckw@xxxxxxxxx [4]
Link: https://lkml.kernel.org/r/20250106170104.3137845-2-visitorckw@xxxxxxxxx
Signed-off-by: Kuan-Wei Chiu <visitorckw@xxxxxxxxx>
Cc: Ching-Chun (Jim) Huang <jserv@xxxxxxxxxxxxxxxx>
Cc: <chuang@xxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 lib/sort.c |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/lib/sort.c~lib-sort-clarify-comparison-function-requirements-in-sort_r
+++ a/lib/sort.c
@@ -200,6 +200,13 @@ static size_t parent(size_t i, unsigned
  * copy (e.g. fix up pointers or auxiliary data), but the built-in swap
  * avoids a slow retpoline and so is significantly faster.
  *
+ * The comparison function must adhere to specific mathematical
+ * properties to ensure correct and stable sorting:
+ * - Antisymmetry: cmp_func(a, b) must return the opposite sign of
+ * cmp_func(b, a).
+ * - Transitivity: if cmp_func(a, b) <= 0 and cmp_func(b, c) <= 0, then
+ * cmp_func(a, c) <= 0.
+ *
  * Sorting time is O(n log n) both on average and worst-case. While
  * quicksort is slightly faster on average, it suffers from exploitable
  * O(n*n) worst-case behavior and extra memory requirements that make
_

Patches currently in -mm which might be from visitorckw@xxxxxxxxx are






[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux