Skip to contentSkip to conversation

fix dfu alt buffer clearing

PATCH Applied Vincent Stehlé 5 participants 18 messages Apr 7, 2025 – May 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fix dfu alt buffer clearing

Hi,

This patch series applies the same fix in five different locations (the detailed description of the fix is in the patches).

I did validate statically by looking at the assembly before/after for all five cases, using the following defconfigs:

stm32mp15_defconfig
synquacer_developerbox_defconfig
xilinx_versal_virt_defconfig
xilinx_zynq_virt_defconfig
xilinx_zynqmp_kria_defconfig

Best regards,
Vincent.

Vincent Stehlé (5):
fwu: developerbox: fix dfu alt buffer clearing
board: st: common: fix dfu alt buffer clearing
arm64: versal: fix dfu alt buffer clearing
xilinx: zynq: fix dfu alt buffer clearing
arm64: zynqmp: fix dfu alt buffer clearing

 board/socionext/developerbox/fwu_plat.c | 2 +-
 board/st/common/stm32mp_dfu.c           | 2 +-
 board/xilinx/versal/board.c             | 2 +-
 board/xilinx/zynq/board.c               | 2 +-
 board/xilinx/zynqmp/zynqmp.c            | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/5 fwu: developerbox: fix dfu alt buffer clearing

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 6b403ca4dcf4 ("fwu: DeveloperBox: add support for FWU")
Cc Masahisa Kojima <[email protected]>
Cc Tom Rini <[email protected]>
Cc Jassi Brar <[email protected]>
---
 board/socionext/developerbox/fwu_plat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/socionext/developerbox/fwu_plat.c +1 -1
index 26031795b09..a8b111477ef 100644
@@ -18,7 +18,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
 	struct mtd_info *mtd;
 	int ret;
 
-	memset(buf, 0, sizeof(buf));
+	memset(buf, 0, DFU_ALT_BUF_LEN);
 
 	mtd_probe_devices();
 
Signature · 1 line
2.47.2
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] fwu: developerbox: fix dfu alt buffer clearing

Hi Vincent,

Thank you for the patch.

Quoted 9 lines · Vincent Stehlé

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.

Quoted 5 lines
Fixes 6b403ca4dcf4 ("fwu: DeveloperBox: add support for FWU")
Cc Masahisa Kojima <[email protected]>
Cc Tom Rini <[email protected]>
Cc Jassi Brar <[email protected]>
Quoted 19 lines
---
 board/socionext/developerbox/fwu_plat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/socionext/developerbox/fwu_plat.c +1 -1
index 26031795b09..a8b111477ef 100644
@@ -18,7 +18,7 @@ void set_dfu_alt_info(char *interface, char *devstr)
 	struct mtd_info *mtd;
 	int ret;
 
-	memset(buf, 0, sizeof(buf));
+	memset(buf, 0, DFU_ALT_BUF_LEN);
 
 	mtd_probe_devices();
 
Signature · 1 line
2.47.2
#3 lore raw

PATCH 2/5 board: st: common: fix dfu alt buffer clearing

In reply to Vincent Stehlé

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")
Cc Patrick Delaunay <[email protected]>
Cc Patrice Chotard <[email protected]>
Cc Tom Rini <[email protected]>
Cc Marek Vasut <[email protected]>
---
 board/st/common/stm32mp_dfu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/st/common/stm32mp_dfu.c +1 -1
index 1db8e45480e..8c1f80b678a 100644
@@ -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);
Signature · 1 line
2.47.2
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] board: st: common: fix dfu alt buffer clearing

Hi Vincent,

Thank you for the patch.

Quoted 9 lines · Vincent Stehlé

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.

Quoted 6 lines
Fixes ec2933e543df ("board: stm32mp1: move set_dfu_alt_info in st common directory")
Cc Patrick Delaunay <[email protected]>
Cc Patrice Chotard <[email protected]>
Cc Tom Rini <[email protected]>
Cc Marek Vasut <[email protected]>
Quoted 19 lines
---
 board/st/common/stm32mp_dfu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/st/common/stm32mp_dfu.c +1 -1
index 1db8e45480e..8c1f80b678a 100644
@@ -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);
Signature · 1 line
2.47.2
#5 lore raw

Re: [PATCH 2/5] board: st: common: fix dfu alt buffer clearing

Quoted 15 lines · Mattijs Korpershoek

Hi Vincent,

Thank you for the patch.

Quoted 9 lines · Vincent Stehlé

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.

Quoted 8 lines
Quoted 6 lines
Fixes ec2933e543df ("board: stm32mp1: move set_dfu_alt_info in st common directory")
Cc Patrick Delaunay <[email protected]>
Cc Patrice Chotard <[email protected]>
Cc Tom Rini <[email protected]>
Cc Marek Vasut <[email protected]>

Patrice, Patrick,

This was assigned to me on patchwork. As [3-5] have been applied already by Michal, could you please pick this up?

I've assigned it to Patrice on patchwork.

Quoted 20 lines
Quoted 20 lines
---
 board/st/common/stm32mp_dfu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/st/common/stm32mp_dfu.c +1 -1
index 1db8e45480e..8c1f80b678a 100644
@@ -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);
Signature · 1 line
2.47.2
Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] board: st: common: fix dfu alt buffer clearing

In reply to Vincent Stehlé
Quoted 24 lines · Vincent Stehlé

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")
Cc Patrick Delaunay <[email protected]>
Cc Patrice Chotard <[email protected]>
Cc Tom Rini <[email protected]>
Cc Marek Vasut <[email protected]>
---
 board/st/common/stm32mp_dfu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/st/common/stm32mp_dfu.c +0 -0
index 1db8e45480e..8c1f80b678a 100644

board/st/common/stm32mp_dfu.c void set_dfu_alt_info(char *interface, char *devstr) · line 111

Quoted 8 lines
board/st/common/stm32mp_dfu.c +1 -1
@@ -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);

Hi Vincent,

Thanks

#7 lore raw

Re: [PATCH 2/5] board: st: common: fix dfu alt buffer clearing

Quoted 33 lines · Patrice CHOTARD
Quoted 30 lines · Vincent Stehlé

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")
Cc Patrick Delaunay <[email protected]>
Cc Patrice Chotard <[email protected]>
Cc Tom Rini <[email protected]>
Cc Marek Vasut <[email protected]>
---
 board/st/common/stm32mp_dfu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/st/common/stm32mp_dfu.c +1 -1
index 1db8e45480e..8c1f80b678a 100644
@@ -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);
 
Quoted 8 lines

board/st/common/stm32mp_dfu.c void set_dfu_alt_info(char *interface, char *devstr) · line 111

Quoted 2 lines
board/st/common/stm32mp_dfu.c +0 -0
 	snprintf(buf, DFU_ALT_BUF_LEN,
 		 "ram 0=%s", CONFIG_DFU_ALT_RAM0);

Hi Vincent,

Thanks

Applied to u-boot-stm32/master

Thanks
Patrice

#8 lore raw

PATCH 3/5 arm64: versal: fix dfu alt buffer clearing

In reply to Vincent Stehlé

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 064c8978b44f ("arm64: versal: Enable capsule update (SD)")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
---
 board/xilinx/versal/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/versal/board.c +1 -1
index b4483d00ad1..3edccc979d8 100644
@@ -396,7 +396,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);
 
 	multiboot = env_get_hex("multiboot", multiboot);
 
Signature · 1 line
2.47.2
Acked-by on v1 3/5
#9 lore raw

RE: [PATCH 3/5] arm64: versal: fix dfu alt buffer clearing

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 19 lines

