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 v5] checkpatch: extend attributes check to handle more patterns Date: Sun, 25 Oct 2020 23:40:54 +0530 [thread overview] Message-ID: <CABJPP5Cec7jKfaygRaxm-z5gzhg-7cBX1GP46NRQDM6rfhg3Ww@mail.gmail.com> (raw) In-Reply-To: <52f88d0bb938c5063ede693a05bf64961af5a496.camel@perches.com> On Sun, Oct 25, 2020 at 11:29 PM Joe Perches <joe@perches.com> wrote: > > 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? > Hi, Yes I used $line initially but changed it because quoted strings were being replaced. Like: __attribute__((__section__("_ftrace_events"))) $line in this case was: __attribute__((__section__("XXXXXXXXXXXXXX"))) While $rawline was: __attribute__((__section__("_ftrace_events"))) So to avoid this problem I changed to $rawline. Is there any other alternative available perhaps? Or should I change back to $rawline? > [] > > > + 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. > Yes I will do that sure. Thanks, Dwaipayan.
WARNING: multiple messages have this Message-ID (diff)
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> Subject: Re: [Linux-kernel-mentees] [PATCH v5] checkpatch: extend attributes check to handle more patterns Date: Sun, 25 Oct 2020 23:40:54 +0530 [thread overview] Message-ID: <CABJPP5Cec7jKfaygRaxm-z5gzhg-7cBX1GP46NRQDM6rfhg3Ww@mail.gmail.com> (raw) In-Reply-To: <52f88d0bb938c5063ede693a05bf64961af5a496.camel@perches.com> On Sun, Oct 25, 2020 at 11:29 PM Joe Perches <joe@perches.com> wrote: > > 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? > Hi, Yes I used $line initially but changed it because quoted strings were being replaced. Like: __attribute__((__section__("_ftrace_events"))) $line in this case was: __attribute__((__section__("XXXXXXXXXXXXXX"))) While $rawline was: __attribute__((__section__("_ftrace_events"))) So to avoid this problem I changed to $rawline. Is there any other alternative available perhaps? Or should I change back to $rawline? > [] > > > + 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. > Yes I will do that sure. Thanks, Dwaipayan. _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next prev parent reply other threads:[~2020-10-25 18:11 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-25 10:15 [PATCH v5] checkpatch: extend attributes check to handle more patterns Dwaipayan Ray 2020-10-25 10:15 ` [Linux-kernel-mentees] " Dwaipayan Ray 2020-10-25 17:59 ` Joe Perches 2020-10-25 17:59 ` [Linux-kernel-mentees] " Joe Perches 2020-10-25 18:10 ` Dwaipayan Ray [this message] 2020-10-25 18:10 ` Dwaipayan Ray 2020-10-25 18:19 ` Joe Perches 2020-10-25 18:19 ` [Linux-kernel-mentees] " Joe Perches 2020-10-25 18:26 ` Dwaipayan Ray 2020-10-25 18:26 ` [Linux-kernel-mentees] " Dwaipayan Ray 2020-10-25 18:48 ` Dwaipayan Ray 2020-10-25 18:48 ` [Linux-kernel-mentees] " 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=CABJPP5Cec7jKfaygRaxm-z5gzhg-7cBX1GP46NRQDM6rfhg3Ww@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.