]> 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)
commit598452f0586bb3d5eb165e59a2f7714b63e345ed
tree4f754a22ece0c12c3ceb9c22e502deabbd51a72c
parent45662a7acaa44c9bf95faeb9e8cb38a0114ea56d
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: d397672a1d02 ("HID: u2fzero: ignore incomplete packets without data")
Fixes: 311f3595abaa ("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