Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+30 -17
+3 -2
include/linux/module.h
··· 477 477 bool warn); 478 478 479 479 /* Walk the exported symbol table */ 480 - bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 481 - unsigned int symnum, void *data), void *data); 480 + bool each_symbol_section(bool (*fn)(const struct symsearch *arr, 481 + struct module *owner, 482 + void *data), void *data); 482 483 483 484 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if 484 485 symnum out of range. */
+27 -15
kernel/module.c
··· 240 240 struct module *owner, 241 241 bool (*fn)(const struct symsearch *syms, 242 242 struct module *owner, 243 - unsigned int symnum, void *data), 243 + void *data), 244 244 void *data) 245 245 { 246 - unsigned int i, j; 246 + unsigned int j; 247 247 248 248 for (j = 0; j < arrsize; j++) { 249 - for (i = 0; i < arr[j].stop - arr[j].start; i++) 250 - if (fn(&arr[j], owner, i, data)) 251 - return true; 249 + if (fn(&arr[j], owner, data)) 250 + return true; 252 251 } 253 252 254 253 return false; 255 254 } 256 255 257 256 /* Returns true as soon as fn returns true, otherwise false. */ 258 - bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, 259 - unsigned int symnum, void *data), void *data) 257 + bool each_symbol_section(bool (*fn)(const struct symsearch *arr, 258 + struct module *owner, 259 + void *data), 260 + void *data) 260 261 { 261 262 struct module *mod; 262 263 static const struct symsearch arr[] = { ··· 310 309 } 311 310 return false; 312 311 } 313 - EXPORT_SYMBOL_GPL(each_symbol); 312 + EXPORT_SYMBOL_GPL(each_symbol_section); 314 313 315 314 struct find_symbol_arg { 316 315 /* Input */ ··· 324 323 const struct kernel_symbol *sym; 325 324 }; 326 325 327 - static bool find_symbol_in_section(const struct symsearch *syms, 328 - struct module *owner, 329 - unsigned int symnum, void *data) 326 + static bool check_symbol(const struct symsearch *syms, 327 + struct module *owner, 328 + unsigned int symnum, void *data) 330 329 { 331 330 struct find_symbol_arg *fsa = data; 332 - 333 - if (strcmp(syms->start[symnum].name, fsa->name) != 0) 334 - return false; 335 331 336 332 if (!fsa->gplok) { 337 333 if (syms->licence == GPL_ONLY) ··· 363 365 return true; 364 366 } 365 367 368 + static bool find_symbol_in_section(const struct symsearch *syms, 369 + struct module *owner, 370 + void *data) 371 + { 372 + struct find_symbol_arg *fsa = data; 373 + unsigned int i; 374 + 375 + for (i = 0; i < syms->stop - syms->start; i++) { 376 + if (strcmp(syms->start[i].name, fsa->name) == 0) 377 + return check_symbol(syms, owner, i, data); 378 + } 379 + return false; 380 + } 381 + 366 382 /* Find a symbol and return it, along with, (optional) crc and 367 383 * (optional) module which owns it. Needs preempt disabled or module_mutex. */ 368 384 const struct kernel_symbol *find_symbol(const char *name, ··· 391 379 fsa.gplok = gplok; 392 380 fsa.warn = warn; 393 381 394 - if (each_symbol(find_symbol_in_section, &fsa)) { 382 + if (each_symbol_section(find_symbol_in_section, &fsa)) { 395 383 if (owner) 396 384 *owner = fsa.owner; 397 385 if (crc)