HID: u2fzero: clarify error check and length calculations
stable inclusion from stable-5.10.80 commit e2f0bff411f5245ecd01061e5c17eff461ff6625 bugzilla: 185821 https://gitee.com/openeuler/kernel/issues/I4L7CG Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e2f0bff411f5245ecd01061e5c17eff461ff6625 -------------------------------- [ Upstream commit b7abf78b ] 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: 22d65765 ("HID: u2fzero: ignore incomplete packets without data") Fixes: 42337b9d ("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> Signed-off-by:
Sasha Levin <sashal@kernel.org> Signed-off-by:
Chen Jun <chenjun102@huawei.com> Reviewed-by:
Weilong Chen <chenweilong@huawei.com> Acked-by:
Weilong Chen <chenweilong@huawei.com> Signed-off-by:
Chen Jun <chenjun102@huawei.com> Signed-off-by:
Zheng Zengkai <zhengzengkai@huawei.com>
Loading
Please sign in to comment