]> git.baikalelectronics.ru Git - kernel.git/commit
HID: u2fzero: clarify error check and length calculations
authorAndrej Shadura <andrew.shadura@collabora.co.uk>
Tue, 19 Oct 2021 15:29:16 +0000 (17:29 +0200)
committerJiri Kosina <jkosina@suse.cz>
Wed, 27 Oct 2021 08:17:08 +0000 (10:17 +0200)
commit320176b90c10fba8daa60e9142cf9a75ef550a93
tree4f754a22ece0c12c3ceb9c22e502deabbd51a72c
parent4c05b458c67450094048c015fba642a74ca17b9e
HID: u2fzero: clarify error check and length calculations

The previous commit fixed handling of incomplete packets but broke error
handling: offsetof returns an unsigned value (size_t), but when compared
against the signed return value, the return value is interpreted as if
it were unsigned, so negative return values are never less than the
offset.

To make the code easier to read, calculate the minimal packet length
once and separately, and assign it to a signed int variable to eliminate
unsigned math and the need for type casts. It then becomes immediately
obvious how the actual data length is calculated and why the return
value cannot be less than the minimal length.

Fixes: b0724aa10e1f ("HID: u2fzero: ignore incomplete packets without data")
Fixes: 9a55fd8b3349 ("HID: add driver for U2F Zero built-in LED and RNG")
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-u2fzero.c