From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753296AbdK3CgM (ORCPT ); Wed, 29 Nov 2017 21:36:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:52644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753176AbdK3CgK (ORCPT ); Wed, 29 Nov 2017 21:36:10 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2823421996 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mcgrof@kernel.org From: "Luis R. Rodriguez" To: jeyu@redhat.com, rusty@rustcorp.com.au Cc: keescook@chromium.org, tixxdz@gmail.com, mbenes@suse.cz, atomlin@redhat.com, pmladek@suse.com, hare@suse.com, james.l.morris@oracle.com, ebiederm@xmission.com, davem@davemloft.net, akpm@linux-foundation.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH 2/3] module: add helper get_modinfo_idx() Date: Wed, 29 Nov 2017 18:36:04 -0800 Message-Id: <20171130023605.29568-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20171130023605.29568-1-mcgrof@kernel.org> References: <20171130023605.29568-1-mcgrof@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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