[PATCH] firmware: zynqmp-fpga: fix use of uninitialized addr
Michael Tretter
m.tretter at pengutronix.de
Wed Feb 2 02:10:54 PST 2022
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 at 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
More information about the barebox
mailing list