From: Colin Ian King Date: Thu, 11 Mar 2021 09:53:16 +0000 (+0000) Subject: nvmem: core: Fix unintentional sign extension issue X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c079b5cd947222a919e7c56ae70ad344c56a5751;p=users%2Fjedix%2Flinux-maple.git 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 Reviewed-by: Douglas Anderson Signed-off-by: Srinivas Kandagatla --- diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 635e3131eb5f7..bca671ff4e546 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -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);