From patchwork Tue Jan 9 08:30:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123810 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3750237qgn; Tue, 9 Jan 2018 00:32:45 -0800 (PST) X-Google-Smtp-Source: ACJfBova1jh4rLH3ZJbDAk2w/KDi3se1OjdXSKGH12P9UuGNChzXCyQt+J29FFeCGIbkqypCs++Z X-Received: by 10.101.82.205 with SMTP id z13mr11588079pgp.403.1515486765640; Tue, 09 Jan 2018 00:32:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486765; cv=none; d=google.com; s=arc-20160816; b=zRKfydHIOFmGgmi0aZBv/uXL8nVXV+jILvVgySkDnEoEfg70+Qv0mqtDePu2lBAFAC kpKwkiam81AjXXWAG0ogUHv4ugszEw4ue7fxtJhGefFy1ufxOxb79peEhbWj3kXfuRyP lfoArdoI6NAwHF+uE7fQmdpJmpX+3jFcsuTaWDlXmiZv+ArgFL1sigTUbAuge0TaU6rw u8SgarRf9zaopDUv4ljWexafglGijAWPWJxnKrqkshkgaO5U/krXTdyftX+XKqUQbMAt dLD2kuwC5ympIm46r6+1TBMc+ZF0SPbVCvwHfG3I70N53rT7SY1BYKxz+SMNy7ZC39Ng 3yhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=eII+qy4k8i367HbCbA4Q0X4SPtggcoLkPrjaGg5QK9M=; b=je4i8C7FXFyRVSbVf35pPegvACCzvAXLtwnSw+674WIDtoEUxobkazXDWemBTsE45+ oRbHKdm/bGuMrMm5ItGDUwCSyKjX5L5IYhtzTWzh0RHAa8wz6qc/0W5Le4vsVQqfx6YH uw/5GJ5bbbw8t547STGZDgR9gKHB22iZZYRYjrPQH01sW3muy0pxf0IFp2rVXqhnrUwL UF9w3xmXbv5qpRxjM2eujnUheCM/K10xM2pec7syKoVtPlfhA0dLDsYbyMcA+biTlmEk Ep8um389Mzz9xGW56n/TIcRXWcO1p+sXrseROUBwdaU0NBKzq5vK3m9k5JoWgIf45Fyv QYVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UNKteju4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12si8715185pgq.184.2018.01.09.00.32.45; Tue, 09 Jan 2018 00:32:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UNKteju4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751438AbeAIIcC (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:02 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27299 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751127AbeAIIb7 (ORCPT ); Tue, 9 Jan 2018 03:31:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugs024960; Tue, 9 Jan 2018 17:30:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugs024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486656; bh=eII+qy4k8i367HbCbA4Q0X4SPtggcoLkPrjaGg5QK9M=; h=From:To:Cc:Subject:Date:From; b=UNKteju4bWDu9YGtQhjHM7qI/FGGF2ZDBT9ZiPS/+S7t3oHjwko73VC2tMWyHzGnV SRi2dYjq5VL9kx4kaz6gykYEx+nO4fUrzja9OL/isVDDFI1qj7HbrI11Dqih5xJlNU 5zy4xrF/6gO+WSSe5QBp/QgIvSv/shk594CoQ1LdGSoctlpGR4aE4Nj+TzMdt+W7Mn FaNWPKYysljlu66LQs5ulXJOB/1nMtqtUNL2fS39kLvGGLd7pbPoRrkhPIOgP7LOyR p38hout0wI3M/QV3toodtLxVKsCHpnJDJehOb2sEZm1IpblPawPB7Krd0WyU9NATEJ G8HVDxsvQZo/A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 1/6] fixdep: use malloc() and read() to load dep_file to buffer Date: Tue, 9 Jan 2018 17:30:45 +0900 Message-Id: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit dee81e988674 ("fixdep: faster CONFIG_ search") changed how to load files in which CONFIG options are searched. It used malloc() and read() instead of mmap() because it needed to zero-terminate the buffer to use strstr(). print_deps() was left untouched since there was no reason to change it. Now, I have two motivations to change it in the same way. - do_config_file() and print_deps() do quite similar things; they open a file, map it onto memory, and pass it to a parser function. If we use malloc() and read() for print_deps() too, we can factor out the common code. (I will do this in the next commit.) - parse_dep_file() copies each token to a temporary buffer because it needs to zero-terminate it to be passed to printf(). It is not possible to modify the buffer directly because it is mmap'ed with O_RDONLY. If we load the file content into a malloc'ed buffer, we can insert '\0' after each token, and save memcpy(). (I will do this in the commit after next.) Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 55 +++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 86a61d6..7efbeb7 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -309,24 +309,27 @@ static void do_config_file(const char *filename) * assignments are parsed not only by make, but also by the rather simple * parser in scripts/mod/sumversion.c. */ -static void parse_dep_file(void *map, size_t len) +static void parse_dep_file(char *m) { - char *m = map; - char *end = m + len; char *p; char s[PATH_MAX]; - int is_target; + int is_last, is_target; int saw_any_target = 0; int is_first_dep = 0; - while (m < end) { + while (1) { /* Skip any "white space" */ - while (m < end && (*m == ' ' || *m == '\\' || *m == '\n')) + while (*m == ' ' || *m == '\\' || *m == '\n') m++; + + if (!*m) + break; + /* Find next "white space" */ p = m; - while (p < end && *p != ' ' && *p != '\\' && *p != '\n') + while (*p && *p != ' ' && *p != '\\' && *p != '\n') p++; + is_last = (*p == '\0'); /* Is the token we found a target name? */ is_target = (*(p-1) == ':'); /* Don't write any target names into the dependency file */ @@ -374,6 +377,10 @@ static void parse_dep_file(void *map, size_t len) do_config_file(s); } } + + if (is_last) + break; + /* * Start searching for next token immediately after the first * "whitespace" character that follows this token. @@ -392,40 +399,42 @@ static void parse_dep_file(void *map, size_t len) printf("$(deps_%s):\n", target); } -static void print_deps(void) +static void print_deps(const char *filename) { struct stat st; int fd; - void *map; + char *buf; - fd = open(depfile, O_RDONLY); + fd = open(filename, O_RDONLY); if (fd < 0) { fprintf(stderr, "fixdep: error opening depfile: "); - perror(depfile); + perror(filename); exit(2); } if (fstat(fd, &st) < 0) { fprintf(stderr, "fixdep: error fstat'ing depfile: "); - perror(depfile); + perror(filename); exit(2); } if (st.st_size == 0) { - fprintf(stderr,"fixdep: %s is empty\n",depfile); close(fd); return; } - map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if ((long) map == -1) { - perror("fixdep: mmap"); - close(fd); - return; + buf = malloc(st.st_size + 1); + if (!buf) { + perror("fixdep: malloc"); + exit(2); } + if (read(fd, buf, st.st_size) != st.st_size) { + perror("fixdep: read"); + exit(2); + } + buf[st.st_size] = '\0'; + close(fd); - parse_dep_file(map, st.st_size); - - munmap(map, st.st_size); + parse_dep_file(buf); - close(fd); + free(buf); } int main(int argc, char *argv[]) @@ -441,7 +450,7 @@ int main(int argc, char *argv[]) cmdline = argv[3]; print_cmdline(); - print_deps(); + print_deps(depfile); return 0; } From patchwork Tue Jan 9 08:30:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123808 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3749836qgn; Tue, 9 Jan 2018 00:32:15 -0800 (PST) X-Google-Smtp-Source: ACJfBotZeqzWzPBFEODznJw+yqd5e1u7Psv8v8Qy5qkLNpdAzp/tSQADskZcsTxdGECjkyZTUnve X-Received: by 10.99.106.138 with SMTP id f132mr11667001pgc.115.1515486735722; Tue, 09 Jan 2018 00:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486735; cv=none; d=google.com; s=arc-20160816; b=BbxzqR9Mb4vG142UmQo6R3683MUr8B96Om187+HODKr0YrnOQgfpdg4aE8rgLh7DoW 5INbn45DF05gvDokAt5e9xXK/3ParfRxCcYJK0vb1HzmUDqsNXvO6DahJEZ3ObS7If7j wUY2EFNd9jzgjpnUXxnoiPs4ftZIGZ//e1BeNc3MkCtoAW2TSblb2eINzG5F1VAXb+bX gnzYJ0/Q8njgkmkuJT38jvFLJ7RRlVdKj9V0sV8Z2Ya19N74loLAXPGS3+NARzKz1qsT +Vwyrqw+BjAiZemgRJD/iodLK00Hd3LrDdHV/ZKAa2KPuX/OIgMo1JhPHfABPU+wcGM1 otGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=v4B8CfISkXQIbKsnFb/dV48dCxgpM5Y4NCLYNO3Js0I=; b=YyI68JVuGzxhKlsupKd4+mjYKjPCCQnTglP8Dmr5416bH7yv6CLhYxVcykoiQcg57o OCOfMD6FN4NX+lcg3omkzlb/0l0c0JTVgWbBWeJLsi6ArUzPQoRyyk7u2VHN1KPNdReS fUJVc4x6XpZ5rPUVL88fvyjAE/zSY783DsrWVmFX2VJmgZt05mIyN4dgvyPXmWr8Qvzh 7fdUyN1ToRSOmnW06MHeGwZn8TAkofb/yb0zxvqVsjxEwicY8X9lfflRxhcmxry71a1C i6LnNk3/56r//B/w9mitgTQSM6OHwgESZEjMjq2p+4qRFrtRA7pmWUokoEyVLrNoQPFb nSgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=zAkMbYNG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si10025924plb.153.2018.01.09.00.32.15; Tue, 09 Jan 2018 00:32:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=zAkMbYNG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbeAIIcN (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:13 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27465 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751439AbeAIIcD (ORCPT ); Tue, 9 Jan 2018 03:32:03 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugt024960; Tue, 9 Jan 2018 17:30:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugt024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486657; bh=v4B8CfISkXQIbKsnFb/dV48dCxgpM5Y4NCLYNO3Js0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zAkMbYNGUGadwwYykUh/KfBUVkkSoYj8GRc85XvhQUzumVZ4fB0bZTVedXQiPS3I9 Ev3bdRoBegl8hF3ra2OlkoBus7sHyHnjc6bPOKhtwLeH0tOcuMOnonxWJizgWH7Jlu TlpSRE+z5EmsHqgMrj/59MvwGc0RrosyQkmAQgbg2VS3w2yVueVE11JzXnzWrvC5oH aA/SteWfpL9Jo/ESPAnQ2HBdBrW41RP+ynTcfaSyJBKEnSYd1WQ7BdG3RgI/GG/tnA GDC2DYZHFgFb+RbxRLjG0XHjyzzg727gtyKYtXcSCpX6OSGvqpYxUjUnl/FHyViSGm s6jI77qjxWkcw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 2/6] fixdep: merge do_config_file() and print_deps() into load_file() Date: Tue, 9 Jan 2018 17:30:46 +0900 Message-Id: <1515486650-1141-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now, do_config_files() and print_deps() are almost the same. Only the difference is the parser function called (parse_config_file vs parse_dep_file). We can reduce the code duplication by putting the common code into load_file() - this function allocates a buffer and loads a file to it. It returns the pointer to the allocated buffer. (As before, it bails out by exit(2) for any error.) The caller must free the buffer when done. Having empty source files is possible; fixdep should simply skip them. I deleted the "st.st_size == 0" check, so load_file() allocates 1-byte buffer for an empty file. strstr() will just return NULL, and this is what we expect. On the other hand, empty dep_file should be treated as an error. In this case, parse_dep_file() will error out with "no targets found" and it is a correct error message. Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 75 ++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 55 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 7efbeb7..f954f226 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -266,42 +266,36 @@ static int strrcmp(const char *s, const char *sub) return memcmp(s + slen - sublen, sub, sublen); } -static void do_config_file(const char *filename) +static void *load_file(const char *filename) { struct stat st; int fd; - char *map; + char *buf; fd = open(filename, O_RDONLY); if (fd < 0) { - fprintf(stderr, "fixdep: error opening config file: "); + fprintf(stderr, "fixdep: error opening file: "); perror(filename); exit(2); } if (fstat(fd, &st) < 0) { - fprintf(stderr, "fixdep: error fstat'ing config file: "); + fprintf(stderr, "fixdep: error fstat'ing file: "); perror(filename); exit(2); } - if (st.st_size == 0) { - close(fd); - return; - } - map = malloc(st.st_size + 1); - if (!map) { + buf = malloc(st.st_size + 1); + if (!buf) { perror("fixdep: malloc"); exit(2); } - if (read(fd, map, st.st_size) != st.st_size) { + if (read(fd, buf, st.st_size) != st.st_size) { perror("fixdep: read"); exit(2); } - map[st.st_size] = '\0'; + buf[st.st_size] = '\0'; close(fd); - parse_config_file(map); - - free(map); + return buf; } /* @@ -316,6 +310,7 @@ static void parse_dep_file(char *m) int is_last, is_target; int saw_any_target = 0; int is_first_dep = 0; + void *buf; while (1) { /* Skip any "white space" */ @@ -374,7 +369,10 @@ static void parse_dep_file(char *m) is_first_dep = 0; } else printf(" %s \\\n", s); - do_config_file(s); + + buf = load_file(s); + parse_config_file(buf); + free(buf); } } @@ -399,46 +397,10 @@ static void parse_dep_file(char *m) printf("$(deps_%s):\n", target); } -static void print_deps(const char *filename) -{ - struct stat st; - int fd; - char *buf; - - fd = open(filename, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "fixdep: error opening depfile: "); - perror(filename); - exit(2); - } - if (fstat(fd, &st) < 0) { - fprintf(stderr, "fixdep: error fstat'ing depfile: "); - perror(filename); - exit(2); - } - if (st.st_size == 0) { - close(fd); - return; - } - buf = malloc(st.st_size + 1); - if (!buf) { - perror("fixdep: malloc"); - exit(2); - } - if (read(fd, buf, st.st_size) != st.st_size) { - perror("fixdep: read"); - exit(2); - } - buf[st.st_size] = '\0'; - close(fd); - - parse_dep_file(buf); - - free(buf); -} - int main(int argc, char *argv[]) { + void *buf; + if (argc == 5 && !strcmp(argv[1], "-e")) { insert_extra_deps = 1; argv++; @@ -450,7 +412,10 @@ int main(int argc, char *argv[]) cmdline = argv[3]; print_cmdline(); - print_deps(depfile); + + buf = load_file(depfile); + parse_dep_file(buf); + free(buf); return 0; } From patchwork Tue Jan 9 08:30:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123809 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3749853qgn; Tue, 9 Jan 2018 00:32:16 -0800 (PST) X-Google-Smtp-Source: ACJfBosWqdnpN8lwhYTnWgg08OY4nQc7zNO6QJK5flTo4LMCWLKbugkMy4eBwA/90HC0YMnOTNX7 X-Received: by 10.101.65.136 with SMTP id a8mr11434813pgq.363.1515486736855; Tue, 09 Jan 2018 00:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486736; cv=none; d=google.com; s=arc-20160816; b=WtBs6A/rQtuOeG+38YwzuldkFu5I571xH+SUqqfuuVYbdm2QL4aFY3GCPPMSUB9e3w 92mc8KoPSJ7Y7Z5bMn6LcrvDdwWuUblcCuDNbmVYN1DhhhONg6qGIIrN+1t8svJxa2Ox iyEi1pi6zdg6oC+f2L2UO6c0h9BCI9as+6reYzgz6EyFnKh700EpVag1iRRHUFWNaGZl yr9E5uOG7T7jYCVDQC4uU+K51dDz9BIocELLIwa5aE2YvWG7eqYMX4V0IiflR+Ntyg/+ KoYxN3z5MJioU4NVeDkbcnMTrJEUpp7fk2MpzNEk/JJjR953zKcCp8V5zBHALmmIhxvz mViw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=LrFNKyFPpj8wWsQU2ha3UwSEuZKFoYfCXb+WzqfOflE=; b=pRxo6nV32D0KFcdRZu02FYzv7RW5F6QXYiCoBjp6hNqpXUPDpNxbc9nTiNVpM4acKi AwmmZeHOwkFN1EJypHdH/7AFhN2/++wjq90i+4l8PafdTFVNYgS0JsPE3PJMXghVhLq5 5C9CVyt/O2hnZ14h2CpUFt5+WIfmrOw0s7gzNEB3tS4220MBqjhs4fbLUC8n65l01PAb qlLyTWChgSNEm6vjIuR7ftz6HuC96cP2j0akv7fta7xSvByfzlSAhMlUkCxVJCfhFe38 Y3PpRNzxE7JvymS1+xAdDARPtxi3OwWjD5c70YnKAa/elPtbCrsX/2smpxWADit2lN5x bn+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=bBKhCLdF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si10025924plb.153.2018.01.09.00.32.16; Tue, 09 Jan 2018 00:32:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=bBKhCLdF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751579AbeAIIcO (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:14 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27464 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751127AbeAIIcD (ORCPT ); Tue, 9 Jan 2018 03:32:03 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugu024960; Tue, 9 Jan 2018 17:30:57 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugu024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486658; bh=LrFNKyFPpj8wWsQU2ha3UwSEuZKFoYfCXb+WzqfOflE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bBKhCLdFyKNryN35B0LVHntwZEfutu+Rqpol8haAYIOIvbTAEQ02Svje7wPkU25NV jvegFKbvJznn1QAn89/eDQqe+skIFlwW97QwK44h2a1gf7lCaETfOdrj8hcdHWB18x pIv1xxHfP6EEE/4nny+WHzsfoSbe8crsQ6R39t57HRLUT7gPW0rT0Pihuy9/H3kQcu umskr2DuL+B4eJZspGigtzzThrFn3NzkS8AhfmNMwMkX69dQSsh/m/6ws7QQGFQGCI /l2a4Cp6MTDXHtD3uMvlduobzOhYnHjytAx2eqAyHMnlBVKrn3aPGMznZ3eJDwuTs7 Maagz8jzaooOA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 3/6] fixdep: remove unneeded memcpy() in parse_dep_file() Date: Tue, 9 Jan 2018 17:30:47 +0900 Message-Id: <1515486650-1141-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each token in the depfile is copied to the temporary buffer 's' to terminate the token with zero. We do not need to do this any more because the parsed buffer is now writable. Insert '\0' directly in the buffer without calling memcpy(). Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index f954f226..bc2364e 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -306,7 +306,6 @@ static void *load_file(const char *filename) static void parse_dep_file(char *m) { char *p; - char s[PATH_MAX]; int is_last, is_target; int saw_any_target = 0; int is_first_dep = 0; @@ -332,16 +331,14 @@ static void parse_dep_file(char *m) /* The /next/ file is the first dependency */ is_first_dep = 1; } else { - /* Save this token/filename */ - memcpy(s, m, p-m); - s[p - m] = 0; + *p = '\0'; /* Ignore certain dependencies */ - if (strrcmp(s, "include/generated/autoconf.h") && - strrcmp(s, "include/generated/autoksyms.h") && - strrcmp(s, "arch/um/include/uml-config.h") && - strrcmp(s, "include/linux/kconfig.h") && - strrcmp(s, ".ver")) { + if (strrcmp(m, "include/generated/autoconf.h") && + strrcmp(m, "include/generated/autoksyms.h") && + strrcmp(m, "arch/um/include/uml-config.h") && + strrcmp(m, "include/linux/kconfig.h") && + strrcmp(m, ".ver")) { /* * Do not list the source file as dependency, * so that kbuild is not confused if a .c file @@ -362,15 +359,15 @@ static void parse_dep_file(char *m) if (!saw_any_target) { saw_any_target = 1; printf("source_%s := %s\n\n", - target, s); + target, m); printf("deps_%s := \\\n", target); } is_first_dep = 0; } else - printf(" %s \\\n", s); + printf(" %s \\\n", m); - buf = load_file(s); + buf = load_file(m); parse_config_file(buf); free(buf); } From patchwork Tue Jan 9 08:30:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123807 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3749693qgn; Tue, 9 Jan 2018 00:32:06 -0800 (PST) X-Google-Smtp-Source: ACJfBou36FY90cEW0uxK5MkPj/nEfleq+tulLcX6lvkLrh0QXO+4e/Xs3L9Sna4s4Pmc9mdpkCKs X-Received: by 10.99.107.195 with SMTP id g186mr10831449pgc.97.1515486726205; Tue, 09 Jan 2018 00:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486726; cv=none; d=google.com; s=arc-20160816; b=Nm7fPFGSDnd7OmkEyUZcURTI2RBKm05zrjLPOyuNnsvu/GHpIrF2qirMTS5XvscQqd ZjExeaBfoSSHQt69CoWZ4ezIfWOuG8txfe1POlvjb2l6IdVCGIiR2EAjaisZV+tJv6CI 95WTzJMU0tlaz63Bm00989yBYN+Y1HFeegX4kKKDPibAZkcHZwiqRD5O0ZfG7mh6m1qO RXUZfGuC4oXAiRbxiPn6/HVeydnxeICSlEt+gC4CbH6ljbCvUm5EIh6g6e5yGzapb2jw LpY4YkfYZqjMnVF5ghzuQ1oLFz/yRBZSEQke9IkN3Ashn5pxXSJVjRmBMjNbJdFNXamd NKrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=kFQqw9B1ZpEwtLnGmxlW+fopBVk/ZdaFpWqH3N7SoBE=; b=wa9CscRnNKUCPcQ53/QF4GxT4nS9fNqmuBDzK/+pkyW8o3/WXnZoUBjEgoGMPr0qh6 zJWNubxfG27cHcxqNrcKMX4OP5ADdckWYhTG07Y6uSltKmPb1+L1JQ+q/YYA/hXZWWil gpenZgC6N7dEMqPdFtDvG2R/W0x7bwaz0qFePnfXmfGCsHu5kZJ3Nt0fCg4gjD1kJeEP Z4eM/Y++seHlisUsClFYEA9gWy2LvwdPt+i0adPQtfa+VkeFYpdwBJ1XuFhBC0+JdFQb dlTEtcTzhOFEHr5h6NfTJvLxgArIIH1edYgjthtB8132tNeEcVj5A0IiDnW9EuDimA1H WV2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Rk/VE+DK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e190si9729631pfe.96.2018.01.09.00.32.05; Tue, 09 Jan 2018 00:32:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Rk/VE+DK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751477AbeAIIcE (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:04 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27300 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751150AbeAIIb7 (ORCPT ); Tue, 9 Jan 2018 03:31:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugv024960; Tue, 9 Jan 2018 17:30:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugv024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486658; bh=kFQqw9B1ZpEwtLnGmxlW+fopBVk/ZdaFpWqH3N7SoBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rk/VE+DKzpNpaQRHSGqF8/5JgfhD5grucX0gFc1RcRSSkGU+nPjn9TQezQ30cmOa8 OJDInSmWz9C8UK9jA3HbXKmyw6y/gNIxiSzWNvGtcC++zr6JEmvVFPxZqPpztXiD8R YM8ARKOLQ2L4KnXpBaiAFV1o7W63iM/hcjY5fQeW9GgZvoEv4RgxwlOPNj4c09sYtT wmiqpY19Tg5uJPdv1++qE/ZDllstFRC4QgSnGWr3Wr5lAvYnj8HSSXm0tn3HTUzRHT uwYG4nbwfHEpL+nsyY2ou4+t4aAgSglbSDiraSoKe+CjBPLz1ctbnqiNyKFFD6d0s4 cbuNwRY4DYYAw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 4/6] fixdep: move global variables to local variables of main() Date: Tue, 9 Jan 2018 17:30:48 +0900 Message-Id: <1515486650-1141-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I do not mind global variables where they are useful enough. In this case, I do not see a good reason to use global variables since they are just referenced in shallow places. It is easy to pass them via function arguments. Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bc2364e..bb6d2da 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -114,11 +114,6 @@ #include #include -int insert_extra_deps; -char *target; -char *depfile; -char *cmdline; - static void usage(void) { fprintf(stderr, "Usage: fixdep [-e] \n"); @@ -129,7 +124,7 @@ static void usage(void) /* * Print out the commandline prefixed with cmd_ := */ -static void print_cmdline(void) +static void print_cmdline(const char *target, const char *cmdline) { printf("cmd_%s := %s\n\n", target, cmdline); } @@ -155,16 +150,16 @@ static void print_config(const char *m, int slen) static void do_extra_deps(void) { - if (insert_extra_deps) { - char buf[80]; - while(fgets(buf, sizeof(buf), stdin)) { - int len = strlen(buf); - if (len < 2 || buf[len-1] != '\n') { - fprintf(stderr, "fixdep: bad data on stdin\n"); - exit(1); - } - print_config(buf, len-1); + char buf[80]; + + while (fgets(buf, sizeof(buf), stdin)) { + int len = strlen(buf); + + if (len < 2 || buf[len - 1] != '\n') { + fprintf(stderr, "fixdep: bad data on stdin\n"); + exit(1); } + print_config(buf, len - 1); } } @@ -303,7 +298,7 @@ static void *load_file(const char *filename) * assignments are parsed not only by make, but also by the rather simple * parser in scripts/mod/sumversion.c. */ -static void parse_dep_file(char *m) +static void parse_dep_file(char *m, const char *target, int insert_extra_deps) { char *p; int is_last, is_target; @@ -388,7 +383,8 @@ static void parse_dep_file(char *m) exit(1); } - do_extra_deps(); + if (insert_extra_deps) + do_extra_deps(); printf("\n%s: $(deps_%s)\n\n", target, target); printf("$(deps_%s):\n", target); @@ -396,6 +392,8 @@ static void parse_dep_file(char *m) int main(int argc, char *argv[]) { + const char *depfile, *target, *cmdline; + int insert_extra_deps = 0; void *buf; if (argc == 5 && !strcmp(argv[1], "-e")) { @@ -408,10 +406,10 @@ int main(int argc, char *argv[]) target = argv[2]; cmdline = argv[3]; - print_cmdline(); + print_cmdline(target, cmdline); buf = load_file(depfile); - parse_dep_file(buf); + parse_dep_file(buf, target, insert_extra_deps); free(buf); return 0; From patchwork Tue Jan 9 08:30:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123811 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3750396qgn; Tue, 9 Jan 2018 00:32:57 -0800 (PST) X-Google-Smtp-Source: ACJfBotdzbyjZc4nnIjYIS93s+A4HLp9qD6i4+ZmkTC8o8H8kcwL66F1hYY7cILTZU/bYs2PJHFX X-Received: by 10.98.79.12 with SMTP id d12mr5841354pfb.186.1515486777897; Tue, 09 Jan 2018 00:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486777; cv=none; d=google.com; s=arc-20160816; b=ukUKmpkos4JOR+EymRk8G/KcOfmHe8k04gvtKpTabZ6NXc8a1XG64PenHFVtWX5KzK kTS/aaJszYp13CCOclvO/l2yBs6v4ryUAYl6leE2jTY6ZYtmC6zjrui+PiEhrKOSp4Ob cYFb2e8FrBZCX7QZBImaUB/EY3J1+ZO0e18nv01i8nER2XZLFgJ/PA40R/TCNNrKMG8f e9bCzufKKS4rUYnMKd3vwSnZoK+r+mhR+5cwAF1fTrwquV21SeUSY782g+mtpFg6For9 w3yP7PBg8IrCloVfupqpOgUj425Iceg5t7joBumc+hbunU7BoD4NOAuLgM6CLazxfgw9 Vz2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=p2IiKeUeeCM1PZk1FiBC3mNu2+yZuCe6Dxyrlt1dsLI=; b=EhHK0KrbnTks9336QUmDHIzf/G4JkJlKxdqC/dBjH79WoGnuwxMx/dbh4BVk2JwUpB PqGg7K39AVWeI1mt/B13PU3eXgdNCXE93wPODdktm57+PqAgo1LV/rVltfIYIQJ4HHf5 Xee7sHWFrF7kPxPZ3z/m0db+9c9MCHkXd7uYNpPLibEBkn8589oDKt2NyS2r58sE9E2O IkxIstHdRes7wkM5dXw03HRvfm/MoFGtEK0HA74DNTiK4yl9tQ1djW36KywOQBPl2Izy jEMxA1MTUwJGo6lI8hRdmP1GyiAtjAwKukUYmGB5jYjzy2BpH/yhAk/JkUC7FQGWzGTq 1pGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QxaMMGre; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si8703618pgc.748.2018.01.09.00.32.57; Tue, 09 Jan 2018 00:32:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QxaMMGre; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751388AbeAIIcB (ORCPT + 28 others); Tue, 9 Jan 2018 03:32:01 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27301 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750985AbeAIIb7 (ORCPT ); Tue, 9 Jan 2018 03:31:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugw024960; Tue, 9 Jan 2018 17:30:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugw024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486659; bh=p2IiKeUeeCM1PZk1FiBC3mNu2+yZuCe6Dxyrlt1dsLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QxaMMGrefYwC38qjfMpZy1emijJWar2O2XCXvW71tWio9AqJCCwBWnm/Wr3PHJcMX BZIBCk1/25DWjKSfKs2Kbl29Ss5d7kpSKDFWqRh1X+FIgM7Il6TYB8aUIhRk8oo0HG rY2pja2N0BPMMm+u6NLMSkE6p2ZBYDVK9q6vOQlOCrcjOTIuwekCXQOKsTvEVMNOp2 ruAWZT5llXLL71NVUIkCnebkBQhBHbasBoNtrjj+lUhsUJx9DaxkwKO7bzmdNiOFm3 rzG7DZNYPh6ZUGbdxcmzi56ajA4eSkiZ30gmnxW1d/KQikV5aJe6+iCkBELNeJdBUH 5NZcW+DvJc7cw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] fixdep: refactor parse_dep_file() Date: Tue, 9 Jan 2018 17:30:49 +0900 Message-Id: <1515486650-1141-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org parse_dep_file() has too much indentation, and puts the code far to the right. This commit refactors the code and reduces the one level of indentation. strrcmp() computes 'slen' by itself, but the caller already knows the length of the token, so 'slen' can be passed via function argument. With this, we can swap the order of strrcmp() and "*p = \0;" Also, strrcmp() is an ambiguous function name. Flip the logic and rename it to str_ends_with(). I added a new helper is_ignored_file() - this returns 1 if the token represents a file that should be ignored. Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bb6d2da..3881bf1 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -250,15 +250,14 @@ static void parse_config_file(const char *p) } /* test if s ends in sub */ -static int strrcmp(const char *s, const char *sub) +static int str_ends_with(const char *s, int slen, const char *sub) { - int slen = strlen(s); int sublen = strlen(sub); if (sublen > slen) - return 1; + return 0; - return memcmp(s + slen - sublen, sub, sublen); + return !memcmp(s + slen - sublen, sub, sublen); } static void *load_file(const char *filename) @@ -293,6 +292,16 @@ static void *load_file(const char *filename) return buf; } +/* Ignore certain dependencies */ +static int is_ignored_file(const char *s, int len) +{ + return str_ends_with(s, len, "include/generated/autoconf.h") || + str_ends_with(s, len, "include/generated/autoksyms.h") || + str_ends_with(s, len, "arch/um/include/uml-config.h") || + str_ends_with(s, len, "include/linux/kconfig.h") || + str_ends_with(s, len, ".ver"); +} + /* * Important: The below generated source_foo.o and deps_foo.o variable * assignments are parsed not only by make, but also by the rather simple @@ -325,47 +334,38 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) if (is_target) { /* The /next/ file is the first dependency */ is_first_dep = 1; - } else { + } else if (!is_ignored_file(m, p - m)) { *p = '\0'; - /* Ignore certain dependencies */ - if (strrcmp(m, "include/generated/autoconf.h") && - strrcmp(m, "include/generated/autoksyms.h") && - strrcmp(m, "arch/um/include/uml-config.h") && - strrcmp(m, "include/linux/kconfig.h") && - strrcmp(m, ".ver")) { + /* + * Do not list the source file as dependency, so that + * kbuild is not confused if a .c file is rewritten + * into .S or vice versa. Storing it in source_* is + * needed for modpost to compute srcversions. + */ + if (is_first_dep) { /* - * Do not list the source file as dependency, - * so that kbuild is not confused if a .c file - * is rewritten into .S or vice versa. Storing - * it in source_* is needed for modpost to - * compute srcversions. + * If processing the concatenation of multiple + * dependency files, only process the first + * target name, which will be the original + * source name, and ignore any other target + * names, which will be intermediate temporary + * files. */ - if (is_first_dep) { - /* - * If processing the concatenation of - * multiple dependency files, only - * process the first target name, which - * will be the original source name, - * and ignore any other target names, - * which will be intermediate temporary - * files. - */ - if (!saw_any_target) { - saw_any_target = 1; - printf("source_%s := %s\n\n", - target, m); - printf("deps_%s := \\\n", - target); - } - is_first_dep = 0; - } else - printf(" %s \\\n", m); - - buf = load_file(m); - parse_config_file(buf); - free(buf); + if (!saw_any_target) { + saw_any_target = 1; + printf("source_%s := %s\n\n", + target, m); + printf("deps_%s := \\\n", target); + } + is_first_dep = 0; + } else { + printf(" %s \\\n", m); } + + buf = load_file(m); + parse_config_file(buf); + free(buf); } if (is_last) From patchwork Tue Jan 9 08:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 123812 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3750599qgn; Tue, 9 Jan 2018 00:33:11 -0800 (PST) X-Google-Smtp-Source: ACJfBouNI1Ak4r2F4UE5jRv0zwSPwQhTJV8Vy5nMFrioVmbj6s7lOiN78rU6oBj1DXH0NfsW08+w X-Received: by 10.159.205.146 with SMTP id v18mr14913701plo.25.1515486791530; Tue, 09 Jan 2018 00:33:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515486791; cv=none; d=google.com; s=arc-20160816; b=K17ZPg7K3KHR8yqDYEYBgbPuYVj0Wl6qwqo7CkBaLscHnH1SbQqtvvqqHYiUWgs7RK bTKsW8apMvy9tU/ruLUJ+/4fCijJ9VxD9/vsh79BzeXKoU04oiGRWKDOymePMuaq2yvT +j6X88iqTDj8rrhcZ8rSo0cmxNs9UNBzroSoi1SUMstqlJ6qKkEDUYHrnK7LmtSocOaa fvG6XbW0PvWlpC9D2bZ1gGZlDHfkCcUXpFx9MrC0WF3BiN/bLbeaqpELcjgGnkztKOSN Ip8zBFvSJqcikPi487jNbzuGfTSUOpConR/+k9b6GFAJlwuxdpgS4xzuIztmGa7QVaeR y7cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=BJd2E3GJT7zB/OoAoqW6c8vZf0/AtDkjskHmgpQhRc0=; b=iLmZASjKKZRqjA0Xyk/6gATzqChrhMvryRevNgxH586u4X59KuMJ7jB5Q0sXFzXrao bt/XkN4AI6Kj6RKysknehq1OF9vD+WncO8/V1D01QmrY7Dly5aEO6Lqu7qmFmldNQNBa voDN54ea5oM7cdHWU3ekAg01xSkGoMMFN7u8JTozxGAMq+npVpwg33MHMlO22x/vkVpH 3ZIP7ulRsby3Q72cYal3KLmJGKgFlDK3sKi4eqplt8aeH46lTZxLWDY5NNWQcnGmw22/ WGPn/Pstbddej5m5twU24Jkokvur0LeQ1DoqdNKyQBbTmsy/3rhBb+lPJi1VIWDjlIwZ jTCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=V9rb1hgt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h62si8729124pgc.306.2018.01.09.00.33.11; Tue, 09 Jan 2018 00:33:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=V9rb1hgt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751636AbeAIIdI (ORCPT + 28 others); Tue, 9 Jan 2018 03:33:08 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:27298 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751145AbeAIIb7 (ORCPT ); Tue, 9 Jan 2018 03:31:59 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w098Uugx024960; Tue, 9 Jan 2018 17:30:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w098Uugx024960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515486660; bh=BJd2E3GJT7zB/OoAoqW6c8vZf0/AtDkjskHmgpQhRc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V9rb1hgtvLohIS0MgDv5vgBbvRdDGajMz3t20gc448w5RsIJ6BUEpz9xH4fojt1Rf GZVOaIvLI+zFe4aUuiE7l4oCXBBJYYceaywXbB5HPXybBhqeg+wWvDrLoSTk72xK6C TrEv3gLvQUL4zROygc2wMcYIS/4/wxA+8MaD2XEy027CujdkIAYHAslh11c+VbRQPp ae3WaVYWlGCO5rldPMfv0FI0V7Be/kPYwhqoa2ivGVU/MWSTGUQ6JKrKBrbOwB8zVU lw5YTbew3aOqka4lQkYvKJ5ABrQQtLIuX+7wtoAhqrILcB0xPvg8zpui5yTNtG6OLV l5MvIh1c8/vRQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Lukas Bulwahn , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 6/6] fixdep: use existing helper to check modular CONFIG options Date: Tue, 9 Jan 2018 17:30:50 +0900 Message-Id: <1515486650-1141-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> References: <1515486650-1141-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org str_ends_with() (it was strrcmp() before) was introduced to check if the given token ends with a particular string. Currently, it is used to check file paths without $(srctree). Actually, we have one more place where this helper is useful. Use it to check if CONFIG option ends with _MODULE. Signed-off-by: Masahiro Yamada --- scripts/basic/fixdep.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 3881bf1..9642302 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -230,6 +230,17 @@ static void use_config(const char *m, int slen) print_config(m, slen); } +/* test if s ends in sub */ +static int str_ends_with(const char *s, int slen, const char *sub) +{ + int sublen = strlen(sub); + + if (sublen > slen) + return 0; + + return !memcmp(s + slen - sublen, sub, sublen); +} + static void parse_config_file(const char *p) { const char *q, *r; @@ -239,7 +250,7 @@ static void parse_config_file(const char *p) q = p; while (*q && (isalnum(*q) || *q == '_')) q++; - if (memcmp(q - 7, "_MODULE", 7) == 0) + if (str_ends_with(p, q - p, "_MODULE")) r = q - 7; else r = q; @@ -249,17 +260,6 @@ static void parse_config_file(const char *p) } } -/* test if s ends in sub */ -static int str_ends_with(const char *s, int slen, const char *sub) -{ - int sublen = strlen(sub); - - if (sublen > slen) - return 0; - - return !memcmp(s + slen - sublen, sub, sublen); -} - static void *load_file(const char *filename) { struct stat st;