The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>,
	"Andy Whitcroft" <apw@canonical.com>
Cc: Pablo Pellecchia <pablo9891@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts/checkpatch.pl - don't check for const structs if list is empty
Date: Tue, 03 Sep 2019 09:05:48 -0700	[thread overview]
Message-ID: <0435c104093ca60cee5f0489e54af54b693fed10.camel@perches.com> (raw)
In-Reply-To: <542749.1567507103@turing-police>

On Tue, 2019-09-03 at 06:38 -0400, Valdis Klētnieks wrote:
> If the list of structures we expect to be const is empty (due to file permissions,
> or the file being empty, etc), we get odd complaints about structures:
> 
> [/usr/src/linux-next] scripts/checkpatch.pl -f drivers/staging/netlogic/platform_net.h
> No structs that should be const will be found - file '/usr/src/linux-next/scripts/const_structs.checkpatch': Permission denied
> WARNING: struct  should normally be const
> #9: FILE: drivers/staging/netlogic/platform_net.h:9:
> +struct xlr_net_data {
> 
> WARNING: struct  should normally be const
> #20: FILE: drivers/staging/netlogic/platform_net.h:20:
> +	struct xlr_fmn_info *gmac_fmn_info;
> 
> total: 0 errors, 2 warnings, 0 checks, 21 lines checked
> 
> Fix it so that it actually *obeys* what it said about not finding structures.
> 
> Reported-by: Pablo Pellecchia <pablo9891@gmail.com>
> Signed-off-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>
> ---
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index f4b6127ff469..103c67665f61 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6497,7 +6497,7 @@ 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 ($line !~ /\bconst\b/ && $const_structs ne "" &&

Seems sensible, thanks.

I think this would read better with this test order reversed.

Maybe this should verify that const does not exist before the
specific struct found: (and is not also a forward declaration)
---
 scripts/checkpatch.pl | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f4b6127ff469..77d585950ab0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6496,11 +6496,12 @@ 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/ &&
-		    $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
+# avoid struct definitions 'struct foo {' and forward declarations 'struct foo;'
+		if ($const_structs ne "" &&
+		    $line =~ /((\bstruct\s+($const_structs))\b(?!\s*[\{;]))/ &&
+		    $line !~ /\bconst\s+\Q$1\E/) {
 			WARN("CONST_STRUCT",
-			     "struct $1 should normally be const\n" . $herecurr);
+			     "struct $2 should normally be const\n" . $herecurr);
 		}
 
 # use of NR_CPUS is usually wrong



      reply	other threads:[~2019-09-03 16:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 10:38 [PATCH] scripts/checkpatch.pl - don't check for const structs if list is empty Valdis Klētnieks
2019-09-03 16:05 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0435c104093ca60cee5f0489e54af54b693fed10.camel@perches.com \
    --to=joe@perches.com \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pablo9891@gmail.com \
    --cc=valdis.kletnieks@vt.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox