board: st: common: fix dfu alt buffer clearing
authorVincent Stehlé <vincent.stehle@arm.com>
Mon, 7 Apr 2025 17:05:26 +0000 (19:05 +0200)
committerPatrice Chotard <patrice.chotard@foss.st.com>
Mon, 5 May 2025 13:51:47 +0000 (15:51 +0200)
The set_dfu_alt_info() function calls the ALLOC_CACHE_ALIGN_BUFFER()
macro to declare a `buf' variable pointer into an array allocated on the
stack. It then calls the memset() function to clear the useable portion
of the array using the idiomatic expression `sizeof(buf)'.

While this would indeed work fine for an array, in the present case we
end up clearing only the size of a pointer.
Fix this by specifying the explicit size `DFU_ALT_BUF_LEN' instead.

Fixes: ec2933e543df ("board: stm32mp1: move set_dfu_alt_info in st common directory")
Signed-off-by: Vincent Stehlé <vincent.stehle@arm.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Marek Vasut <marex@denx.de>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
board/st/common/stm32mp_dfu.c

index 1db8e45..8c1f80b 100644 (file)
@@ -105,7 +105,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
        if (env_get("dfu_alt_info"))
                return;
 
-       memset(buf, 0, sizeof(buf));
+       memset(buf, 0, DFU_ALT_BUF_LEN);
 
        snprintf(buf, DFU_ALT_BUF_LEN,
                 "ram 0=%s", CONFIG_DFU_ALT_RAM0);