From patchwork Thu Nov 1 03:30:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 10663477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29E43157A for ; Thu, 1 Nov 2018 03:30:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E3602BD99 for ; Thu, 1 Nov 2018 03:30:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 028D02BDD6; Thu, 1 Nov 2018 03:30:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 751952BC23 for ; Thu, 1 Nov 2018 03:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbeKAMbu (ORCPT ); Thu, 1 Nov 2018 08:31:50 -0400 Received: from mail-qt1-f174.google.com ([209.85.160.174]:42906 "EHLO mail-qt1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726095AbeKAMbt (ORCPT ); Thu, 1 Nov 2018 08:31:49 -0400 Received: by mail-qt1-f174.google.com with SMTP id z20-v6so19664183qti.9; Wed, 31 Oct 2018 20:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cuLNrA7rriyAhJkMEFnPydKWkWCnPgwIADQDCUFLAjQ=; b=DuezBhGe3fOCv3TBGPdSZb3kL2By1e3DJyKQyyu1ffKwrDf+2cuZTWhxNMorlYPsVk Yb0+zZgEyIlxeVUt/izJATaUCH9Eql9Ody0v4Ny+BJLFmdPxU+G7Nrn7nJslg/EUIlF+ aylg/OoDgg9lY4grBNLlDA+9/wiFzQ+aEofjsY/6yjZWYa3bmE20J/D8A+8Oq9ad8pAB /cKNazvEWFUed68Azl1XF/F4zeqy/HsWM6fBC0ZRT6rTWrHxkoBxQPgMn/dzloInpLWl XlcaguJA9pLJgevCvTELY0LKV8/KL9KUUKfeWfYRziuQcpMkvM2r4cWnhPZXc2a3fEbH DYWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cuLNrA7rriyAhJkMEFnPydKWkWCnPgwIADQDCUFLAjQ=; b=En9EiMvfyEfhb8NytsAf+VdKJ661ZC/Y+aNZvDpfNGdOp60N00V1MiSOAh+kQx6KR1 SojpRWzzCjC1zR8j4lgEnxVmt8Epw+Y9o9mHhXpmF+/TjRafD97AAbj335SKCIeAsE+S sDu4FTKbbLOyS1atlVImfbw+GpfEG6O2RLAm7ZJFqryPAEWzEvWzO36YqerHoCJQqpvx cJlNB8MqYhyqcrKKRWbnJPsc33ymdFR2SDr+XVs1Zc0BRQsNWARxFmUsw5va7Z1wkBdj KuM98K6MjCxbgokIqbAJaQQoEGvW2Gqp4nrsoUN5LUZ9HyNuZPjY4fHw5RsB2BDDIc1Q 0W5g== X-Gm-Message-State: AGRZ1gISH+k8TIpFOwFiHWKULxo9Pg/nxYs1rXkTNsmlglboScQB84KP EBn7U3thh1rpCbU/yJcfA0o= X-Google-Smtp-Source: AJdET5c/jTr4Wm+dP8r3hPXzQ6km+SOwzxqK1MB5H4pSuCfya/L2jWijh3GYh8/dhrd5ub5989NhMQ== X-Received: by 2002:a0c:94e5:: with SMTP id k34mr5285950qvk.215.1541043043833; Wed, 31 Oct 2018 20:30:43 -0700 (PDT) Received: from localhost.localdomain ([179.159.21.48]) by smtp.gmail.com with ESMTPSA id 83sm29956779qkz.73.2018.10.31.20.30.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 20:30:43 -0700 (PDT) From: Leonardo Bras To: lkcamp@lists.libreplanetbr.org Cc: Leonardo Bras , Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] modpost: Refactor and removes global variable *modules Date: Thu, 1 Nov 2018 00:30:38 -0300 Message-Id: <20181101033038.24142-1-leobras.c@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactors the code to accept the modules list as a parameter in the functions that need it, and moves the variable from the global scope to the main function scope. This also fixes the parameter shadowing of add_depends. Signed-off-by: Leonardo Bras --- scripts/mod/modpost.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0d998c54564d..bebe65ed957a 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -118,10 +118,7 @@ void *do_nofail(void *ptr, const char *expr) return ptr; } -/* A list of all modules we processed */ -static struct module *modules; - -static struct module *find_module(const char *modname) +static struct module *find_module(const char *modname, struct module *modules) { struct module *mod; @@ -131,7 +128,7 @@ static struct module *find_module(const char *modname) return mod; } -static struct module *new_module(const char *modname) +static struct module *new_module(const char *modname, struct module **pmodules) { struct module *mod; char *p; @@ -149,8 +146,8 @@ static struct module *new_module(const char *modname) /* add to list */ mod->name = p; mod->gpl_compatible = -1; - mod->next = modules; - modules = mod; + mod->next = *pmodules; + *pmodules = mod; return mod; } @@ -1929,7 +1926,7 @@ static char *remove_dot(char *s) return s; } -static void read_symbols(const char *modname) +static void read_symbols(const char *modname, struct module **pmodules) { const char *symname; char *version; @@ -1941,7 +1938,7 @@ static void read_symbols(const char *modname) if (!parse_elf(&info, modname)) return; - mod = new_module(modname); + mod = new_module(modname, pmodules); /* When there's no vmlinux, don't print warnings about * unresolved symbols (since there'll be too many ;) */ @@ -1992,7 +1989,8 @@ static void read_symbols(const char *modname) mod->unres = alloc_symbol("module_layout", 0, mod->unres); } -static void read_symbols_from_files(const char *filename) +static void read_symbols_from_files(const char *filename, + struct module **pmodules) { FILE *in = stdin; char fname[PATH_MAX]; @@ -2006,7 +2004,7 @@ static void read_symbols_from_files(const char *filename) while (fgets(fname, PATH_MAX, in) != NULL) { if (strends(fname, "\n")) fname[strlen(fname)-1] = '\0'; - read_symbols(fname); + read_symbols(fname, pmodules); } if (in != stdin) @@ -2318,7 +2316,8 @@ static void write_if_changed(struct buffer *b, const char *fname) /* parse Module.symvers file. line format: * 0x12345678symbolmodule[[export]something] **/ -static void read_dump(const char *fname, unsigned int kernel) +static void read_dump(const char *fname, unsigned int kernel, + struct module **pmodules) { unsigned long size, pos = 0; void *file = grab_file(fname, &size); @@ -2347,11 +2346,11 @@ static void read_dump(const char *fname, unsigned int kernel) crc = strtoul(line, &d, 16); if (*symname == '\0' || *modname == '\0' || *d != '\0') goto fail; - mod = find_module(modname); + mod = find_module(modname, *pmodules); if (!mod) { if (is_vmlinux(modname)) have_vmlinux = 1; - mod = new_module(modname); + mod = new_module(modname, pmodules); mod->skip = 1; } s = sym_add_exported(symname, mod, export_no(export)); @@ -2415,6 +2414,8 @@ int main(int argc, char **argv) int err; struct ext_sym_list *extsym_iter; struct ext_sym_list *extsym_start = NULL; + /* A list of all modules we processed */ + static struct module *modules; while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) { switch (opt) { @@ -2466,21 +2467,21 @@ int main(int argc, char **argv) } if (kernel_read) - read_dump(kernel_read, 1); + read_dump(kernel_read, 1, &modules); if (module_read) - read_dump(module_read, 0); + read_dump(module_read, 0, &modules); while (extsym_start) { - read_dump(extsym_start->file, 0); + read_dump(extsym_start->file, 0, &modules); extsym_iter = extsym_start->next; free(extsym_start); extsym_start = extsym_iter; } while (optind < argc) - read_symbols(argv[optind++]); + read_symbols(argv[optind++], &modules); if (files_source) - read_symbols_from_files(files_source); + read_symbols_from_files(files_source, &modules); for (mod = modules; mod; mod = mod->next) { if (mod->skip)