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 v3] checkpatch: extend attributes check to handle more patterns Date: Sat, 24 Oct 2020 16:21:36 -0700 [thread overview] Message-ID: <1d9d4793a6f89dda2e06ae73065ed7a28b50e02f.camel@perches.com> (raw) In-Reply-To: <20201024090557.45092-1-dwaipayanray1@gmail.com> On Sat, 2020-10-24 at 14:35 +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. [] > - } > + $line =~ /__attribute__\s*\(\s*($balanced_parens)\s*\)/) { > + my $attr = $1; > + $attr =~ s/\s*\(\s*(.*)\)\s*/$1/; > + > + my %attr_list = ( > + "alias" => "__alias", > + "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", I'd remove fallthrough. It doesn't make sense as the attribute could be in any line of a switch/case block and fallthrough; must be the last line of the block. > + if ($attr =~ /^(\w+)\s*(${balanced_parens})?/) { > + my $curr_attr = $1; > + my $params = ''; > + $params = $2 if defined($2); > + $curr_attr =~ s/^[\s_]+|[\s_]+$//g; > + > + if (exists($attr_list{$curr_attr})) { > + my $new = $attr_list{$curr_attr}; > + WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "$new$params is preffered over __attribute__(($attr))\n" . $herecurr); Be nice to have a $fix option here > + # Check for __attribute__ format(printf, prefer __printf > + if ($attr =~ /^_*format_*\s*\(\s*printf/) { > + if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; like for format(printf, index, pos) and format(scanf, index, pos)
WARNING: multiple messages have this Message-ID (diff)
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 v3] checkpatch: extend attributes check to handle more patterns Date: Sat, 24 Oct 2020 16:21:36 -0700 [thread overview] Message-ID: <1d9d4793a6f89dda2e06ae73065ed7a28b50e02f.camel@perches.com> (raw) In-Reply-To: <20201024090557.45092-1-dwaipayanray1@gmail.com> On Sat, 2020-10-24 at 14:35 +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. [] > - } > + $line =~ /__attribute__\s*\(\s*($balanced_parens)\s*\)/) { > + my $attr = $1; > + $attr =~ s/\s*\(\s*(.*)\)\s*/$1/; > + > + my %attr_list = ( > + "alias" => "__alias", > + "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", I'd remove fallthrough. It doesn't make sense as the attribute could be in any line of a switch/case block and fallthrough; must be the last line of the block. > + if ($attr =~ /^(\w+)\s*(${balanced_parens})?/) { > + my $curr_attr = $1; > + my $params = ''; > + $params = $2 if defined($2); > + $curr_attr =~ s/^[\s_]+|[\s_]+$//g; > + > + if (exists($attr_list{$curr_attr})) { > + my $new = $attr_list{$curr_attr}; > + WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "$new$params is preffered over __attribute__(($attr))\n" . $herecurr); Be nice to have a $fix option here > + # Check for __attribute__ format(printf, prefer __printf > + if ($attr =~ /^_*format_*\s*\(\s*printf/) { > + if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", > + "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; like for format(printf, index, pos) and format(scanf, index, pos) _______________________________________________ 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-24 23:21 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-24 9:05 [PATCH v3] checkpatch: extend attributes check to handle more patterns Dwaipayan Ray 2020-10-24 9:05 ` [Linux-kernel-mentees] " Dwaipayan Ray 2020-10-24 20:20 ` Dwaipayan Ray 2020-10-24 20:20 ` [Linux-kernel-mentees] " Dwaipayan Ray 2020-10-24 23:21 ` Joe Perches [this message] 2020-10-24 23:21 ` Joe Perches 2020-10-24 23:29 ` Randy Dunlap 2020-10-24 23:29 ` [Linux-kernel-mentees] " Randy Dunlap
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=1d9d4793a6f89dda2e06ae73065ed7a28b50e02f.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: 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.