From 6a94b67bcac67e4b52622366cec019ea14c0ddd0 Mon Sep 17 00:00:00 2001
From: Michal Marek <mmarek@suse.cz>
Date: Mon, 19 Sep 2011 16:31:49 +0200
Subject: [PATCH] modpost: Allow wildcards in the Module.supported file
Patch-mainline: Never, SLES feature
References: none
Signed-off-by: Michal Marek <mmarek@suse.cz>
---
scripts/mod/modpost.c | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <fnmatch.h>
#include <limits.h>
#include <stdbool.h>
#include <errno.h>
@@ -1702,7 +1703,7 @@ static char *underscores(char *string)
void *supported_file;
unsigned long supported_size;
-static const char *supported(struct module *mod)
+static const char *supported(const char *modname)
{
unsigned long pos = 0;
char *line;
@@ -1710,8 +1711,9 @@ static const char *supported(struct modu
/* In a first shot, do a simple linear scan. */
while ((line = get_next_line(&pos, supported_file,
supported_size))) {
- const char *basename, *how = "yes";
+ const char *how = "yes";
char *l = line;
+ char *pat_basename, *mod, *orig_mod, *mod_basename;
/* optional type-of-support flag */
for (l = line; *l != '\0'; l++) {
@@ -1721,29 +1723,38 @@ static const char *supported(struct modu
break;
}
}
-
- /* skip directory components */
- if ((l = strrchr(line, '/')))
- line = l + 1;
/* strip .ko extension */
l = line + strlen(line);
if (l - line > 3 && !strcmp(l-3, ".ko"))
*(l-3) = '\0';
- underscores(line);
- /* skip directory components */
- if ((basename = strrchr(mod->name, '/')))
- basename++;
+ /*
+ * convert dashes to underscores in the last path component
+ * of line and mod
+ */
+ if ((pat_basename = strrchr(line, '/')))
+ pat_basename++;
else
- basename = mod->name;
- basename = strdup(basename);
- underscores(basename);
+ pat_basename = line;
+ underscores(pat_basename);
+
+ orig_mod = mod = strdup(modname);
+ if ((mod_basename = strrchr(mod, '/')))
+ mod_basename++;
+ else
+ mod_basename = mod;
+ underscores(mod_basename);
- if (!strcmp(basename, line)) {
- free(basename);
+ /* only compare the last component if no wildcards are used */
+ if (strcspn(line, "[]*?") == strlen(line)) {
+ line = pat_basename;
+ mod = mod_basename;
+ }
+ if (!fnmatch(line, mod, 0)) {
+ free(orig_mod);
return how;
}
- free(basename);
+ free(orig_mod);
}
return NULL;
}
@@ -1966,7 +1977,7 @@ static void add_staging_flag(struct buff
#ifdef CONFIG_SUSE_KERNEL_SUPPORTED
static void add_supported_flag(struct buffer *b, struct module *mod)
{
- const char *how = supported(mod);
+ const char *how = supported(mod->name);
if (how)
buf_printf(b, "\nMODULE_INFO(supported, \"%s\");\n", how);
}