HID: i2c-hid: fix ret_count check
authorJiri Kosina <jkosina@suse.cz>
Thu, 6 Dec 2012 09:59:28 +0000 (10:59 +0100)
committerJiri Kosina <jkosina@suse.cz>
Thu, 6 Dec 2012 09:59:28 +0000 (10:59 +0100)
ret_count has to be at least 3, as we have to count the 2 bytes that are used
for the size of the reply. Without this, memcpy() might be called with zero or
negative count.

Reported-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/i2c-hid/i2c-hid.c

index ce01d5916184e6e6a894fd68342f119e2a2dbdd1..6e1774c3a3f9e5da197de66472ec0e956171952f 100644 (file)
@@ -520,7 +520,7 @@ static int i2c_hid_get_raw_report(struct hid_device *hid,
 
        ret_count = ihid->inbuf[0] | (ihid->inbuf[1] << 8);
 
-       if (!ret_count)
+       if (ret_count <= 2)
                return 0;
 
        ret_count = min(ret_count, ask_count);