mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.duyck@gmail.com>
To: apw@canonical.com, joe@perches.com, dwaipayanray1@gmail.com,
	lukas.bulwahn@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: Fix MACRO_ARG_REUSE false positives for offsetof and sizeof_field
Date: Thu, 12 Aug 2021 19:00:02 -0700	[thread overview]
Message-ID: <162881998124.70219.4038998149078838864.stgit@localhost.localdomain> (raw)

From: Alexander Duyck <alexanderduyck@fb.com>

The MACRO_ARG_REUSE check was generating false positives when run against
macros that made use of offsetof and sizeof_field. This was due to the fact
that the type variable was not being checked for and as a result they were
not being stripped from the final use count for the macro argument.

Reproduction steps below:
  # ./scripts/checkpatch.pl --strict --no-tree -types MACRO_ARG_REUSE \
	-f drivers/net/ethernet/intel/igb/igb_ethtool.c
CHECK: Macro argument reuse '_stat' - possible side-effects?
  #27: FILE: drivers/net/ethernet/intel/igb/igb_ethtool.c:27:
  +#define IGB_STAT(_name, _stat) { \
  + .stat_string = _name, \
  + .sizeof_stat = sizeof_field(struct igb_adapter, _stat), \
  + .stat_offset = offsetof(struct igb_adapter, _stat) \
  +}

  CHECK: Macro argument reuse '_net_stat' - possible side-effects?
  #77: FILE: drivers/net/ethernet/intel/igb/igb_ethtool.c:77:
  +#define IGB_NETDEV_STAT(_net_stat) { \
  + .stat_string = __stringify(_net_stat), \
  + .sizeof_stat = sizeof_field(struct rtnl_link_stats64, _net_stat), \
  + .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \
  +}

  total: 0 errors, 0 warnings, 2 checks, 3498 lines checked

Address that by adding the type to the offset and sizeof_field checks so
that they will properly strip both the macro and the two arguments. With
this change the result is 0 checks as the two argument macros correctly
strip the type and argument.

Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
---
 scripts/checkpatch.pl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 461d4221e4a4..cda33bb71ad6 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5833,7 +5833,7 @@ sub process {
 			        next if ($arg =~ /\.\.\./);
 			        next if ($arg =~ /^type$/i);
 				my $tmp_stmt = $define_stmt;
-				$tmp_stmt =~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__stringify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
+				$tmp_stmt =~ s/\b(__must_be_array|offsetof\s*\(\s*$Type\s*,|\#+|sizeof|sizeof_field\s*\(\s*$Type\s*,|\#+|__stringify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
 				$tmp_stmt =~ s/\#+\s*$arg\b//g;
 				$tmp_stmt =~ s/\b$arg\s*\#\#//g;
 				my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;



                 reply	other threads:[~2021-08-13  2:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=162881998124.70219.4038998149078838864.stgit@localhost.localdomain \
    --to=alexander.duyck@gmail.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=joe@perches.com \
    --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®