linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dwaipayan Ray <dwaipayanray1@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>
Subject: Re: [PATCH RFC v2] checkpatch: extend attributes check to handle more patterns
Date: Fri, 23 Oct 2020 17:10:14 +0530	[thread overview]
Message-ID: <CABJPP5Dx4qj-_0gOx0bmaWvJj3okB-tNGJg5-8Y3KF2LnCjowQ@mail.gmail.com> (raw)
In-Reply-To: <d2b05b45adbcf3f1d16692b054862a7aa7353f6d.camel@perches.com>

On Fri, Oct 23, 2020 at 4:34 PM Joe Perches <joe@perches.com> wrote:
>
> On Fri, 2020-10-23 at 15:13 +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
>
> checkpatch, no need for capitalization
>
> and non-trivially:
>
> > +                     my $attr_list = qr {
> > +                             __alias__|
> > +                             __aligned__$|
> > +                             __aligned__\(.*\)|
> > +                             __always_inline__|
> > +                             __assume_aligned__\(.*\)|
> > +                             __cold__|
> > +                             __const__|
> > +                             __copy__\(.*\)|
> > +                             __designated_init__|
> > +                             __externally_visible__|
> > +                             __fallthrough__|
> > +                             __gnu_inline__|
> > +                             __malloc__|
> > +                             __mode__\(.*\)|
> > +                             __no_caller_saved_registers__|
> > +                             __noclone__|
> > +                             __noinline__|
> > +                             __nonstring__|
> > +                             __noreturn__|
> > +                             __packed__|
> > +                             __pure__|
> > +                             __used__
> > +                     }x;
> []
> > +                     my %attr_replace = (
> > +                             "__alias__"                     => "__alias",
> > +                             "__aligned__"           => "__aligned_largest",
> > +                             "__aligned__("          => "__aligned",
> > +                             "__always_inline__"     => "__always_inline",
> > +                             "__assume_aligned__("   => "__assume_aligned",
> > +                             "__cold__"                      => "__cold",
> > +                             "__const__"                     => "__const",
> > +                             "__copy__("                     => "__copy",
> > +                             "__designated_init__"           => "__designated_init",
> > +                             "__externally_visible__"        => "__visible",
> > +                             "__fallthrough__"               => "fallthrough",
> > +                             "__gnu_inline__"                => "__gnu_inline",
> > +                             "__malloc__"            => "__malloc",
> > +                             "__mode__("                     => "__mode",
> > +                             "__no_caller_saved_registers__" => "__no_caller_saved_registers",
> > +                             "__noclone__"           => "__noclone",
> > +                             "__noinline__"          => "noinline",
> > +                             "__nonstring__"         => "__nonstring",
> > +                             "__noreturn__"          => "__noreturn",
> > +                             "__packed__"            => "__packed",
> > +                             "__pure__"                      => "__pure",
> > +                             "__used__"                      => "__used"
> > +                     );
> > +
> > +                     if ($attr =~/^($attr_list)/) {
>
> I would remove the __ from the entries here.
>
> And you could check using
>
>         $line =~ /__attribute__\s*\(\s*($balanced_parens)\s*)/
>
> and check for all attributes in $1 after
> stripping the leading and trailing parens
> and any leading and trailing underscores
> from each attribute.
>
> And you only need one hash and you should
> check for existence of the key rather than
> have multiple lists.
>
>         if (exists($attributes($attr))) {
>

Okay thanks!
But what should be done for the attributes which are
parameterized, like __aligned__(x). Should all the __
for these entries be trimmed too? There are also
cases where there are multiple versions like:

__aligned__
__aligned__(x)

To help differentiate between them what can be done?
Should i make the keys as:

aligned
aligned__(

instead of

__aligned__
__aligned__(

Thanks,
Dwaipayan.

  reply	other threads:[~2020-10-23 11:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-23  9:43 [PATCH RFC v2] checkpatch: extend attributes check to handle more patterns Dwaipayan Ray
2020-10-23 11:04 ` Joe Perches
2020-10-23 11:40   ` Dwaipayan Ray [this message]
2020-10-23 12:08     ` Joe Perches
2020-10-23 19:14       ` Dwaipayan Ray
2020-10-23 20:42         ` Joe Perches
2020-10-23 20:57           ` Dwaipayan Ray
2020-10-23 21:04             ` Joe Perches
2020-10-23 21:09               ` 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=CABJPP5Dx4qj-_0gOx0bmaWvJj3okB-tNGJg5-8Y3KF2LnCjowQ@mail.gmail.com \
    --to=dwaipayanray1@gmail.com \
    --cc=joe@perches.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;
as well as URLs for NNTP newsgroup(s).