[PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro

Mohammed Guermoud posted 1 patch 1 month, 2 weeks ago
drivers/staging/nvec/nvec_ps2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
Posted by Mohammed Guermoud 1 month, 2 weeks ago
The NVEC_PHD macro was defined with three arguments (str, buf, len)
that were not used in its empty body, causing a compiler warning.

This patch silences the warning by explicitly casting the unused
arguments to (void), making the intent clear without changing
functionality.

Signed-off-by: Mohammed Guermoud <mohammed.guermoud@gmail.com>
---
 drivers/staging/nvec/nvec_ps2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
index 575233fa1677..7accdcafeeac 100644
--- a/drivers/staging/nvec/nvec_ps2.c
+++ b/drivers/staging/nvec/nvec_ps2.c
@@ -28,7 +28,7 @@
 	print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
 			16, 1, buf, len, false)
 #else
-#define NVEC_PHD(str, buf, len) do { } while (0)
+#define NVEC_PHD(str, buf, len) do { (void)str; (void)buf; (void)len; } while (0)
 #endif
 
 enum ps2_subcmds {
-- 
2.50.1
Re: [PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
Posted by Geert Uytterhoeven 1 month, 2 weeks ago
Hi Mohammed,

On Mon, 18 Aug 2025 at 17:10, Mohammed Guermoud
<mohammed.guermoud@gmail.com> wrote:
> The NVEC_PHD macro was defined with three arguments (str, buf, len)
> that were not used in its empty body, causing a compiler warning.
>
> This patch silences the warning by explicitly casting the unused
> arguments to (void), making the intent clear without changing
> functionality.
>
> Signed-off-by: Mohammed Guermoud <mohammed.guermoud@gmail.com>

Thanks for your patch!

> --- a/drivers/staging/nvec/nvec_ps2.c
> +++ b/drivers/staging/nvec/nvec_ps2.c
> @@ -28,7 +28,7 @@
>         print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
>                         16, 1, buf, len, false)
>  #else
> -#define NVEC_PHD(str, buf, len) do { } while (0)
> +#define NVEC_PHD(str, buf, len) do { (void)str; (void)buf; (void)len; } while (0)
>  #endif
>
>  enum ps2_subcmds {

The proper solution would be to remove the custom NVEC_PHD() macro (and
NVEC_PS2_DEBUG), and just call print_hex_dump_debug() directly instead.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
Posted by Mohammed Guermoud 1 month, 2 weeks ago
Hi Greg, Dan, and Geert,

Thank you all for the detailed feedback. This has been a great
learning experience.

My initial patch was incorrect and broke the build, as the test robot found.

Following Greg's advice, I will send a v2 patch that removes the
unused NVEC_PHD macro and all the places it is used.

Thanks,
Mohammed


Mohammed GUERMOUD
Software Architect
Stellantis (Formerly Groupe PSA Peugeot Citroën) - Morocco


On Mon, Aug 18, 2025 at 4:42 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Mohammed,
>
> On Mon, 18 Aug 2025 at 17:10, Mohammed Guermoud
> <mohammed.guermoud@gmail.com> wrote:
> > The NVEC_PHD macro was defined with three arguments (str, buf, len)
> > that were not used in its empty body, causing a compiler warning.
> >
> > This patch silences the warning by explicitly casting the unused
> > arguments to (void), making the intent clear without changing
> > functionality.
> >
> > Signed-off-by: Mohammed Guermoud <mohammed.guermoud@gmail.com>
>
> Thanks for your patch!
>
> > --- a/drivers/staging/nvec/nvec_ps2.c
> > +++ b/drivers/staging/nvec/nvec_ps2.c
> > @@ -28,7 +28,7 @@
> >         print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
> >                         16, 1, buf, len, false)
> >  #else
> > -#define NVEC_PHD(str, buf, len) do { } while (0)
> > +#define NVEC_PHD(str, buf, len) do { (void)str; (void)buf; (void)len; } while (0)
> >  #endif
> >
> >  enum ps2_subcmds {
>
> The proper solution would be to remove the custom NVEC_PHD() macro (and
> NVEC_PS2_DEBUG), and just call print_hex_dump_debug() directly instead.
>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
Re: [PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
Posted by kernel test robot 1 month, 2 weeks ago
Hi Mohammed,

kernel test robot noticed the following build errors:

[auto build test ERROR on staging/staging-testing]

url:    https://github.com/intel-lab-lkp/linux/commits/Mohammed-Guermoud/staging-nvec-Silence-unused-argument-warning-in-NVEC_PHD-macro/20250818-032647
base:   staging/staging-testing
patch link:    https://lore.kernel.org/r/20250817192425.12983-1-mohammed.guermoud%40gmail.com
patch subject: [PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
config: arm-defconfig (https://download.01.org/0day-ci/archive/20250818/202508182005.4PiKxXcN-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 93d24b6b7b148c47a2fa228a4ef31524fa1d9f3f)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250818/202508182005.4PiKxXcN-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508182005.4PiKxXcN-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/staging/nvec/nvec_ps2.c:80:51: error: invalid operands to binary expression ('void' and 'int')
      80 |                         NVEC_PHD("ps/2 mouse reply: ", &msg[4], msg[1] - 2);
         |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
   drivers/staging/nvec/nvec_ps2.c:31:66: note: expanded from macro 'NVEC_PHD'
      31 | #define NVEC_PHD(str, buf, len) do { (void)str; (void)buf; (void)len; } while (0)
         |                                                            ~~~~~~^~~
   drivers/staging/nvec/nvec_ps2.c:84:52: error: invalid operands to binary expression ('void' and 'int')
      84 |                         NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
         |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
   drivers/staging/nvec/nvec_ps2.c:31:66: note: expanded from macro 'NVEC_PHD'
      31 | #define NVEC_PHD(str, buf, len) do { (void)str; (void)buf; (void)len; } while (0)
         |                                                            ~~~~~~^~~
   2 errors generated.


vim +80 drivers/staging/nvec/nvec_ps2.c

32890b98308613 Marc Dietrich       2011-05-19  62  
32890b98308613 Marc Dietrich       2011-05-19  63  static int nvec_ps2_notifier(struct notifier_block *nb,
32890b98308613 Marc Dietrich       2011-05-19  64  			     unsigned long event_type, void *data)
32890b98308613 Marc Dietrich       2011-05-19  65  {
32890b98308613 Marc Dietrich       2011-05-19  66  	int i;
0df8f51eed5067 Ben Marsh           2016-03-10  67  	unsigned char *msg = data;
32890b98308613 Marc Dietrich       2011-05-19  68  
32890b98308613 Marc Dietrich       2011-05-19  69  	switch (event_type) {
32890b98308613 Marc Dietrich       2011-05-19  70  	case NVEC_PS2_EVT:
1e46e6273bc62d Julian Andres Klode 2011-09-27  71  		for (i = 0; i < msg[1]; i++)
1e46e6273bc62d Julian Andres Klode 2011-09-27  72  			serio_interrupt(ps2_dev.ser_dev, msg[2 + i], 0);
0eedab704ed93d Marc Dietrich       2011-12-26  73  		NVEC_PHD("ps/2 mouse event: ", &msg[2], msg[1]);
32890b98308613 Marc Dietrich       2011-05-19  74  		return NOTIFY_STOP;
32890b98308613 Marc Dietrich       2011-05-19  75  
32890b98308613 Marc Dietrich       2011-05-19  76  	case NVEC_PS2:
0eedab704ed93d Marc Dietrich       2011-12-26  77  		if (msg[2] == 1) {
32890b98308613 Marc Dietrich       2011-05-19  78  			for (i = 0; i < (msg[1] - 2); i++)
32890b98308613 Marc Dietrich       2011-05-19  79  				serio_interrupt(ps2_dev.ser_dev, msg[i + 4], 0);
0eedab704ed93d Marc Dietrich       2011-12-26 @80  			NVEC_PHD("ps/2 mouse reply: ", &msg[4], msg[1] - 2);
32890b98308613 Marc Dietrich       2011-05-19  81  		}
32890b98308613 Marc Dietrich       2011-05-19  82  
0eedab704ed93d Marc Dietrich       2011-12-26  83  		else if (msg[1] != 2) /* !ack */
0eedab704ed93d Marc Dietrich       2011-12-26  84  			NVEC_PHD("unhandled mouse event: ", msg, msg[1] + 2);
32890b98308613 Marc Dietrich       2011-05-19  85  		return NOTIFY_STOP;
32890b98308613 Marc Dietrich       2011-05-19  86  	}
32890b98308613 Marc Dietrich       2011-05-19  87  
32890b98308613 Marc Dietrich       2011-05-19  88  	return NOTIFY_DONE;
32890b98308613 Marc Dietrich       2011-05-19  89  }
32890b98308613 Marc Dietrich       2011-05-19  90  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
Posted by Greg KH 1 month, 2 weeks ago
On Sun, Aug 17, 2025 at 08:24:25PM +0100, Mohammed Guermoud wrote:
> The NVEC_PHD macro was defined with three arguments (str, buf, len)
> that were not used in its empty body, causing a compiler warning.
> 
> This patch silences the warning by explicitly casting the unused
> arguments to (void), making the intent clear without changing
> functionality.
> 
> Signed-off-by: Mohammed Guermoud <mohammed.guermoud@gmail.com>
> ---
>  drivers/staging/nvec/nvec_ps2.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
> index 575233fa1677..7accdcafeeac 100644
> --- a/drivers/staging/nvec/nvec_ps2.c
> +++ b/drivers/staging/nvec/nvec_ps2.c
> @@ -28,7 +28,7 @@
>  	print_hex_dump(KERN_DEBUG, str, DUMP_PREFIX_NONE, \
>  			16, 1, buf, len, false)
>  #else
> -#define NVEC_PHD(str, buf, len) do { } while (0)
> +#define NVEC_PHD(str, buf, len) do { (void)str; (void)buf; (void)len; } while (0)

As Dan said, what is the warning?

And this isn't the best/proper way to handle this type of issue.  Best
is to make an inline function that does nothing, as that way you
properly check the variable types.

But, I'll push back and say why is this even needed at all?  As
NVEC_PS2_DEBUG is never defined, why not just remove them?

thanks,

greg k-h
Re: [PATCH] staging: nvec: Silence unused argument warning in NVEC_PHD macro
Posted by Dan Carpenter 1 month, 2 weeks ago
On Sun, Aug 17, 2025 at 08:24:25PM +0100, Mohammed Guermoud wrote:
> The NVEC_PHD macro was defined with three arguments (str, buf, len)
> that were not used in its empty body, causing a compiler warning.
> 
> This patch silences the warning by explicitly casting the unused
> arguments to (void), making the intent clear without changing
> functionality.
> 
> Signed-off-by: Mohammed Guermoud <mohammed.guermoud@gmail.com>

What's the warning.  Does it break the build since we're using -Werror?

I feel like in the end, I'm going to say just ignore the compiler warning
since this is not a bug in the code but obviously if it breaks the build
then that's a different story.

regards,
dan carpenter