diff mbox series

env: sf: report malloc error to caller

Message ID 20240119213216.3811402-1-ralph.siemsen@linaro.org
State Accepted
Commit 04add62e8cf1209ca21ddfa13346d9ddcc6126fb
Headers show
Series env: sf: report malloc error to caller | expand

Commit Message

Ralph Siemsen Jan. 19, 2024, 9:32 p.m. UTC
In the non-redundant code for env_sf_save(), a failure to malloc() the
temporary buffer produces the following output:

    Saving Environment to SPIFlash... OK

This is misleading as the flash has neither been erased nor written.

Fix it to return an error to the caller, so the output will be:

    Saving Environment to SPIFlash... Failed (-12)

Note that there is another copy of env_sf_save() in the same file, for
handling redundant environment, and it already has the same logic.

Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>
---
 env/sf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tom Rini Jan. 30, 2024, 1:54 a.m. UTC | #1
On Fri, 19 Jan 2024 16:32:17 -0500, Ralph Siemsen wrote:

> In the non-redundant code for env_sf_save(), a failure to malloc() the
> temporary buffer produces the following output:
> 
>     Saving Environment to SPIFlash... OK
> 
> This is misleading as the flash has neither been erased nor written.
> 
> [...]

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/env/sf.c b/env/sf.c
index a425ecc11c8..8f5c03b00d3 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -210,8 +210,10 @@  static int env_sf_save(void)
 		saved_size = sect_size - CONFIG_ENV_SIZE;
 		saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;
 		saved_buffer = malloc(saved_size);
-		if (!saved_buffer)
+		if (!saved_buffer) {
+			ret = -ENOMEM;
 			goto done;
+		}
 
 		ret = spi_flash_read(env_flash, saved_offset,
 			saved_size, saved_buffer);