mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org, lukas.bulwahn@gmail.com
Subject: Re: [PATCH v5] checkpatch: extend attributes check to handle more patterns
Date: Sun, 25 Oct 2020 10:59:09 -0700	[thread overview]
Message-ID: <52f88d0bb938c5063ede693a05bf64961af5a496.camel@perches.com> (raw)
In-Reply-To: <20201025101537.59133-1-dwaipayanray1@gmail.com>

On Sun, 2020-10-25 at 15:45 +0530, Dwaipayan Ray wrote:
> It is generally preferred that the macros from
> include/linux/compiler_attributes.h are used, unless there
> is a reason not to.
> 
> checkpatch currently checks __attribute__ for each of
> packed, aligned, section, printf, scanf, and weak. Other
> declarations in compiler_attributes.h are not handled.
> 
> Add a generic test to check the presence of such attributes.
> Some attributes require more specific handling and are kept
> separate.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -6155,50 +6155,95 @@ sub process {
>  			}
>  		}
>  
> 
> -# Check for __attribute__ packed, prefer __packed
> +# Check for compiler attributes
>  		if ($realfile !~ m@\binclude/uapi/@ &&
> -		    $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
> -			WARN("PREFER_PACKED",
> -			     "__packed is preferred over __attribute__((packed))\n" . $herecurr);
> -		}
> +		    $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) {

Using $rawline would also change comments and that seems wrong.
Any reason to use $rawline instead of $line?

[]

> +			if (scalar @conv_array > 0 && $conv_possible == 1) {
> +				my $replace = join(' ', @conv_array);
> +				if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO",
> +				         "$replace is preferred over __attribute__(($attr))\n" . $herecurr) &&
> +					$fix) {
> +					$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*\Q$attr\E\s*\)\s*\)/$replace/;

I looks it would be useful to add
					$fixed[$fixlinenr] =~ s/\}\Q$replace\E/} $replace/;
so there's a space added between } and any replacements.



  reply	other threads:[~2020-10-25 17:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-25 10:15 Dwaipayan Ray
2020-10-25 17:59 ` Joe Perches [this message]
2020-10-25 18:10   ` Dwaipayan Ray
2020-10-25 18:19     ` Joe Perches
2020-10-25 18:26       ` Dwaipayan Ray
2020-10-25 18:48   ` Dwaipayan Ray

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=52f88d0bb938c5063ede693a05bf64961af5a496.camel@perches.com \
    --to=joe@perches.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /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

all inboxes | Powered by JetHome®