2
0

819-v6.8-0013-nvmem-u-boot-env-improve-coding-style.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From 6bafe07c930676d6430be471310958070816a595 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Thu, 21 Dec 2023 18:34:20 +0100
  4. Subject: [PATCH] nvmem: u-boot-env: improve coding style
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. 1. Prefer kzalloc() over kcalloc()
  9. See memory-allocation.rst which says: "to be on the safe side it's
  10. best to use routines that set memory to zero, like kzalloc()"
  11. 2. Drop dev_err() for u_boot_env_add_cells() fail
  12. It can fail only on -ENOMEM. We don't want to print error then.
  13. 3. Add extra "crc32_addr" variable
  14. It makes code reading header's crc32 easier to understand / review.
  15. Signed-off-by: Rafał Miłecki <[email protected]>
  16. Reviewed-by: Miquel Raynal <[email protected]>
  17. Link: https://lore.kernel.org/r/[email protected]
  18. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  19. ---
  20. drivers/nvmem/u-boot-env.c | 8 ++++----
  21. 1 file changed, 4 insertions(+), 4 deletions(-)
  22. --- a/drivers/nvmem/u-boot-env.c
  23. +++ b/drivers/nvmem/u-boot-env.c
  24. @@ -132,6 +132,7 @@ static int u_boot_env_parse(struct u_boo
  25. size_t crc32_data_offset;
  26. size_t crc32_data_len;
  27. size_t crc32_offset;
  28. + __le32 *crc32_addr;
  29. size_t data_offset;
  30. size_t data_len;
  31. size_t dev_size;
  32. @@ -143,7 +144,7 @@ static int u_boot_env_parse(struct u_boo
  33. dev_size = nvmem_dev_size(nvmem);
  34. - buf = kcalloc(1, dev_size, GFP_KERNEL);
  35. + buf = kzalloc(dev_size, GFP_KERNEL);
  36. if (!buf) {
  37. err = -ENOMEM;
  38. goto err_out;
  39. @@ -175,7 +176,8 @@ static int u_boot_env_parse(struct u_boo
  40. data_offset = offsetof(struct u_boot_env_image_broadcom, data);
  41. break;
  42. }
  43. - crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
  44. + crc32_addr = (__le32 *)(buf + crc32_offset);
  45. + crc32 = le32_to_cpu(*crc32_addr);
  46. crc32_data_len = dev_size - crc32_data_offset;
  47. data_len = dev_size - data_offset;
  48. @@ -188,8 +190,6 @@ static int u_boot_env_parse(struct u_boo
  49. buf[dev_size - 1] = '\0';
  50. err = u_boot_env_add_cells(priv, buf, data_offset, data_len);
  51. - if (err)
  52. - dev_err(dev, "Failed to add cells: %d\n", err);
  53. err_kfree:
  54. kfree(buf);