Message ID | CAG_fn=WZnBtRujLyhouz1AmerSKB71oPej442JDOw2OaORbWQg@mail.gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp442349wrd; Fri, 3 Mar 2023 06:36:06 -0800 (PST) X-Google-Smtp-Source: AK7set8DF58uAD7e85/yDxv1oBs1ErFeAV8+q1A9vScmZAx3vHpBUnWc3ZLLje9ZwoSP2rHQHkRC X-Received: by 2002:a17:902:ec92:b0:19d:397b:f05 with SMTP id x18-20020a170902ec9200b0019d397b0f05mr2461430plg.32.1677854165775; Fri, 03 Mar 2023 06:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677854165; cv=none; d=google.com; s=arc-20160816; b=shBS4DG+zkGBVHm2D2GQwiyML3za427a2w44ltuoHAhqPhfOnDPp36LakbFA/yvKXu UGe/EbG6FoAqQl1OUAuKxG+agCSdLqJMvcVvVVez8BdRbC/0pLxB3P8NdZiHuL0xiHIo f6J/bSXo3mfER2fG7r+wlgU+wNrRL0yT0b+1IpNxCisWyrEvHsqqsu/xKQ9i1YsAbG0v VfXKkxstG58LqGmBQxWBr6jp7jh9ULcXyGfjlFAv4ECrsoZ/sANuWECo4zGhBxxQsfa+ tvzrx4x+cRECmS1Mz4A6BT8HVaSGvbEr88m83snvt8ySJEg8PHtsf0WKNxAGNYpzZq+e GAjg== 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:mime-version :dkim-signature; bh=PRcr1qg5pQOktZ9kX0ziwdm9E4pyF51eI2ym5oRUyFE=; b=jx2xJkk6cyEtHr7aCpg19/pbKRHTzdDudUc75EzayXSUEkNjg6ZtYQ0s5n5J9CNO37 GEdy+Uxm3DA9THYWPiy4hzHgbLtA1+1FEFV6O+Z7KYgNur5MBFs1ZQjC2mQo68VGgpMX 23lxWjjuh/Qayu9b87iYC5GRoiQqe6frZpzio6rQLKcTMNj54exAcrgXeqUtOnMklWH8 SKCSXXZrTxcA1saSCRyOpNWEKHgfTRj21iXtb1mPEAuVOiP0cN73Ryt1h34+dmXaz7gk U1egt/UyWX1Xx4weckV3v1FzbixYjJgoulFIG/egwOahpPgfX0L1QDIOzY4TQ0DOZSfF UfDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=G5Osnu5h; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a1709029a4700b0019abb540355si2319773plv.15.2023.03.03.06.35.53; Fri, 03 Mar 2023 06:36:05 -0800 (PST) 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=G5Osnu5h; 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 S231128AbjCCO2v (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Fri, 3 Mar 2023 09:28:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbjCCO2t (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 3 Mar 2023 09:28:49 -0500 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C3B13D7C for <linux-kernel@vger.kernel.org>; Fri, 3 Mar 2023 06:28:49 -0800 (PST) Received: by mail-il1-x12c.google.com with SMTP id z5so1726757ilq.0 for <linux-kernel@vger.kernel.org>; Fri, 03 Mar 2023 06:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677853728; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=PRcr1qg5pQOktZ9kX0ziwdm9E4pyF51eI2ym5oRUyFE=; b=G5Osnu5hzYoVxhN4oaDmF5ViD0nXFxer6ZmbnkHX+XteHQB6w9jeCBHfe/lpiNZQkF TnXhJ4mCWNuKZoh1vLG+CLsLsS4dUZB+PTvJ44unjclgLGyq+MvLzUP3CQxG/U4mCF7p HjfW/RlyqqIpILTffO10FhS8wZCw9XF+H0CF09VXjfs7qqVp/AdfBdqFqzQLqaO+0KcY hCgjK4WySE5WFwwcxUYEVjwosYEi866GUTErjZuLnAH3haBJiNHO9BeYZXnhtnSWN5pO 0bysOuL5OEvrXWBVTvinonfeYXGrf7OPLfqNCTAzMdpNLJwkOs/XTvfPv1Y/X5OoS1ml uDDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677853728; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PRcr1qg5pQOktZ9kX0ziwdm9E4pyF51eI2ym5oRUyFE=; b=TqEQh3jz5mU7apBTnfvqPUWi78C+kOsc9r1WqqwnpYKn6CimMsMzIKx0dt+7QJaMW3 kDuN3eJrM/1cRWoT32ZSkl3rgf8xUv/MJ9LyXNULnvZV9JVnGp8b87Y1F27jCC5uuWRK dkxCJ2uQmxAgdkrsLfL/XmXn34LT8da12E7EOY7TjIxcFm6+5nDiaiXQg8wjQbEFfBxz Qt3eQse2BAUEsyMyJW8YKtLIPGZqxt/ag4gmKTnWEGeciKkEPVOMrIxPxovNG2e8ww2x 3pMxa5zAqVe5U9x3e9UYxi1EXhpXIrVmceL/07ntNV46+1FukBqFnGaU3txSk9J94jO+ Oiow== X-Gm-Message-State: AO0yUKV9HqsOElv2zkWKGeEy3HnDqHyKhPAgM6ovd9djkXC2GjcVtm7G faX82q2FtF8WtIBbklY0RdKz/u5TqYOElW7ZBHomG2u6sZ6w1WSgGIKZ+w== X-Received: by 2002:a05:6e02:130f:b0:315:9761:6965 with SMTP id g15-20020a056e02130f00b0031597616965mr931127ilr.5.1677853728379; Fri, 03 Mar 2023 06:28:48 -0800 (PST) MIME-Version: 1.0 From: Alexander Potapenko <glider@google.com> Date: Fri, 3 Mar 2023 15:28:12 +0100 Message-ID: <CAG_fn=WZnBtRujLyhouz1AmerSKB71oPej442JDOw2OaORbWQg@mail.gmail.com> Subject: Infinite loop in checkpatch.pl To: apw@canonical.com, Joe Perches <joe@perches.com>, dwaipayanray1@gmail.com, Lukas Bulwahn <lukas.bulwahn@gmail.com> Cc: LKML <linux-kernel@vger.kernel.org> Content-Type: multipart/mixed; boundary="00000000000077b6b205f5ffc351" 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, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759357609819621088?= X-GMAIL-MSGID: =?utf-8?q?1759357609819621088?= |
Series |
Infinite loop in checkpatch.pl
|
|
Commit Message
Alexander Potapenko
March 3, 2023, 2:28 p.m. UTC
Hi folks, I've noticed that checkpatch.pl chokes on the following file (also attached): ================================== $ cat test-checkpatch.txt , but I have no idea how to test it properly. Could you please take a look? Thanks, Alex
Comments
On Fri, 2023-03-03 at 15:28 +0100, Alexander Potapenko wrote: > Hi folks, > > I've noticed that checkpatch.pl chokes on the following file (also attached): > > ================================== > $ cat test-checkpatch.txt > diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c > @@ -504,6 +504,25 @@ static void > test_memcpy_aligned_to_unaligned2(struct kunit *test) > + EXPECTATION_NO_REPORT(expect); \ > + volatile uint##size##_t uninit; \ checkpatch isn't a syntax complete c parser. Don't expect to be.
On Fri, Mar 3, 2023 at 5:53 PM Joe Perches <joe@perches.com> wrote: > > On Fri, 2023-03-03 at 15:28 +0100, Alexander Potapenko wrote: > > Hi folks, > > > > I've noticed that checkpatch.pl chokes on the following file (also attached): > > > > ================================== > > $ cat test-checkpatch.txt > > diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c > > @@ -504,6 +504,25 @@ static void > > test_memcpy_aligned_to_unaligned2(struct kunit *test) > > + EXPECTATION_NO_REPORT(expect); \ > > + volatile uint##size##_t uninit; \ > > checkpatch isn't a syntax complete c parser. Don't expect to be. That's understandable, and I sure don't. But as a user I expect it to not loop infinitely, and I think that's also reasonable. The example I gave is not a randomly generated code snippet, but an excerpt from a valid patch that I sent earlier today: https://lore.kernel.org/lkml/20230303141433.3422671-4-glider@google.com/, which checkpatch cannot process.
On Fri, 2023-03-03 at 21:53 +0100, Alexander Potapenko wrote: > On Fri, Mar 3, 2023 at 5:53 PM Joe Perches <joe@perches.com> wrote: > > > > On Fri, 2023-03-03 at 15:28 +0100, Alexander Potapenko wrote: > > > Hi folks, > > > > > > I've noticed that checkpatch.pl chokes on the following file (also attached): > > > > > > ================================== > > > $ cat test-checkpatch.txt > > > diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c > > > @@ -504,6 +504,25 @@ static void > > > test_memcpy_aligned_to_unaligned2(struct kunit *test) > > > + EXPECTATION_NO_REPORT(expect); \ > > > + volatile uint##size##_t uninit; \ > > > > checkpatch isn't a syntax complete c parser. Don't expect to be. > > That's understandable, and I sure don't. But as a user I expect it to > not loop infinitely, and I think that's also reasonable. > The example I gave is not a randomly generated code snippet, but an > excerpt from a valid patch that I sent earlier today: > https://lore.kernel.org/lkml/20230303141433.3422671-4-glider@google.com/, > which checkpatch cannot process. I think this may be appropriate instead. Andy W? --- scripts/checkpatch.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index bd44d12965c98..3328fb9f6d048 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -999,7 +999,9 @@ if (defined($typedefsfile)) { } sub build_types { - my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; + my $mods = "(?x: \n" . join("|\n ", @modifierList); + $mods .= "|(?^: \n" . join("|\n ", @modifierListFile) . "\n)" if ($#modifierListFile >= 0); + $mods .= ')'; my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)"; my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c @@ -504,6 +504,25 @@ static void test_memcpy_aligned_to_unaligned2(struct kunit *test) + EXPECTATION_NO_REPORT(expect); \ + volatile uint##size##_t uninit; \ ================================== , getting into an infinite loop in annotate_values(). The following patch helps it to proceed: diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 78cc595b98ce1..01d998b416a51 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2240,8 +2240,13 @@ sub annotate_values { print "C($1)\n" if ($dbg_values > 1); } if (defined $1) { - $cur = substr($cur, length($1)); - $res .= $type x length($1); + if (length($1)) { + $cur = substr($cur, length($1)); + $res .= $type x length($1); + } else { + $res .= $cur; + $cur = ""; + } } }