linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: Silence 'unused variable' warning in iforce joystick driver
@ 2007-08-30 22:13 Jesper Juhl
  2007-08-30 22:57 ` Satyam Sharma
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2007-08-30 22:13 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linux Kernel Mailing List, Vojtech Pavlik, Johann Deneux, dtor,
	linux-input, linux-joystick, Jesper Juhl

In the iforce driver we currently get this warning

 drivers/input/joystick/iforce/iforce-packets.c: In function 'iforce_get_id_packet':
 drivers/input/joystick/iforce/iforce-packets.c:249: warning: unused variable 'status'

if CONFIG_JOYSTICK_IFORCE_USB is not defined.

The warning is easy to avoid by simply moving the variable inside 
the only case in the switch that actually use it.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index 3154ccd..48d4a86 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -246,13 +246,12 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)
 
 int iforce_get_id_packet(struct iforce *iforce, char *packet)
 {
-	int status;
-
 	switch (iforce->bus) {
 
 	case IFORCE_USB:
-
 #ifdef CONFIG_JOYSTICK_IFORCE_USB
+		int status;
+
 		iforce->cr.bRequest = packet[0];
 		iforce->ctrl->dev = iforce->usbdev;
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] input: Silence 'unused variable' warning in iforce joystick driver
  2007-08-30 22:57 ` Satyam Sharma
@ 2007-08-30 22:50   ` Jesper Juhl
  2007-08-31 15:26     ` Dmitry Torokhov
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2007-08-30 22:50 UTC (permalink / raw)
  To: Satyam Sharma
  Cc: Dmitry Torokhov, Linux Kernel Mailing List, Vojtech Pavlik,
	Johann Deneux, dtor, linux-input, linux-joystick

On 31/08/2007, Satyam Sharma <satyam@infradead.org> wrote:
...
> 
> Hmm, would this not still give a warning when JOYSTICK_IFORCE_USB=y?

Arrgh, I messed that one up real good...  Thank you for your keen eye Satyam :-)


> [ I didn't know mixing code and declarations (not at top of statement
>   block) was accepted style in the kernel ... ]
> 
It's not the common case, but this is certainly not the only place in the kernel where we do it.


> IMHO either you should at least wrap that case inside a {} of its
> own (so that the int status; is at top of a statement block), or else,

Yeah, I should...

> preferably, just add "__maybe_unused" to the first declaration that you
> removed just now.
> 

Here's an updated patch that actually works as intended.



In the iforce driver we currently get this warning

  drivers/input/joystick/iforce/iforce-packets.c: In function 'iforce_get_id_packet':
  drivers/input/joystick/iforce/iforce-packets.c:249: warning: unused variable 'status'

if CONFIG_JOYSTICK_IFORCE_USB is not defined.

The warning is easy to avoid by simply moving the variable inside
the only case in the switch that actually use it.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index 3154ccd..2731057 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -246,13 +246,12 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)
 
 int iforce_get_id_packet(struct iforce *iforce, char *packet)
 {
-	int status;
-
 	switch (iforce->bus) {
 
-	case IFORCE_USB:
-
+	case IFORCE_USB: {
 #ifdef CONFIG_JOYSTICK_IFORCE_USB
+		int status;
+
 		iforce->cr.bRequest = packet[0];
 		iforce->ctrl->dev = iforce->usbdev;
 
@@ -270,6 +269,7 @@ int iforce_get_id_packet(struct iforce *iforce, char *packet)
 			usb_unlink_urb(iforce->ctrl);
 			return -1;
 		}
+	}
 #else
 		dbg("iforce_get_id_packet: iforce->bus = USB!");
 #endif

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] input: Silence 'unused variable' warning in iforce joystick driver
  2007-08-30 22:13 [PATCH] input: Silence 'unused variable' warning in iforce joystick driver Jesper Juhl
@ 2007-08-30 22:57 ` Satyam Sharma
  2007-08-30 22:50   ` Jesper Juhl
  0 siblings, 1 reply; 4+ messages in thread
From: Satyam Sharma @ 2007-08-30 22:57 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: Dmitry Torokhov, Linux Kernel Mailing List, Vojtech Pavlik,
	Johann Deneux, dtor, linux-input, linux-joystick

Hi,


On Fri, 31 Aug 2007, Jesper Juhl wrote:

> In the iforce driver we currently get this warning
> 
>  drivers/input/joystick/iforce/iforce-packets.c: In function 'iforce_get_id_packet':
>  drivers/input/joystick/iforce/iforce-packets.c:249: warning: unused variable 'status'
> 
> if CONFIG_JOYSTICK_IFORCE_USB is not defined.
> 
> The warning is easy to avoid by simply moving the variable inside 
> the only case in the switch that actually use it.
> 
> 
> Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
> ---
> 
> diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
> index 3154ccd..48d4a86 100644
> --- a/drivers/input/joystick/iforce/iforce-packets.c
> +++ b/drivers/input/joystick/iforce/iforce-packets.c
> @@ -246,13 +246,12 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)
>  
>  int iforce_get_id_packet(struct iforce *iforce, char *packet)
>  {
> -	int status;
> -
>  	switch (iforce->bus) {
>  
>  	case IFORCE_USB:
> -
>  #ifdef CONFIG_JOYSTICK_IFORCE_USB
> +		int status;
> +
>  		iforce->cr.bRequest = packet[0];
>  		iforce->ctrl->dev = iforce->usbdev;

Hmm, would this not still give a warning when JOYSTICK_IFORCE_USB=y?
[ I didn't know mixing code and declarations (not at top of statement
  block) was accepted style in the kernel ... ]

IMHO either you should at least wrap that case inside a {} of its
own (so that the int status; is at top of a statement block), or else,
preferably, just add "__maybe_unused" to the first declaration that you
removed just now.


Satyam

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] input: Silence 'unused variable' warning in iforce joystick driver
  2007-08-30 22:50   ` Jesper Juhl
@ 2007-08-31 15:26     ` Dmitry Torokhov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2007-08-31 15:26 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: Satyam Sharma, Linux Kernel Mailing List, Vojtech Pavlik,
	Johann Deneux, linux-input, linux-joystick

Hi Jesper,

On 8/30/07, Jesper Juhl <jesper.juhl@gmail.com> wrote:
> On 31/08/2007, Satyam Sharma <satyam@infradead.org> wrote:
> ...
> >
> > Hmm, would this not still give a warning when JOYSTICK_IFORCE_USB=y?
>
> Arrgh, I messed that one up real good...  Thank you for your keen eye Satyam :-)
>
>
> > [ I didn't know mixing code and declarations (not at top of statement
> >   block) was accepted style in the kernel ... ]
> >
> It's not the common case, but this is certainly not the only place in the kernel where we do it.
>
>
> > IMHO either you should at least wrap that case inside a {} of its
> > own (so that the int status; is at top of a statement block), or else,
>
> Yeah, I should...
>
> > preferably, just add "__maybe_unused" to the first declaration that you
> > removed just now.
> >
>
> Here's an updated patch that actually works as intended.
>

I had a similar patch from Andrew Morton in my queue and it just got
merged. There should be no warning anymore.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-31 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-30 22:13 [PATCH] input: Silence 'unused variable' warning in iforce joystick driver Jesper Juhl
2007-08-30 22:57 ` Satyam Sharma
2007-08-30 22:50   ` Jesper Juhl
2007-08-31 15:26     ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).