mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
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.
Fixes: a28e824fb8
("nvmem: core: Add functions to make number reading easy")
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Addresses-Coverity: ("Unintended sign extension")
Link: https://lore.kernel.org/r/20210330111241.19401-8-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
a28e824fb8
commit
55022fdeac
@ -1693,7 +1693,7 @@ int nvmem_cell_read_variable_le_u64(struct device *dev, const char *cell_id,
|
||||
/* Copy w/ implicit endian conversion */
|
||||
*val = 0;
|
||||
for (i = 0; i < len; i++)
|
||||
*val |= buf[i] << (8 * i);
|
||||
*val |= (uint64_t)buf[i] << (8 * i);
|
||||
|
||||
kfree(buf);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user