From: U-Boot <[email protected]> On Behalf Of Vincent Stehlé
Sent: Monday, April 7, 2025 10:35 PM
To: [email protected]
Cc: Vincent Stehlé <[email protected]>; Jassi Brar <[email protected]>; Marek Vasut <[email protected]>; Masahisa Kojima <[email protected]>; Simek, Michal <[email protected]>; Patrice Chotard <[email protected]>; Patrick Delaunay <[email protected]>; Tom Rini <[email protected]>
Subject: [PATCH 3/5] arm64: versal: fix dfu alt buffer clearing

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

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)'.

Quoted 8 lines

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 064c8978b44f ("arm64: versal: Enable capsule update (SD)")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
Quoted 19 lines
---
 board/xilinx/versal/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/versal/board.c index renamed from board/xilinx/versal/board.c +0 -0

b4483d00ad1..3edccc979d8 100644

board/xilinx/versal/board.c +1 -2
@@ -396,7 +396,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);
 
        multiboot = env_get_hex("multiboot", multiboot);
 
--

2.47.2

maintainer Applied
#10 lore raw

Re: [PATCH 3/5] arm64: versal: fix dfu alt buffer clearing

In reply to Vincent Stehlé
Quoted 22 lines · Vincent Stehlé

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 064c8978b44f ("arm64: versal: Enable capsule update (SD)")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
---
  board/xilinx/versal/board.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/versal/board.c +0 -0
index b4483d00ad1..3edccc979d8 100644

board/xilinx/versal/board.c void set_dfu_alt_info(char *interface, char *devstr) · line 402

Quoted 8 lines
board/xilinx/versal/board.c +1 -1
@@ -396,7 +396,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);
 
  	multiboot = env_get_hex("multiboot", multiboot);
 

Applied.
M

#11 lore raw

PATCH 4/5 xilinx: zynq: fix dfu alt buffer clearing

In reply to Vincent Stehlé

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 c67fecd2125b ("ARM: zynq: Enable capsule update for qspi and mmc")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
---
 board/xilinx/zynq/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/zynq/board.c +1 -1
index 8dbfa560423..d8d4d5022ae 100644
@@ -176,7 +176,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);
 
 	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
 #if defined(CONFIG_SPL_FS_LOAD_PAYLOAD_NAME)
Signature · 1 line
2.47.2
Acked-by on v1 4/5
#12 lore raw

RE: [PATCH 4/5] xilinx: zynq: fix dfu alt buffer clearing

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 19 lines

From: U-Boot <[email protected]> On Behalf Of Vincent Stehlé
Sent: Monday, April 7, 2025 10:35 PM
To: [email protected]
Cc: Vincent Stehlé <[email protected]>; Jassi Brar <[email protected]>; Marek Vasut <[email protected]>; Masahisa Kojima <[email protected]>; Simek, Michal <[email protected]>; Patrice Chotard <[email protected]>; Patrick Delaunay <[email protected]>; Tom Rini <[email protected]>
Subject: [PATCH 4/5] xilinx: zynq: fix dfu alt buffer clearing

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

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)'.

Quoted 8 lines

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 c67fecd2125b ("ARM: zynq: Enable capsule update for qspi and mmc")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
Quoted 19 lines
---
 board/xilinx/zynq/board.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/zynq/board.c index renamed from board/xilinx/zynq/board.c +0 -0

8dbfa560423..d8d4d5022ae 100644

board/xilinx/zynq/board.c +1 -2
@@ -176,7 +176,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);
 
        switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {  #if
 defined(CONFIG_SPL_FS_LOAD_PAYLOAD_NAME)
--

2.47.2

maintainer Applied
#13 lore raw

Re: [PATCH 4/5] xilinx: zynq: fix dfu alt buffer clearing

In reply to Vincent Stehlé
Quoted 22 lines · Vincent Stehlé

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 c67fecd2125b ("ARM: zynq: Enable capsule update for qspi and mmc")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
---
  board/xilinx/zynq/board.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/zynq/board.c +0 -0
index 8dbfa560423..d8d4d5022ae 100644

board/xilinx/zynq/board.c void set_dfu_alt_info(char *interface, char *devstr) · line 182

Quoted 8 lines
board/xilinx/zynq/board.c +1 -1
@@ -176,7 +176,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);
 
  	switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
  #if defined(CONFIG_SPL_FS_LOAD_PAYLOAD_NAME)

