803-v5.13-0005-nvmem-core-Fix-unintentional-sign-extension-issue.patch 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. From 55022fdeace8e432f008787ce03703bdcc9c3ca9 Mon Sep 17 00:00:00 2001
  2. From: Colin Ian King <[email protected]>
  3. Date: Tue, 30 Mar 2021 12:12:38 +0100
  4. Subject: [PATCH] nvmem: core: Fix unintentional sign extension issue
  5. The shifting of the u8 integer buf[3] by 24 bits to the left will
  6. be promoted to a 32 bit signed int and then sign-extended to a
  7. u64. In the event that the top bit of buf[3] is set then all
  8. then all the upper 32 bits of the u64 end up as also being set
  9. because of the sign-extension. Fix this by casting buf[i] to
  10. a u64 before the shift.
  11. Fixes: a28e824fb827 ("nvmem: core: Add functions to make number reading easy")
  12. Reviewed-by: Douglas Anderson <[email protected]>
  13. Signed-off-by: Colin Ian King <[email protected]>
  14. Signed-off-by: Srinivas Kandagatla <[email protected]>
  15. Addresses-Coverity: ("Unintended sign extension")
  16. Link: https://lore.kernel.org/r/[email protected]
  17. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  18. ---
  19. drivers/nvmem/core.c | 2 +-
  20. 1 file changed, 1 insertion(+), 1 deletion(-)
  21. --- a/drivers/nvmem/core.c
  22. +++ b/drivers/nvmem/core.c
  23. @@ -1700,7 +1700,7 @@ int nvmem_cell_read_variable_le_u64(stru
  24. /* Copy w/ implicit endian conversion */
  25. *val = 0;
  26. for (i = 0; i < len; i++)
  27. - *val |= buf[i] << (8 * i);
  28. + *val |= (uint64_t)buf[i] << (8 * i);
  29. kfree(buf);