Skip to content

Commit 0267cbf

Browse files
Peter Zijlstramasahir0y
authored andcommitted
module: Account for the build time module name mangling
Sean noted that scripts/Makefile.lib:name-fix-token rule will mangle the module name with s/-/_/g. Since this happens late in the build, only the kernel needs to bother with this, the modpost tool still sees the original name. Reported-by: Sean Christopherson <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> Tested-by: Sean Christopherson <[email protected]> Reviewed-by: Petr Pavlu <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 754f873 commit 0267cbf

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

kernel/module/main.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,30 @@ static inline void add_taint_module(struct module *mod, unsigned flag,
169169
set_bit(flag, &mod->taints);
170170
}
171171

172+
/*
173+
* Like strncmp(), except s/-/_/g as per scripts/Makefile.lib:name-fix-token rule.
174+
*/
175+
static int mod_strncmp(const char *str_a, const char *str_b, size_t n)
176+
{
177+
for (int i = 0; i < n; i++) {
178+
char a = str_a[i];
179+
char b = str_b[i];
180+
int d;
181+
182+
if (a == '-') a = '_';
183+
if (b == '-') b = '_';
184+
185+
d = a - b;
186+
if (d)
187+
return d;
188+
189+
if (!a)
190+
break;
191+
}
192+
193+
return 0;
194+
}
195+
172196
/*
173197
* A thread that wants to hold a reference to a module only while it
174198
* is running can call this to safely exit.
@@ -1116,7 +1140,7 @@ static bool verify_module_namespace(const char *namespace, const char *modname)
11161140
if (*sep)
11171141
sep++;
11181142

1119-
if (strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
1143+
if (mod_strncmp(namespace, modname, len) == 0 && (glob || len == modlen))
11201144
return true;
11211145
}
11221146

0 commit comments

Comments
 (0)