lkml.org 
[lkml]   [2017]   [Nov]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/3] module: add helper get_modinfo_idx()
Date
get_modinfo() lets you look for at the modinfo section for
a value using a specific tag, this however is limited to
only give you the first tag found. In practice you can have
multiple entries using the same tag, one example are aliases

We have not had a need to support hunting for beyond the first
tag entry on the modinfo sectin of a module. For aliases we'll
need infrastructure to pick and choose which tag entry we want.

Add get_modinfo_idx() to enable us to pick and chooes *which*
tag entry we wish to get. get_modinfo() becomes then a wrapper
which uses get_modinfo_idx() to get the first entry.

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
kernel/module.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index bb595dc87651..6d5f02e86681 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2485,20 +2485,28 @@ static char *next_string(char *string, unsigned long *secsize)
return string;
}

-static char *get_modinfo(struct load_info *info, const char *tag)
+static const char *get_modinfo_idx(struct load_info *info, const char *tag,
+ unsigned int tag_idx)
{
char *p;
unsigned int taglen = strlen(tag);
Elf_Shdr *infosec = &info->sechdrs[info->index.info];
unsigned long size = infosec->sh_size;
+ unsigned int num_tags = 0;

for (p = (char *)infosec->sh_addr; p; p = next_string(p, &size)) {
- if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
+ if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=' &&
+ num_tags++ == tag_idx)
return p + taglen + 1;
}
return NULL;
}

+static const char *get_modinfo(struct load_info *info, const char *tag)
+{
+ return get_modinfo_idx(info, tag, 0);
+}
+
static void setup_modinfo(struct module *mod, struct load_info *info)
{
struct module_attribute *attr;
--
2.15.0
\
 
 \ /
  Last update: 2017-11-30 03:36    [W:0.748 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site