mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 819-v6.8-0013-nvmem-u-boot-env-improve-coding-style.patch
1 From 6bafe07c930676d6430be471310958070816a595 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
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
9 1. Prefer kzalloc() over kcalloc()
10 See memory-allocation.rst which says: "to be on the safe side it's
11 best to use routines that set memory to zero, like kzalloc()"
12 2. Drop dev_err() for u_boot_env_add_cells() fail
13 It can fail only on -ENOMEM. We don't want to print error then.
14 3. Add extra "crc32_addr" variable
15 It makes code reading header's crc32 easier to understand / review.
16
17 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
18 Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
19 Link: https://lore.kernel.org/r/20231221173421.13737-5-zajec5@gmail.com
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 ---
22 drivers/nvmem/u-boot-env.c | 8 ++++----
23 1 file changed, 4 insertions(+), 4 deletions(-)
24
25 --- a/drivers/nvmem/u-boot-env.c
26 +++ b/drivers/nvmem/u-boot-env.c
27 @@ -132,6 +132,7 @@ static int u_boot_env_parse(struct u_boo
28 size_t crc32_data_offset;
29 size_t crc32_data_len;
30 size_t crc32_offset;
31 + __le32 *crc32_addr;
32 size_t data_offset;
33 size_t data_len;
34 size_t dev_size;
35 @@ -143,7 +144,7 @@ static int u_boot_env_parse(struct u_boo
36
37 dev_size = nvmem_dev_size(nvmem);
38
39 - buf = kcalloc(1, dev_size, GFP_KERNEL);
40 + buf = kzalloc(dev_size, GFP_KERNEL);
41 if (!buf) {
42 err = -ENOMEM;
43 goto err_out;
44 @@ -175,7 +176,8 @@ static int u_boot_env_parse(struct u_boo
45 data_offset = offsetof(struct u_boot_env_image_broadcom, data);
46 break;
47 }
48 - crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
49 + crc32_addr = (__le32 *)(buf + crc32_offset);
50 + crc32 = le32_to_cpu(*crc32_addr);
51 crc32_data_len = dev_size - crc32_data_offset;
52 data_len = dev_size - data_offset;
53
54 @@ -188,8 +190,6 @@ static int u_boot_env_parse(struct u_boo
55
56 buf[dev_size - 1] = '\0';
57 err = u_boot_env_add_cells(priv, buf, data_offset, data_len);
58 - if (err)
59 - dev_err(dev, "Failed to add cells: %d\n", err);
60
61 err_kfree:
62 kfree(buf);