aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-04-19 15:49:58 -0400
committerRusty Russell <rusty@rustcorp.com.au>2011-05-19 03:25:26 -0400
commitde4d8d53465483168d6a627d409ee2d09d8e3308 (patch)
treedadc9b82860842dcb970f2898f677e0d2373a2ab /kernel/module.c
parent01526ed0830643bd53a8434c3068e4c077e1b09d (diff)
module: each_symbol_section instead of each_symbol
Instead of having a callback function for each symbol in the kernel, have a callback for each array of symbols. This eases the logic when we move to sorted symbols and binary search. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Alessio Igor Bogani <abogani@kernel.org>
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 0e6f97f43c88..e8aa462301e7 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -240,23 +240,24 @@ static bool each_symbol_in_section(const struct symsearch *arr,
240 struct module *owner, 240 struct module *owner,
241 bool (*fn)(const struct symsearch *syms, 241 bool (*fn)(const struct symsearch *syms,
242 struct module *owner, 242 struct module *owner,
243 unsigned int symnum, void *data), 243 void *data),
244 void *data) 244 void *data)
245{ 245{
246 unsigned int i, j; 246 unsigned int j;
247 247
248 for (j = 0; j < arrsize; j++) { 248 for (j = 0; j < arrsize; j++) {
249 for (i = 0; i < arr[j].stop - arr[j].start; i++) 249 if (fn(&arr[j], owner, data))
250 if (fn(&arr[j], owner, i, data)) 250 return true;
251 return true;
252 } 251 }
253 252
254 return false; 253 return false;
255} 254}
256 255
257/* Returns true as soon as fn returns true, otherwise false. */ 256/* Returns true as soon as fn returns true, otherwise false. */
258bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 257bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
259 unsigned int symnum, void *data), void *data) 258 struct module *owner,
259 void *data),
260 void *data)
260{ 261{
261 struct module *mod; 262 struct module *mod;
262 static const struct symsearch arr[] = { 263 static const struct symsearch arr[] = {
@@ -309,7 +310,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
309 } 310 }
310 return false; 311 return false;
311} 312}
312EXPORT_SYMBOL_GPL(each_symbol); 313EXPORT_SYMBOL_GPL(each_symbol_section);
313 314
314struct find_symbol_arg { 315struct find_symbol_arg {
315 /* Input */ 316 /* Input */
@@ -323,15 +324,12 @@ struct find_symbol_arg {
323 const struct kernel_symbol *sym; 324 const struct kernel_symbol *sym;
324}; 325};
325 326
326static bool find_symbol_in_section(const struct symsearch *syms, 327static bool check_symbol(const struct symsearch *syms,
327 struct module *owner, 328 struct module *owner,
328 unsigned int symnum, void *data) 329 unsigned int symnum, void *data)
329{ 330{
330 struct find_symbol_arg *fsa = data; 331 struct find_symbol_arg *fsa = data;
331 332
332 if (strcmp(syms->start[symnum].name, fsa->name) != 0)
333 return false;
334
335 if (!fsa->gplok) { 333 if (!fsa->gplok) {
336 if (syms->licence == GPL_ONLY) 334 if (syms->licence == GPL_ONLY)
337 return false; 335 return false;
@@ -365,6 +363,20 @@ static bool find_symbol_in_section(const struct symsearch *syms,
365 return true; 363 return true;
366} 364}
367 365
366static bool find_symbol_in_section(const struct symsearch *syms,
367 struct module *owner,
368 void *data)
369{
370 struct find_symbol_arg *fsa = data;
371 unsigned int i;
372
373 for (i = 0; i < syms->stop - syms->start; i++) {
374 if (strcmp(syms->start[i].name, fsa->name) == 0)
375 return check_symbol(syms, owner, i, data);
376 }
377 return false;
378}
379
368/* Find a symbol and return it, along with, (optional) crc and 380/* Find a symbol and return it, along with, (optional) crc and
369 * (optional) module which owns it. Needs preempt disabled or module_mutex. */ 381 * (optional) module which owns it. Needs preempt disabled or module_mutex. */
370const struct kernel_symbol *find_symbol(const char *name, 382const struct kernel_symbol *find_symbol(const char *name,
@@ -379,7 +391,7 @@ const struct kernel_symbol *find_symbol(const char *name,
379 fsa.gplok = gplok; 391 fsa.gplok = gplok;
380 fsa.warn = warn; 392 fsa.warn = warn;
381 393
382 if (each_symbol(find_symbol_in_section, &fsa)) { 394 if (each_symbol_section(find_symbol_in_section, &fsa)) {
383 if (owner) 395 if (owner)
384 *owner = fsa.owner; 396 *owner = fsa.owner;
385 if (crc) 397 if (crc)