From 705364b2bfc805e0c07ea64ec01e3080e5609bc3 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 6 Jan 2009 02:04:51 -0800 Subject: [PATCH] Fix nits in .ko.{gz,bz2} matching. --- libdwfl/ChangeLog | 2 +- libdwfl/linux-kernel-modules.c | 42 ++++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index b3bf84e..0e37686 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,6 +1,6 @@ 2009-01-06 Roland McGrath - * linux-kernel-modules.c (is_ko): New function. + * linux-kernel-modules.c (check_suffix): New function. Match ".ko", ".ko.gz", and ".ko.bz2" suffixes. (dwfl_linux_kernel_report_offline): Use it. (dwfl_linux_kernel_find_elf): Likewise. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 7da33d8..753e9bc 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -254,25 +254,27 @@ report_kernel_archive (Dwfl *dwfl, const char **release, return result; } -static bool -is_ko (const FTSENT *f, size_t namelen) +static size_t +check_suffix (const FTSENT *f, size_t namelen) { -#define has_suffix(f, sfx, namelen) \ - ((namelen ? f->fts_namelen == namelen + sizeof sfx - 1 \ - : f->fts_namelen >= sizeof sfx) \ - && !memcmp (f->fts_name + f->fts_namelen - (sizeof sfx - 1), \ - sfx, sizeof sfx)) - - return (has_suffix (f, ".ko", namelen) +#define TRY(sfx) \ + if ((namelen ? f->fts_namelen == namelen + sizeof sfx - 1 \ + : f->fts_namelen >= sizeof sfx) \ + && !memcmp (f->fts_name + f->fts_namelen - (sizeof sfx - 1), \ + sfx, sizeof sfx)) \ + return sizeof sfx - 1 + + TRY (".ko"); #if USE_ZLIB - || has_suffix (f, ".ko.gz", namelen) + TRY (".ko.gz"); #endif #if USE_BZLIB - || has_suffix (f, ".ko.bz2", namelen) + TRY (".ko.bz2"); #endif - ); -#undef has_suffix + return 0; + +#undef TRY } /* Report a kernel and all its modules found on disk, for offline use. @@ -321,9 +323,10 @@ dwfl_linux_kernel_report_offline (Dwfl *dwfl, const char *release, { case FTS_F: case FTS_SL: - case FTS_NSOK: + case FTS_NSOK:; /* See if this file name matches "*.ko". */ - if (is_ko (f, 0)) + const size_t suffix = check_suffix (f, 0); + if (suffix) { /* We have a .ko file to report. Following the algorithm by which the kernel makefiles set KBUILD_MODNAME, we @@ -333,13 +336,13 @@ dwfl_linux_kernel_report_offline (Dwfl *dwfl, const char *release, names. To handle that, we would have to look at the __this_module.name contents in the module's text. */ - char name[f->fts_namelen - 3 + 1]; + char name[f->fts_namelen - suffix + 1]; for (size_t i = 0; i < f->fts_namelen - 3U; ++i) if (f->fts_name[i] == '-' || f->fts_name[i] == ',') name[i] = '_'; else name[i] = f->fts_name[i]; - name[f->fts_namelen - 3] = '\0'; + name[f->fts_namelen - suffix] = '\0'; if (predicate != NULL) { @@ -354,8 +357,7 @@ dwfl_linux_kernel_report_offline (Dwfl *dwfl, const char *release, continue; } - if (dwfl_report_offline (dwfl, name, - f->fts_path, -1) == NULL) + if (dwfl_report_offline (dwfl, name, f->fts_path, -1) == NULL) { result = -1; break; @@ -687,7 +689,7 @@ dwfl_linux_kernel_find_elf (Dwfl_Module *mod, case FTS_SL: case FTS_NSOK: /* See if this file name is "MODULE_NAME.ko". */ - if (is_ko (f, namelen) + if (check_suffix (f, namelen) && (!memcmp (f->fts_name, module_name, namelen) || !memcmp (f->fts_name, alternate_name, namelen))) { -- 2.7.4