Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3486737ybt; Tue, 23 Jun 2020 03:36:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd03RNH2jjFaBzDs7hHvsgj/WTO7AgN3euQkxLDTnUq9mIt0QjVtbzBX9sDYPMgDoUM/i5 X-Received: by 2002:a17:907:40f5:: with SMTP id no5mr2300096ejb.149.1592908597321; Tue, 23 Jun 2020 03:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592908597; cv=none; d=google.com; s=arc-20160816; b=WlL84f9L9JF1mkgvyWEdubfXEMzMLVg4pHQ8vquzQ4bKcc1VWp3VJoBQ20fLuYwwDA TYEyBI+8ns1/UkRQ4dNnzy41JLAPsDtzji06mCmdvKGT5baeQjA+rX5oQi2/zFV3U3SV bPScszO8ROCSuqWzslPumDzrHE5t7IdpVh9XXkJ/bSrtVB/C0SBj5S9oVhjfTCMlYpP9 +KlOymv6kKRj3k9gC3CKIWvheHY7BVjeCVI3I8Cey2tDnhJdueLZGOXLcDV7N1zg0THw w3GXSx76msq7ZamhgBNX5c0F7YJj06StQmyLPYimFWViB8TQC/heiMnOx8NCVmAiU1ll 0n0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=h62r6XS0jqYfIJmWVT9efAIcIqFr2bxw7xGquL+kTA0=; b=h0uARTWx89BjkLasDkQaBGqJ8DXaSJhO0KbF7HDQfV3ICrTcoOnaITuYWgFkSzrpRB hgRs5x+0s6TCo5rRyL83P+wl5FXBaDqNanmDIiKUW/x/ZuMOyS37Ls1d2lcPQE44uqZU oGsuZO0GGlUZq8jIrGamJIIfeNkzgI7rT1uTpPX8ybegToR7LYitudKjG6hsHwxVlSo+ gRJN8tyN5Ktli7n6Q6QcTVRbjg1qxCwxCONzReRJSD9koXZS7ZO7RuSfPHttyVVVkSUj KS9vXzSWBLmx45ZzObI1IoMB+GANzRmRatMXSoKGZMNPjf/EtN1gRauyNpJzhtcPJ4g1 woyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent-com.20150623.gappssmtp.com header.s=20150623 header.b=PaAVGcq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u27si10236688eje.558.2020.06.23.03.36.13; Tue, 23 Jun 2020 03:36:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@isovalent-com.20150623.gappssmtp.com header.s=20150623 header.b=PaAVGcq5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732247AbgFWKeE (ORCPT + 99 others); Tue, 23 Jun 2020 06:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732076AbgFWKeE (ORCPT ); Tue, 23 Jun 2020 06:34:04 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBC45C061573 for ; Tue, 23 Jun 2020 03:34:02 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id g21so2682416wmg.0 for ; Tue, 23 Jun 2020 03:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=h62r6XS0jqYfIJmWVT9efAIcIqFr2bxw7xGquL+kTA0=; b=PaAVGcq51bK0il7pnXFZVs9ta1DoWfsKr4m305qKiGMZEfpaknGGzwmWgA1i5KXEZ4 eUiOJ2qgAbaJotMouyqdb4KcXiQxHRCpyQPtaq1OHw8df+S/lEG1uaahFRHg/4Fzfsre bBwR6d9BFmLMpv4MUVm7XaD2pSRsG2oQZDhFnhErSL6adK0P696KRKXkXUmEx9Si+jkn VFjPH33a1UN+dEGxh/+A4/1SqKPsnm7z20xfSdaVnqWEJGaL7QqHHyoCWXcsEawxSkbO OUe8vJ/kSCWfVUWmMMmlu7LfO3BY5hbPU5rQO1sKbXEU3URx1PulhVM6k1etrYYO3xfL SqRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h62r6XS0jqYfIJmWVT9efAIcIqFr2bxw7xGquL+kTA0=; b=DjND2dpap+vVBw6jDiJPQqqEhDtjbd5kkQJKHm0Z9qEnpJGMsirWEA6e/n0BN17obp dFKprJfcBGKscMkgyrREI03bqDRe7jdqY5rUJDrBKm6OGnsDivyY/MMu652QOwuG/QdZ 0WH620rQSMOBOc6FACxMr1846s7fv5qhj7p5NanuHTgnRUh5ViIfltm7UGhtqTUWuRNK oCSykxMk07y/uh6/J97LVtnoIHFsN2X3RGgUu5A6yh3RuUGycK8/Kfgw0WRPwYATqAOA z7uKC4DEBG60cRDS3w1hgRpAN3c43UAxROUy4R39alqmUXFCYim8PGp6nP83JWoGoCQt 1xEQ== X-Gm-Message-State: AOAM5332T4CwjmpR4FqDq4KPDKFY4kfg5o1wA5UsDz177DvYgNubwCwZ Md6WagCE1yvULn77jJmkYA/izPeGRDz16A== X-Received: by 2002:a1c:8192:: with SMTP id c140mr9620670wmd.108.1592908438033; Tue, 23 Jun 2020 03:33:58 -0700 (PDT) Received: from [192.168.1.12] ([194.53.184.63]) by smtp.gmail.com with ESMTPSA id n8sm18676940wrj.44.2020.06.23.03.33.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jun 2020 03:33:57 -0700 (PDT) Subject: Re: [PATCH] checkpatch: fix CONST_STRUCT when const_structs.checkpatch is missing To: Joe Perches , Andy Whitcroft , Andrew Morton Cc: linux-kernel@vger.kernel.org References: <20200622204844.21030-1-quentin@isovalent.com> <8a218fa14cc2e1690df32d278c82587c7507a820.camel@perches.com> From: Quentin Monnet Message-ID: Date: Tue, 23 Jun 2020 11:33:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <8a218fa14cc2e1690df32d278c82587c7507a820.camel@perches.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2020-06-22 14:24 UTC-0700 ~ Joe Perches > On Mon, 2020-06-22 at 21:48 +0100, Quentin Monnet wrote: >> Checkpatch reports warnings when some specific structs are not declared >> as const in the code. The list of structs to consider was initially >> defined in the checkpatch.pl script itself, but it was later moved to an >> external file (scripts/const_structs.checkpatch). This introduced two >> minor issues: >> >> - When file scripts/const_structs.checkpatch is not present (for >> example, if checkpatch is run outside of the kernel directory with the >> "--no-tree" option), a warning is printed to stderr to tell the user >> that "No structs that should be const will be found". This is fair, >> but the warning is printed unconditionally, even if the option >> "--ignore CONST_STRUCT" is passed. In the latter case, we explicitly >> ask checkpatch to skip this check, so no warning should be printed. >> >> - When scripts/const_structs.checkpatch is missing, or even when trying >> to silence the warning by adding an empty file, $const_structs is set >> to "", and the regex used for finding structs that should be const, >> "$line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/)", matches all >> structs found in the code, thus reporting a number of false positives. >> >> Let's fix the first item by skipping scripts/const_structs.checkpatch >> processing if "CONST_STRUCT" checks are ignored, and the second one by >> skipping the test if $const_structs is an empty string. >> >> Fixes: bf1fa1dae68e ("checkpatch: externalize the structs that should be const") > > Probably not worthy of a Fixes: line, as that's > generally used for backporting, but OK by me. Yeah I hesitated, I'll drop it for v2. > >> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > [] >> @@ -781,8 +781,10 @@ sub read_words { >> } >> >> my $const_structs = ""; > > This might be a tiny bit faster/less cpu using: > > my $const_structs; > >> -read_words(\$const_structs, $conststructsfile) >> - or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; >> +if (show_type("CONST_STRUCT")) { >> + read_words(\$const_structs, $conststructsfile) >> + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; >> +} >> >> my $typeOtherTypedefs = ""; >> if (length($typedefsfile)) { >> @@ -6660,7 +6662,8 @@ sub process { >> >> # check for various structs that are normally const (ops, kgdb, device_tree) >> # and avoid what seem like struct definitions 'struct foo {' >> - if ($line !~ /\bconst\b/ && >> + if ($const_structs ne "" && > > instead testing > > if (defined($const_structs) && Sure, I will respin. Thank you for the review! Quentin