From: Jason Baron on
Make use of the the kernel's generic sort routines.

Signed-off-by: Jason Baron <jbaron(a)redhat.com>
---
kernel/jump_label.c | 37 ++++++++++++++++---------------------
1 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 10fb17f..faef97e 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -12,6 +12,7 @@
#include <linux/jhash.h>
#include <linux/slab.h>
#include <linux/err.h>
+#include <linux/sort.h>

#ifdef HAVE_JUMP_LABEL

@@ -38,33 +39,27 @@ struct jump_label_module_entry {
struct module *mod;
};

-static void swap_jump_label_entries(struct jump_entry *previous, struct jump_entry *next)
+static int jump_label_cmp(const void *a, const void *b)
{
- struct jump_entry tmp;
+ const struct jump_entry *jea = a;
+ const struct jump_entry *jeb = b;

- tmp = *next;
- *next = *previous;
- *previous = tmp;
+ if (jea->key < jeb->key)
+ return -1;
+
+ if (jea->key > jeb->key)
+ return 1;
+
+ return 0;
}

static void sort_jump_label_entries(struct jump_entry *start, struct jump_entry *stop)
{
- int swapped = 0;
- struct jump_entry *iter;
- struct jump_entry *iter_next;
-
- do {
- swapped = 0;
- iter = start;
- iter_next = start;
- iter_next++;
- for (; iter_next < stop; iter++, iter_next++) {
- if (iter->key > iter_next->key) {
- swap_jump_label_entries(iter, iter_next);
- swapped = 1;
- }
- }
- } while (swapped == 1);
+ unsigned long size;
+
+ size = (((unsigned long)stop - (unsigned long)start)
+ / sizeof(struct jump_entry));
+ sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
}

static struct jump_label_entry *get_jump_label_entry(jump_label_t key)
--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/