From patchwork Wed Sep 23 17:28:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Abbott X-Patchwork-Id: 49581 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8NHZL8x023775 for ; Wed, 23 Sep 2009 17:35:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752686AbZIWReh (ORCPT ); Wed, 23 Sep 2009 13:34:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752681AbZIWReh (ORCPT ); Wed, 23 Sep 2009 13:34:37 -0400 Received: from BISCAYNE-ONE-STATION.MIT.EDU ([18.7.7.80]:47552 "EHLO biscayne-one-station.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752147AbZIWRee (ORCPT ); Wed, 23 Sep 2009 13:34:34 -0400 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by biscayne-one-station.mit.edu (8.13.6/8.9.2) with ESMTP id n8NHTffw006762; Wed, 23 Sep 2009 13:29:42 -0400 (EDT) Received: from localhost (c-71-192-160-118.hsd1.nh.comcast.net [71.192.160.118]) (authenticated bits=0) (User authenticated as tabbott@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id n8NHTf2s028213; Wed, 23 Sep 2009 13:29:41 -0400 (EDT) From: Tim Abbott To: Alan Jenkins Cc: Linux Kernel Mailing List , rusty@rustcorp.com.au, linux-kbuild@vger.kernel.org, linux-modules@vger.kernel.org, Tim Abbott Subject: [PATCH 2/2] module: use bsearch in find_symbol_in_kernel_section. Date: Wed, 23 Sep 2009 13:28:46 -0400 Message-Id: <1253726926-5504-3-git-send-email-tabbott@ksplice.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1253626718-18887-5-git-send-email-alan-jenkins@tuffmail.co.uk> References: <1253626718-18887-5-git-send-email-alan-jenkins@tuffmail.co.uk> X-Scanned-By: MIMEDefang 2.42 X-Spam-Flag: NO X-Spam-Score: 0.00 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Signed-off-by: Tim Abbott --- kernel/module.c | 34 +++++++++++++++------------------- 1 files changed, 15 insertions(+), 19 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 9b19f23..25ff16b 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -55,6 +55,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -209,31 +210,26 @@ struct symsearch { #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) #endif -/* binary search on sorted symbols */ +static int symbol_compare(const void *key, const void *elt) +{ + const char *str = key; + const struct kernel_symbol *sym = elt; + return strcmp(sym->name, str); +} + static bool find_symbol_in_kernel_section(const struct symsearch *syms, const char *name, unsigned int *symnum) { - int lo = 0, hi = syms->stop - syms->start - 1; - int mid, cmp; - - while (lo <= hi) { - mid = (lo + hi) / 2; - cmp = strcmp(syms->start[mid].name, name); - if (cmp == 0) { - *symnum = mid; - return true; - } - else if (cmp < 0) - hi = mid - 1; - else - lo = mid + 1; - } - - return false; + const struct kernel_symbol *sym = + bsearch(name, syms->start, syms->stop - syms->start, + sizeof(*syms->start), symbol_compare); + if (sym == NULL) + return false; + *symnum = sym - syms->start; + return true; } - static bool find_symbol_in_kernel(const char *name, struct symsearch *sym, unsigned int *symnum)