Page MenuHomeFreeBSD

D62194.1796052938.diff
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

D62194.1796052938.diff

diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -2577,43 +2577,35 @@
return (0);
}
-struct list_sort_thunk {
- int (*cmp)(void *, struct list_head *, struct list_head *);
- void *priv;
-};
-
-static inline int
-linux_le_cmp(const void *d1, const void *d2, void *priv)
-{
- struct list_head *le1, *le2;
- struct list_sort_thunk *thunk;
-
- thunk = priv;
- le1 = *(__DECONST(struct list_head **, d1));
- le2 = *(__DECONST(struct list_head **, d2));
- return ((thunk->cmp)(thunk->priv, le1, le2));
-}
-
void
list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv,
struct list_head *a, struct list_head *b))
{
- struct list_sort_thunk thunk;
struct list_head **ar, *le;
- size_t count, i;
+ size_t i, j, n;
- count = 0;
+ /* count the list */
+ n = 0;
list_for_each(le, head)
- count++;
- ar = malloc(sizeof(struct list_head *) * count, M_KMALLOC, M_WAITOK);
+ n++;
+
+ /* create a temporary array with the same contents as the list */
+ ar = malloc(sizeof(*ar) * n, M_KMALLOC, M_WAITOK);
i = 0;
list_for_each(le, head)
ar[i++] = le;
- thunk.cmp = cmp;
- thunk.priv = priv;
- qsort_r(ar, count, sizeof(struct list_head *), linux_le_cmp, &thunk);
+
+ /* sort the array using insertion sort */
+ for (i = 1; i < n; i++) {
+ le = ar[i];
+ for (j = i; j > 0 && cmp(priv, ar[j - 1], ar[j]) > 0; j--)
+ ar[j] = ar[j - 1];
+ ar[j] = le;
+ }
+
+ /* convert the array back into a list */
INIT_LIST_HEAD(head);
- for (i = 0; i < count; i++)
+ for (i = 0; i < n; i++)
list_add_tail(ar[i], head);
free(ar, M_KMALLOC);
}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 30, 3:35 PM (22 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42105187
Default Alt Text
D62194.1796052938.diff (1 KB)

Event Timeline