* Re: [PATCH v3 2/2] scripts: checkpatch: check unused parameters for function-like macro
@ 2024-03-29 23:08 Charlemagne Lasse
2024-03-30 2:49 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Charlemagne Lasse @ 2024-03-29 23:08 UTC (permalink / raw)
To: Barry Song, Jonathan Corbet, workflows, linux-doc,
Andy Whitcroft, Joe Perches, Dwaipayan Ray, lukas.bulwahn
Cc: LKML, Xining Xu, Andrew Morton
Hi,
Can this patch please be dropped from Linux-next (currently via
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm#mm-everything)?
It is obviously wrong when dealing with named variadic macro
parameters:
./scripts/checkpatch.pl -f include/linux/rculist.h
ERROR: Parameter 'dummy' is not used in function-like macro, please
use static inline instead
#51: FILE: include/linux/rculist.h:51:
+#define __list_check_rcu(dummy, cond, extra...)
\
+ ({ \
+ check_arg_count_one(extra); \
+ RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \
+ "RCU-list traversed in non-reader section!"); \
+ })
ERROR: Parameter 'extra...' is not used in function-like macro, please
use static inline instead
#51: FILE: include/linux/rculist.h:51:
+#define __list_check_rcu(dummy, cond, extra...)
\
+ ({ \
+ check_arg_count_one(extra); \
+ RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(), \
+ "RCU-list traversed in non-reader section!"); \
+ })
ERROR: Parameter 'dummy' is not used in function-like macro, please
use static inline instead
#64: FILE: include/linux/rculist.h:64:
+#define __list_check_rcu(dummy, cond, extra...)
\
+ ({ check_arg_count_one(extra); })
ERROR: Parameter 'cond' is not used in function-like macro, please use
static inline instead
#64: FILE: include/linux/rculist.h:64:
+#define __list_check_rcu(dummy, cond, extra...)
\
+ ({ check_arg_count_one(extra); })
ERROR: Parameter 'extra...' is not used in function-like macro, please
use static inline instead
#64: FILE: include/linux/rculist.h:64:
+#define __list_check_rcu(dummy, cond, extra...)
\
+ ({ check_arg_count_one(extra); })
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 2/2] scripts: checkpatch: check unused parameters for function-like macro
2024-03-29 23:08 [PATCH v3 2/2] scripts: checkpatch: check unused parameters for function-like macro Charlemagne Lasse
@ 2024-03-30 2:49 ` Joe Perches
0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2024-03-30 2:49 UTC (permalink / raw)
To: Charlemagne Lasse, Barry Song, Jonathan Corbet, workflows,
linux-doc, Andy Whitcroft, Dwaipayan Ray, lukas.bulwahn
Cc: LKML, Xining Xu, Andrew Morton
On Sat, 2024-03-30 at 00:08 +0100, Charlemagne Lasse wrote:
> Hi,
>
> Can this patch please be dropped from Linux-next (currently via
> git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm#mm-everything)?
> It is obviously wrong when dealing with named variadic macro
> parameters:
I agree it was a bit early to add to -mm but
there is a fix for (most of) that coming up.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] scripts: checkpatch: Check unused parameters for function-like macro
2024-03-22 8:49 [PATCH v3 0/2] codingstyle: avoid unused parameters for a " Barry Song
@ 2024-03-22 8:49 ` Barry Song
0 siblings, 0 replies; 3+ messages in thread
From: Barry Song @ 2024-03-22 8:49 UTC (permalink / raw)
To: corbet, workflows, linux-doc, apw, joe, dwaipayanray1, lukas.bulwahn
Cc: linux-kernel, Xining Xu, Andrew Morton, Chris Zankel,
Huacai Chen, Herbert Xu, Guenter Roeck, Stephen Rothwell,
Mark Brown, Barry Song
From: Xining Xu <ma.xxn@outlook.com>
If function-like macros do not utilize a parameter, it might result in a
build warning. In our coding style guidelines, we advocate for utilizing
static inline functions to replace such macros. This patch verifies
compliance with the new rule.
For a macro such as the one below,
#define test(a) do { } while (0)
The test result is as follows.
ERROR: Parameter 'a' is not used in function-like macro, please use static
inline instead
#21: FILE: mm/init-mm.c:20:
+#define test(a) do { } while (0)
total: 1 errors, 0 warnings, 8 lines checked
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Chris Zankel <chris@zankel.net>
Cc: Huacai Chen <chenhuacai@loongson.cn>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Xining Xu <ma.xxn@outlook.com>
Tested-by: Barry Song <v-songbaohua@oppo.com>
---
scripts/checkpatch.pl | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9c4c4a61bc83..6f778f3403b5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6109,6 +6109,30 @@ sub process {
WARN("TRAILING_SEMICOLON",
"macros should not use a trailing semicolon\n" . "$herectx");
}
+
+ if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*(\((?:[^\(\)]++|(?-1))*\))\s+(\S+.*)(\/\/.*)?/) {
+ my $params = $1 || "";
+ my $body = $2 || "";
+
+ # get the individual params
+ $params =~ tr/()//d;
+ # remove leading and trailing whitespace
+ $params =~ s/^\s+|\s+$//g;
+
+ $ctx =~ s/\n*$//;
+ my $cnt = statement_rawlines($ctx);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ if ($params ne "") {
+ my @paramList = split /,\s*/, $params;
+ foreach my $param(@paramList) {
+ if ($body !~ /\b$param\b/) {
+ ERROR("UNUSED_PARAM_IN_MACRO",
+ "Parameter '$param' is not used in function-like macro, please use static inline instead\n" . "$herectx");
+ }
+ }
+ }
+ }
}
# check for redundant bracing round if etc
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-30 2:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 23:08 [PATCH v3 2/2] scripts: checkpatch: check unused parameters for function-like macro Charlemagne Lasse
2024-03-30 2:49 ` Joe Perches
-- strict thread matches above, loose matches on Subject: below --
2024-03-22 8:49 [PATCH v3 0/2] codingstyle: avoid unused parameters for a " Barry Song
2024-03-22 8:49 ` [PATCH v3 2/2] scripts: checkpatch: Check unused parameters for " Barry Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox