Skip to content

Commit 6bafe07

Browse files
Rafał Miłeckigregkh
authored andcommitted
nvmem: u-boot-env: improve coding style
1. Prefer kzalloc() over kcalloc() See memory-allocation.rst which says: "to be on the safe side it's best to use routines that set memory to zero, like kzalloc()" 2. Drop dev_err() for u_boot_env_add_cells() fail It can fail only on -ENOMEM. We don't want to print error then. 3. Add extra "crc32_addr" variable It makes code reading header's crc32 easier to understand / review. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/r/20231221173421.13737-5-zajec5@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a832556 commit 6bafe07

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/nvmem/u-boot-env.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ static int u_boot_env_parse(struct u_boot_env *priv)
132132
size_t crc32_data_offset;
133133
size_t crc32_data_len;
134134
size_t crc32_offset;
135+
__le32 *crc32_addr;
135136
size_t data_offset;
136137
size_t data_len;
137138
size_t dev_size;
@@ -143,7 +144,7 @@ static int u_boot_env_parse(struct u_boot_env *priv)
143144

144145
dev_size = nvmem_dev_size(nvmem);
145146

146-
buf = kcalloc(1, dev_size, GFP_KERNEL);
147+
buf = kzalloc(dev_size, GFP_KERNEL);
147148
if (!buf) {
148149
err = -ENOMEM;
149150
goto err_out;
@@ -175,7 +176,8 @@ static int u_boot_env_parse(struct u_boot_env *priv)
175176
data_offset = offsetof(struct u_boot_env_image_broadcom, data);
176177
break;
177178
}
178-
crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset));
179+
crc32_addr = (__le32 *)(buf + crc32_offset);
180+
crc32 = le32_to_cpu(*crc32_addr);
179181
crc32_data_len = dev_size - crc32_data_offset;
180182
data_len = dev_size - data_offset;
181183

@@ -188,8 +190,6 @@ static int u_boot_env_parse(struct u_boot_env *priv)
188190

189191
buf[dev_size - 1] = '\0';
190192
err = u_boot_env_add_cells(priv, buf, data_offset, data_len);
191-
if (err)
192-
dev_err(dev, "Failed to add cells: %d\n", err);
193193

194194
err_kfree:
195195
kfree(buf);

0 commit comments

Comments
 (0)