Re: [PATCH] module: Use binary search in lookup_symbol()
From: Dirk Behme
Date: Mon May 16 2011 - 11:36:30 EST
On 03.05.2011 22:42, Alessio Igor Bogani wrote:
This work was supported by a hardware donation from the CE Linux Forum.
Signed-off-by: Alessio Igor Bogani<abogani@xxxxxxxxxx>
---
kernel/module.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c
index 6a34337..a1f841e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2055,10 +2055,8 @@ static const struct kernel_symbol *lookup_symbol(const char *name,
const struct kernel_symbol *stop)
{
const struct kernel_symbol *ks = start;
- for (; ks< stop; ks++)
- if (strcmp(ks->name, name) == 0)
- return ks;
- return NULL;
+ return bsearch(ks->name, start, stop - start,
+ sizeof(struct kernel_symbol), cmp_name);
}
Back porting this patch to a 2.6.34.9 based ARM system fails with an
Oops at 0x00000004. Debugging shows that both start and stop are 0 in
this case resulting in ks->name accessing 0x00000004. The original
code checked for this by 'ks < stop' in the for loop.
So the first idea was that the code should be
if(k < stop)
return bsearch();
else
return NULL;
Then, thinking again, results in the question if the first argument of
bsearch() shouldn't be 'name' rather than 'ks->name'? Then it would be
the job of cmp_name() to check for start == stop == 0? I.e.
return bsearch(name, ...);
?
Best regards
Dirk
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/