Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1119393iof; Mon, 6 Jun 2022 21:30:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8v6h+Vd097WSmZzjm9xYpKIw5lcd57rivxLmHqy2Q++IO4BvRW422RuwDo/2z66Mqy7cU X-Received: by 2002:a05:6402:2696:b0:42f:aa52:aca7 with SMTP id w22-20020a056402269600b0042faa52aca7mr21018344edd.358.1654576223365; Mon, 06 Jun 2022 21:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654576223; cv=none; d=google.com; s=arc-20160816; b=dSPgeGFpZxqiW1Yld6tVocYzNfA5g8A0YXhI8r39FgbkSxns2AWGZN4SVTRuo7e9Sw +f2UopqSz7mAIfWbi5sTOJJElgl0O+dc2ntKjrwpSdq48nJK1c1jgysiQYkNJfhRF0FA TVgOv7teGixMJamhm+sdsOkiYy8l7oxoSfx2d5UWLb1Pq0v9Ex9Qh1vLEj4TUZARBUFy 1adWKUQAza1V447ts6UZb/EzFQArUeprwFTCbmJjyQUHqa0te7g8Q9bephokg/HR82WZ qrI50+95enkgjwtqZ1cwPOsDmpxNJ4ylEP1OcHV3zwn9Wrv71NyNcJRgbqTVHype6N78 ZdhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gvgkNt5AvonmRpEaW+kJLiTrofK1h4p2ZLrrpF3hb6g=; b=nEgdcFRn39duKqAz5zWhjYpnnXGN5ERtVqZQm8EVYZWjcLFnPW3t3aREApkaLYbjD9 WelRyza/ptUyfaYydTfufVimnt5HTWI5+MuaWXePzVpdKCDbSusaCBJUuJngL3akcB4I zxeJI1sQzJMZlgmqm/sgRsiBqFCXqX9kakKwSZamZoYu8HluRZHmgdY6087VzRF6+Lp0 7dVkt2RTsoW3kqiWAtu+uoiQ8kzYMYszCHCDNax4io8dLHyBnPLYoB6IuTVHZk6A/ic9 2y1bLher+RG2TO1hWBgPVnZPSRreopnhqBZaJNtA2MUg2ApPVyd9dArx4wDt132s4SbD 9hLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WhNfhPUv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c21-20020aa7df15000000b0042baca38617si1800844edy.89.2022.06.06.21.29.32; Mon, 06 Jun 2022 21:30:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=WhNfhPUv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233486AbiFFUQ7 (ORCPT + 99 others); Mon, 6 Jun 2022 16:16:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233411AbiFFUQp (ORCPT ); Mon, 6 Jun 2022 16:16:45 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23A1D6FD13 for ; Mon, 6 Jun 2022 13:16:36 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id h23so25063424lfe.4 for ; Mon, 06 Jun 2022 13:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gvgkNt5AvonmRpEaW+kJLiTrofK1h4p2ZLrrpF3hb6g=; b=WhNfhPUvNR4xNPpmPIjOZ33SDP8SNm1f2V4XQziGGsbFEtvGuEO+7kncu8CVybQwni AMLGCqzs7wPsZyXipxxAwpUY/yl7XxFEL5XoitJLAncOtiDSdLJcHhE7FP/KDQSZlSXj OkM0v+9UL4+z1yVDJoDbPydh4/vFaFxnleL43I4CVAl376fOD4K5ZhSspoxP6eRFVdKe LPgZ1RzYk3AVRNPr7YLg2V8pT0sq/EHnrM4pbKL3A5EuWKJ+wRM+VYPPREfAXnoB163b zBORHrb5Xncjv7rqstJhMH5ZcWINBCWncuVyK6oUlgMkBcBfmSU2cgqZ0I+bgQN5XY1e K1DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gvgkNt5AvonmRpEaW+kJLiTrofK1h4p2ZLrrpF3hb6g=; b=1AV+gEWCbRxAB9sQexY70dlbDr5xYFDGqnfjcgw1D+afAbfJZtBezMImsKmE9z/xTz NEW4EPyEWINoTE6nB06m/rZnfK3dH+zw1S/72Izz61SW6id900zSpZ9zrE0LJO4/xFHr 5J4Mic9zM1rT0Vc/hH6zt1ZsrGTlOx8GIvTiPOvZtyguoBgjEZx4ijVqPGm+sHvBup+Q 7x8l//yuIAZ+IRswpUbI2os+1xgYKKwBuFgAWfjAqdU3FRGR0Z8DmKRckGAt5sINMcj7 Cb7xcEaQtoDfQKSZMFfIwFhNV9xWxSGElaoIirqi2pRKQIzUfJWO4l7r+8X++T/8cweZ ctRA== X-Gm-Message-State: AOAM530H5QJcaDGblViTRlEgP6labKhP+lwWLwY6CyeZsDtPd+9eSXfl w3rgvmUXb0xtQMg4954o/75Vh2I2K+CTWciPZIdybRlzkE4= X-Received: by 2002:a05:6512:3f1a:b0:477:8ecd:368c with SMTP id y26-20020a0565123f1a00b004778ecd368cmr64495550lfa.403.1654546594123; Mon, 06 Jun 2022 13:16:34 -0700 (PDT) MIME-Version: 1.0 References: <20220530090139.3030866-1-masahiroy@kernel.org> <20220530090139.3030866-2-masahiroy@kernel.org> In-Reply-To: <20220530090139.3030866-2-masahiroy@kernel.org> From: Nick Desaulniers Date: Mon, 6 Jun 2022 13:16:22 -0700 Message-ID: Subject: Re: [PATCH 2/2] modpost: use fnmatch() to simplify match() To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Marek Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 30, 2022 at 2:03 AM Masahiro Yamada wrote: > > Replace the own implementation for wildcard (glob) matching with > a function call to the library function, fnmatch(). > > Also, change the return type to 'bool'. > > Signed-off-by: Masahiro Yamada Thanks for the patch! Reviewed-by: Nick Desaulniers > --- > > scripts/mod/modpost.c | 74 ++++++++----------------------------------- > 1 file changed, 13 insertions(+), 61 deletions(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index c1558bacf717..29d5a841e215 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -13,6 +13,7 @@ > > #define _GNU_SOURCE > #include > +#include > #include > #include > #include > @@ -710,29 +711,6 @@ static char *get_modinfo(struct elf_info *info, const char *tag) > return get_next_modinfo(info, tag, NULL); > } > > -/** > - * Test if string s ends in string sub > - * return 0 if match > - **/ > -static int strrcmp(const char *s, const char *sub) > -{ > - int slen, sublen; > - > - if (!s || !sub) > - return 1; > - > - slen = strlen(s); > - sublen = strlen(sub); > - > - if ((slen == 0) || (sublen == 0)) > - return 1; > - > - if (sublen > slen) > - return 1; > - > - return memcmp(s + slen - sublen, sub, sublen); > -} > - > static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) > { > if (sym) > @@ -741,48 +719,22 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) > return "(unknown)"; > } > > -/* The pattern is an array of simple patterns. > - * "foo" will match an exact string equal to "foo" > - * "*foo" will match a string that ends with "foo" > - * "foo*" will match a string that begins with "foo" > - * "*foo*" will match a string that contains "foo" > +/* > + * Check whether the 'string' argument matches one of the 'patterns', > + * an array of shell wildcard patterns (glob). > + * > + * Return true is there is a match. > */ > -static int match(const char *sym, const char * const pat[]) > +static bool match(const char *string, const char *const patterns[]) > { > - const char *p; > - while (*pat) { > - const char *endp; > - > - p = *pat++; > - endp = p + strlen(p) - 1; > + const char *pattern; > > - /* "*foo*" */ > - if (*p == '*' && *endp == '*') { > - char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2)); > - char *here = strstr(sym, bare); > - > - free(bare); > - if (here != NULL) > - return 1; > - } > - /* "*foo" */ > - else if (*p == '*') { > - if (strrcmp(sym, p + 1) == 0) > - return 1; > - } > - /* "foo*" */ > - else if (*endp == '*') { > - if (strncmp(sym, p, strlen(p) - 1) == 0) > - return 1; > - } > - /* no wildcards */ > - else { > - if (strcmp(p, sym) == 0) > - return 1; > - } > + while ((pattern = *patterns++)) { > + if (!fnmatch(pattern, string, 0)) > + return true; > } > - /* no match */ > - return 0; > + > + return false; > } > > /* sections that we do not want to do full section mismatch check on */ > -- > 2.32.0 > -- Thanks, ~Nick Desaulniers