From: Jan Kara <jack@suse.cz>
To: Julian Sun <sunjunchao2870@gmail.com>
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kbuild@vger.kernel.org,
jack@suse.cz, brauner@kernel.org, viro@zeniv.linux.org.uk,
masahiroy@kernel.org, akpm@linux-foundation.org, n.schier@avm.de,
ojeda@kernel.org, djwong@kernel.org, kvalo@kernel.org
Subject: Re: [PATCH] scripts: reduce false positives in the macro_checker script.
Date: Thu, 25 Jul 2024 10:51:56 +0200 [thread overview]
Message-ID: <20240725085156.dezpnf44cilt46su@quack3> (raw)
In-Reply-To: <20240725075830.63585-1-sunjunchao2870@gmail.com>
On Thu 25-07-24 03:58:30, Julian Sun wrote:
> Reduce false positives in the macro_checker
> in the following scenarios:
> 1. Conditional compilation
> 2. Macro definitions with only a single character
> 3. Macro definitions as (0) and (1)
>
> Before this patch:
> sjc@sjc:linux$ ./scripts/macro_checker.py fs | wc -l
> 99
>
> After this patch:
> sjc@sjc:linux$ ./scripts/macro_checker.py fs | wc -l
> 11
>
> Most of the current warnings are valid now.
>
> Signed-off-by: Julian Sun <sunjunchao2870@gmail.com>
...
> def file_check_macro(file_path, report):
> + # number of conditional compiling
> + cond_compile = 0
> # only check .c and .h file
> if not file_path.endswith(".c") and not file_path.endswith(".h"):
> return
> @@ -57,7 +72,14 @@ def file_check_macro(file_path, report):
> while True:
> line = f.readline()
> if not line:
> - return
> + break
> + line = line.strip()
> + if line.startswith(cond_compile_mark):
> + cond_compile += 1
> + continue
> + if line.startswith(cond_compile_end):
> + cond_compile -= 1
> + continue
>
> macro = re.match(macro_pattern, line)
> if macro:
> @@ -67,6 +89,11 @@ def file_check_macro(file_path, report):
> macro = macro.strip()
> macro += f.readline()
> macro = macro_strip(macro)
> + if file_path.endswith(".c") and cond_compile != 0:
> + continue
> + # 1 is for #ifdef xxx at the beginning of the header file
> + if file_path.endswith(".h") and cond_compile != 1:
> + continue
> check_macro(macro, report)
>
> def get_correct_macros(path):
So I don't think this is right. As far as I understand this skips any macros
that are conditionally defined? Why? There is a lot of them and checking
them is beneficial... The patterns you have added should be dealing with
most of the conditional defines anyway.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-07-25 8:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 7:58 [PATCH] scripts: reduce false positives in the macro_checker script Julian Sun
2024-07-25 8:51 ` Jan Kara [this message]
2024-07-25 9:15 ` Julian Sun
2024-07-25 9:48 ` Jan Kara
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=20240725085156.dezpnf44cilt46su@quack3 \
--to=jack@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=kvalo@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=n.schier@avm.de \
--cc=ojeda@kernel.org \
--cc=sunjunchao2870@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/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