Applied.
M

#14 lore raw

PATCH 5/5 arm64: zynqmp: fix dfu alt buffer clearing

In reply to Vincent Stehlé

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 b86f43de0be0 ("xilinx: zynqmp: Add support for runtime dfu_alt_info setup")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
---
 board/xilinx/zynqmp/zynqmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/zynqmp/zynqmp.c +1 -1
index 820fb252a3f..687dcd3ac9d 100644
@@ -669,7 +669,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);
 
 	multiboot = multi_boot();
 	if (multiboot < 0)
Signature · 1 line
2.47.2
Acked-by on v1 5/5
#15 lore raw

RE: [PATCH 5/5] arm64: zynqmp: fix dfu alt buffer clearing

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 19 lines

From: U-Boot <[email protected]> On Behalf Of Vincent Stehlé
Sent: Monday, April 7, 2025 10:35 PM
To: [email protected]
Cc: Vincent Stehlé <[email protected]>; Jassi Brar <[email protected]>; Marek Vasut <[email protected]>; Masahisa Kojima <[email protected]>; Simek, Michal <[email protected]>; Patrice Chotard <[email protected]>; Patrick Delaunay <[email protected]>; Tom Rini <[email protected]>
Subject: [PATCH 5/5] arm64: zynqmp: fix dfu alt buffer clearing

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

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)'.

Quoted 8 lines

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 b86f43de0be0 ("xilinx: zynqmp: Add support for runtime dfu_alt_info setup")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
Quoted 19 lines
---
 board/xilinx/zynqmp/zynqmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/zynqmp/zynqmp.c index renamed from board/xilinx/zynqmp/zynqmp.c +0 -0

820fb252a3f..687dcd3ac9d 100644

board/xilinx/zynqmp/zynqmp.c +1 -2
@@ -669,7 +669,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);
 
        multiboot = multi_boot();
        if (multiboot < 0)
--

2.47.2

maintainer Applied
#16 lore raw

Re: [PATCH 5/5] arm64: zynqmp: fix dfu alt buffer clearing

In reply to Vincent Stehlé
Quoted 22 lines · Vincent Stehlé

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 b86f43de0be0 ("xilinx: zynqmp: Add support for runtime dfu_alt_info setup")
Cc Michal Simek <[email protected]>
Cc Tom Rini <[email protected]>
---
  board/xilinx/zynqmp/zynqmp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
board/xilinx/zynqmp/zynqmp.c +0 -0
index 820fb252a3f..687dcd3ac9d 100644

board/xilinx/zynqmp/zynqmp.c void set_dfu_alt_info(char *interface, char *devstr) · line 675

Quoted 8 lines
board/xilinx/zynqmp/zynqmp.c +1 -1
@@ -669,7 +669,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);
 
  	multiboot = multi_boot();
  	if (multiboot < 0)

Applied.
M

#17 lore raw

Re: (subset) [PATCH 0/5] fix dfu alt buffer clearing

In reply to Vincent Stehlé

Hi,

Quoted 6 lines · Vincent Stehlé

This patch series applies the same fix in five different locations (the detailed description of the fix is in the patches).

I did validate statically by looking at the assembly before/after for all five cases, using the following defconfigs:

Quoted 7 lines

stm32mp15_defconfig
synquacer_developerbox_defconfig
xilinx_versal_virt_defconfig
xilinx_zynq_virt_defconfig
xilinx_zynqmp_kria_defconfig

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/5] fwu: developerbox: fix dfu alt buffer clearing

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/39a719dce59607d6abcac17cc2683aa9f2162539

--
Mattijs