linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 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
Subject: Re: [Linux-kernel-mentees] [PATCH v4] checkpatch: extend attributes check to handle more patterns
Date: Sun, 25 Oct 2020 01:22:14 -0700	[thread overview]
Message-ID: <e96f8306d57e9a2ce7118b545db197e819e97b19.camel@perches.com> (raw)
In-Reply-To: <20201025065134.21737-1-dwaipayanray1@gmail.com>

On Sun, 2020-10-25 at 12:21 +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, 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.
[]
> Also add fixes for the generic attributes check.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> +				if (exists($attr_list{$curr_attr})) {
> +					my $new = $attr_list{$curr_attr};
> +					if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO",
> +					         "$new$params is preferred over __attribute__(($attr))\n" . $herecurr) &&
> +						$fix) {
> +						$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*\Q$attr\E\s*\)\s*\)/$new$params/;

Thanks.

This fix would only work for the single conversions
and would not work for multiple attributes like:

	__attribute__((aligned(4), packed))

It would be nice to be able to convert this to

	__aligned(4) __packed

One mechanism to do that might be to:

	create an empty array
	for each attr
		push(@array, conversion)
	s/__attribute__(...)/join(' ', @array)/

if all attrs were converted.


_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-25  6:51 [Linux-kernel-mentees] [PATCH v4] checkpatch: extend attributes check to handle more patterns Dwaipayan Ray
2020-10-25  8:22 ` Joe Perches [this message]
2020-10-25  8:32   ` Dwaipayan Ray
2020-10-25  8:38     ` Joe Perches
2020-10-25  8:42       ` Dwaipayan Ray
2020-10-25  8:48         ` Joe Perches

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