]> www.infradead.org Git - users/jedix/linux-maple.git/commit
nvmem: core: Fix unintentional sign extension issue
authorColin Ian King <colin.king@canonical.com>
Thu, 11 Mar 2021 09:53:16 +0000 (09:53 +0000)
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Thu, 11 Mar 2021 17:49:46 +0000 (17:49 +0000)
commitc079b5cd947222a919e7c56ae70ad344c56a5751
tree1851b43cf183dc7ed1a5ec8cb217fd2d633ba179
parent097eb1136ebb4b8fcf2bea3cf7e29d1c3e7a2542
nvmem: core: Fix unintentional sign extension issue

The shifting of the u8 integer buf[3] by 24 bits to the left will
be promoted to a 32 bit signed int and then sign-extended to a
u64. In the event that the top bit of buf[3] is set then all
then all the upper 32 bits of the u64 end up as also being set
because of the sign-extension. Fix this by casting buf[i] to
a u64 before the shift.

Addresses-Coverity: ("Unintended sign extension")
Fixes: 097eb1136ebb ("nvmem: core: Add functions to make number reading easy")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
drivers/nvmem/core.c