Commit b5d3f322 authored by Matt Mackall's avatar Matt Mackall Committed by Linus Torvalds

[PATCH] lib/sort: Replace insertion sort in IA64 exception tables

Switch IA64 exception tables to lib/sort.
Signed-off-by: default avatarMatt Mackall <mpm@selenic.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 9e9dd5d9
...@@ -6,29 +6,24 @@ ...@@ -6,29 +6,24 @@
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/sort.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/module.h> #include <asm/module.h>
static inline int static int cmp_ex(const void *a, const void *b)
compare_entries (struct exception_table_entry *l, struct exception_table_entry *r)
{ {
const struct exception_table_entry *l = a, *r = b;
u64 lip = (u64) &l->addr + l->addr; u64 lip = (u64) &l->addr + l->addr;
u64 rip = (u64) &r->addr + r->addr; u64 rip = (u64) &r->addr + r->addr;
if (lip < rip) return lip - rip;
return -1;
if (lip == rip)
return 0;
else
return 1;
} }
static inline void static void swap_ex(void *a, void *b)
swap_entries (struct exception_table_entry *l, struct exception_table_entry *r)
{ {
struct exception_table_entry *l = a, *r = b, tmp;
u64 delta = (u64) r - (u64) l; u64 delta = (u64) r - (u64) l;
struct exception_table_entry tmp;
tmp = *l; tmp = *l;
l->addr = r->addr + delta; l->addr = r->addr + delta;
...@@ -38,23 +33,20 @@ swap_entries (struct exception_table_entry *l, struct exception_table_entry *r) ...@@ -38,23 +33,20 @@ swap_entries (struct exception_table_entry *l, struct exception_table_entry *r)
} }
/* /*
* Sort the exception table. It's usually already sorted, but there may be unordered * Sort the exception table. It's usually already sorted, but there
* entries due to multiple text sections (such as the .init text section). Note that the * may be unordered entries due to multiple text sections (such as the
* exception-table-entries contain location-relative addresses, which requires a bit of * .init text section). Note that the exception-table-entries contain
* care during sorting to avoid overflows in the offset members (e.g., it would not be * location-relative addresses, which requires a bit of care during
* safe to make a temporary copy of an exception-table entry on the stack, because the * sorting to avoid overflows in the offset members (e.g., it would
* stack may be more than 2GB away from the exception-table). * not be safe to make a temporary copy of an exception-table entry on
* the stack, because the stack may be more than 2GB away from the
* exception-table).
*/ */
void void sort_extable (struct exception_table_entry *start,
sort_extable (struct exception_table_entry *start, struct exception_table_entry *finish) struct exception_table_entry *finish)
{ {
struct exception_table_entry *p, *q; sort(start, finish - start, sizeof(struct exception_table_entry),
cmp_ex, swap_ex);
/* insertion sort */
for (p = start + 1; p < finish; ++p)
/* start .. p-1 is sorted; push p down to it's proper place */
for (q = p; q > start && compare_entries(&q[0], &q[-1]) < 0; --q)
swap_entries(&q[0], &q[-1]);
} }
const struct exception_table_entry * const struct exception_table_entry *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment