Skip to contentSkip to conversation

hid: Fix uninitialized variable "size" in hid-wiimote-debug

PATCH Superseded Simon Que 2 participants 3 messages Jan 17, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Simon Que

author
#0 lore raw

PATCH 1/1 hid: Fix uninitialized variable "size" in hid-wiimote-debug

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.

---
 drivers/hid/hid-wiimote-debug.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/hid/hid-wiimote-debug.c +1 -1
index eec3291..90124ff 100644
@@ -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;
Signature · 1 line
1.7.8.6
#1 lore raw

Hi Simon

Quoted 3 lines · 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.

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.

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

#2 lore raw

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

Quoted 32 lines · David Herrmann

Hi Simon

Quoted 3 lines · 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.

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.

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