mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] firmware: zynqmp-fpga: fix use of uninitialized addr
@ 2022-02-02 10:10 Michael Tretter
  2022-02-03 10:16 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Tretter @ 2022-02-02 10:10 UTC (permalink / raw)
  To: barebox; +Cc: m.tretter

The bitstream loading API of the firmware is a bit clunky, as the driver
needs to either pass the size of the bitstream or a pointer to the size
of the bitstream.

Commit 2f29ee311f1d ("firmware: zynqmp-fpga: do not use DMA coherent
memory for bitstream") broke the loading by address, as the pointer to
the bitstream size was set using the uninitialized DMA address.

Fix it by determining the argument that is passed to the firmware after
the bitstream has been mapped and always write the size of the bitstream
at the end of the passed buffer.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 drivers/firmware/zynqmp-fpga.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/zynqmp-fpga.c b/drivers/firmware/zynqmp-fpga.c
index a76600d4c96d..63d7398fd4e8 100644
--- a/drivers/firmware/zynqmp-fpga.c
+++ b/drivers/firmware/zynqmp-fpga.c
@@ -252,13 +252,7 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
 				   body_length / sizeof(u32));
 	else
 		memcpy((u32 *)buf_aligned, body, body_length);
-
-	if (mgr->features & ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED) {
-		buf_size = body_length;
-	} else {
-		buf_aligned[body_length / sizeof(*buf_aligned)] = body_length;
-		buf_size = addr + body_length;
-	}
+	buf_aligned[body_length / sizeof(*buf_aligned)] = body_length;
 
 	addr = dma_map_single(&mgr->dev, buf_aligned,
 			      body_length + sizeof(buf_size), DMA_TO_DEVICE);
@@ -267,6 +261,11 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
 		goto err_free_dma;
 	}
 
+	if (mgr->features & ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED)
+		buf_size = body_length;
+	else
+		buf_size = addr + body_length;
+
 	status = mgr->eemi_ops->fpga_load((u64)addr, buf_size, flags);
 	dma_unmap_single(&mgr->dev, addr, body_length + sizeof(buf_size),
 			 DMA_TO_DEVICE);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] firmware: zynqmp-fpga: fix use of uninitialized addr
  2022-02-02 10:10 [PATCH] firmware: zynqmp-fpga: fix use of uninitialized addr Michael Tretter
@ 2022-02-03 10:16 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-02-03 10:16 UTC (permalink / raw)
  To: Michael Tretter; +Cc: barebox

On Wed, Feb 02, 2022 at 11:10:54AM +0100, Michael Tretter wrote:
> The bitstream loading API of the firmware is a bit clunky, as the driver
> needs to either pass the size of the bitstream or a pointer to the size
> of the bitstream.
> 
> Commit 2f29ee311f1d ("firmware: zynqmp-fpga: do not use DMA coherent
> memory for bitstream") broke the loading by address, as the pointer to
> the bitstream size was set using the uninitialized DMA address.
> 
> Fix it by determining the argument that is passed to the firmware after
> the bitstream has been mapped and always write the size of the bitstream
> at the end of the passed buffer.
> 
> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> ---
>  drivers/firmware/zynqmp-fpga.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-03 10:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 10:10 [PATCH] firmware: zynqmp-fpga: fix use of uninitialized addr Michael Tretter
2022-02-03 10:16 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox