linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hid: Fix uninitialized variable "size" in hid-wiimote-debug
@ 2013-01-17 19:47 Simon Que
  2013-01-17 20:07 ` David Herrmann
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Que @ 2013-01-17 19:47 UTC (permalink / raw)
  To: dh.herrmann, linux-input; +Cc: msb, Simon Que

This variable is initialized conditionally, based on whether a wiimote
call succeeds.  However, the logic is not obvious to the compiler so it
throws a warning.  Eliminate the warning by initializing "size" to 0.

Signed-off-by: Simon Que <sque@chromium.org>
---
 drivers/hid/hid-wiimote-debug.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
index eec3291..90124ff 100644
--- a/drivers/hid/hid-wiimote-debug.c
+++ b/drivers/hid/hid-wiimote-debug.c
@@ -31,7 +31,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
 	unsigned long flags;
 	ssize_t ret;
 	char buf[16];
-	__u16 size;
+	__u16 size = 0;
 
 	if (s == 0)
 		return -EINVAL;
-- 
1.7.8.6


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

* Re: [PATCH] hid: Fix uninitialized variable "size" in hid-wiimote-debug
  2013-01-17 19:47 [PATCH] hid: Fix uninitialized variable "size" in hid-wiimote-debug Simon Que
@ 2013-01-17 20:07 ` David Herrmann
  2013-01-17 20:29   ` David Herrmann
  0 siblings, 1 reply; 3+ messages in thread
From: David Herrmann @ 2013-01-17 20:07 UTC (permalink / raw)
  To: Simon Que; +Cc: linux-input, msb

Hi Simon

On Thu, Jan 17, 2013 at 8:47 PM, Simon Que <sque@chromium.org> wrote:
> This variable is initialized conditionally, based on whether a wiimote
> call succeeds.  However, the logic is not obvious to the compiler so it
> throws a warning.  Eliminate the warning by initializing "size" to 0.

Hm, I think it says:

  54         ret = wiimote_cmd_wait(wdata);
  55         if (!ret)
  56                 size = wdata->state.cmd_read_size;

...not touching "size" or "ret" inbetween...

  64         if (ret)
  65                 return ret;

...using "size" below...

Weird that gcc cannot figure that out that there is no path to line 66
where "size" is uninitialized. Anyway, I am fine with this fix. We
test for "size == 0" anyway.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>

Next time please copy the gcc-warning message verbatim into the
commit-message so we can more easily reproduce this and see which line
is affected.

Thanks for the patch
David

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

* Re: [PATCH] hid: Fix uninitialized variable "size" in hid-wiimote-debug
  2013-01-17 20:07 ` David Herrmann
@ 2013-01-17 20:29   ` David Herrmann
  0 siblings, 0 replies; 3+ messages in thread
From: David Herrmann @ 2013-01-17 20:29 UTC (permalink / raw)
  To: Simon Que; +Cc: linux-input, msb, Jiri Kosina

CC'ing Jiri so he can apply it to hid-next.

On Thu, Jan 17, 2013 at 9:07 PM, David Herrmann
<dh.herrmann@googlemail.com> wrote:
> Hi Simon
>
> On Thu, Jan 17, 2013 at 8:47 PM, Simon Que <sque@chromium.org> wrote:
>> This variable is initialized conditionally, based on whether a wiimote
>> call succeeds.  However, the logic is not obvious to the compiler so it
>> throws a warning.  Eliminate the warning by initializing "size" to 0.
>
> Hm, I think it says:
>
>   54         ret = wiimote_cmd_wait(wdata);
>   55         if (!ret)
>   56                 size = wdata->state.cmd_read_size;
>
> ...not touching "size" or "ret" inbetween...
>
>   64         if (ret)
>   65                 return ret;
>
> ...using "size" below...
>
> Weird that gcc cannot figure that out that there is no path to line 66
> where "size" is uninitialized. Anyway, I am fine with this fix. We
> test for "size == 0" anyway.
>
> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
>
> Next time please copy the gcc-warning message verbatim into the
> commit-message so we can more easily reproduce this and see which line
> is affected.
>
> Thanks for the patch
> David

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

end of thread, other threads:[~2013-01-17 20:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-17 19:47 [PATCH] hid: Fix uninitialized variable "size" in hid-wiimote-debug Simon Que
2013-01-17 20:07 ` David Herrmann
2013-01-17 20:29   ` David Herrmann

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).