[PATCH v2 34/59] checkpatch: dont warn about unused macro arg on empty body

Jim Cromie posted 59 patches 9 months ago
There is a newer version of this series
[PATCH v2 34/59] checkpatch: dont warn about unused macro arg on empty body
Posted by Jim Cromie 9 months ago
we currently get:
  WARNING: Argument 'name' is not used in function-like macro
on:
  #define DRM_CLASSMAP_USE(name)  /* nothing here */

Following this advice is wrong here, and shouldn't be fixed by
ignoring args altogether; the macro should properly fail if invoked
with 0 or 2+ args.

cc: Andy Whitcroft <apw@canonical.com>
cc: Joe Perches <joe@perches.com>
cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b28ad331742..0c4f578ea6e7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6037,7 +6037,7 @@ sub process {
 				}
 
 # check if this is an unused argument
-				if ($define_stmt !~ /\b$arg\b/) {
+				if ($define_stmt !~ /\b$arg\b/ && $define_stmt) {
 					WARN("MACRO_ARG_UNUSED",
 					     "Argument '$arg' is not used in function-like macro\n" . "$herectx");
 				}
-- 
2.49.0
Re: [PATCH v2 34/59] checkpatch: dont warn about unused macro arg on empty body
Posted by Louis Chauvet 9 months ago

Le 20/03/2025 à 19:52, Jim Cromie a écrit :
> we currently get:
>    WARNING: Argument 'name' is not used in function-like macro
> on:
>    #define DRM_CLASSMAP_USE(name)  /* nothing here */
> 
> Following this advice is wrong here, and shouldn't be fixed by
> ignoring args altogether; the macro should properly fail if invoked
> with 0 or 2+ args.
> 
> cc: Andy Whitcroft <apw@canonical.com>
> cc: Joe Perches <joe@perches.com>
> cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
> cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>

Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>

> ---
>   scripts/checkpatch.pl | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7b28ad331742..0c4f578ea6e7 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6037,7 +6037,7 @@ sub process {
>   				}
>   
>   # check if this is an unused argument
> -				if ($define_stmt !~ /\b$arg\b/) {
> +				if ($define_stmt !~ /\b$arg\b/ && $define_stmt) {
>   					WARN("MACRO_ARG_UNUSED",
>   					     "Argument '$arg' is not used in function-like macro\n" . "$herectx");
>   				}

-- 
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


Re: [PATCH v2 34/59] checkpatch: dont warn about unused macro arg on empty body
Posted by Joe Perches 9 months ago
On Thu, 2025-03-20 at 12:52 -0600, Jim Cromie wrote:
> we currently get:
>   WARNING: Argument 'name' is not used in function-like macro
> on:
>   #define DRM_CLASSMAP_USE(name)  /* nothing here */
> 
> Following this advice is wrong here, and shouldn't be fixed by
> ignoring args altogether; the macro should properly fail if invoked
> with 0 or 2+ args.
> 
> cc: Andy Whitcroft <apw@canonical.com>
> cc: Joe Perches <joe@perches.com>
> cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
> cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>

Completely sensible, thanks Jim.

> ---
>  scripts/checkpatch.pl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7b28ad331742..0c4f578ea6e7 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6037,7 +6037,7 @@ sub process {
>  				}
>  
>  # check if this is an unused argument
> -				if ($define_stmt !~ /\b$arg\b/) {
> +				if ($define_stmt !~ /\b$arg\b/ && $define_stmt) {
>  					WARN("MACRO_ARG_UNUSED",
>  					     "Argument '$arg' is not used in function-like macro\n" . "$herectx");
>  				}