Skip to content

Commit c5e4a06

Browse files
mettiJessica Yu
authored andcommitted
module: support reading multiple values per modinfo tag
Similar to modpost's get_next_modinfo(), introduce get_next_modinfo() in kernel/module.c to acquire any further values associated with the same modinfo tag name. That is useful for any tags that have multiple occurrences (such as 'alias'), but is in particular introduced here as part of the symbol namespaces patch series to read the (potentially) multiple namespaces a module is importing. Reviewed-by: Joel Fernandes (Google) <[email protected]> Reviewed-by: Martijn Coenen <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Matthias Maennich <[email protected]> Signed-off-by: Jessica Yu <[email protected]>
1 parent 089cf7f commit c5e4a06

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

kernel/module.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,8 @@ static char *next_string(char *string, unsigned long *secsize)
24812481
return string;
24822482
}
24832483

2484-
static char *get_modinfo(struct load_info *info, const char *tag)
2484+
static char *get_next_modinfo(const struct load_info *info, const char *tag,
2485+
char *prev)
24852486
{
24862487
char *p;
24872488
unsigned int taglen = strlen(tag);
@@ -2492,13 +2493,25 @@ static char *get_modinfo(struct load_info *info, const char *tag)
24922493
* get_modinfo() calls made before rewrite_section_headers()
24932494
* must use sh_offset, as sh_addr isn't set!
24942495
*/
2495-
for (p = (char *)info->hdr + infosec->sh_offset; p; p = next_string(p, &size)) {
2496+
char *modinfo = (char *)info->hdr + infosec->sh_offset;
2497+
2498+
if (prev) {
2499+
size -= prev - modinfo;
2500+
modinfo = next_string(prev, &size);
2501+
}
2502+
2503+
for (p = modinfo; p; p = next_string(p, &size)) {
24962504
if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
24972505
return p + taglen + 1;
24982506
}
24992507
return NULL;
25002508
}
25012509

2510+
static char *get_modinfo(const struct load_info *info, const char *tag)
2511+
{
2512+
return get_next_modinfo(info, tag, NULL);
2513+
}
2514+
25022515
static void setup_modinfo(struct module *mod, struct load_info *info)
25032516
{
25042517
struct module_attribute *attr;

0 commit comments

Comments
 (0)