mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: barebox@lists.infradead.org
Cc: m.tretter@pengutronix.de
Subject: [PATCH] firmware: zynqmp-fpga: fix use of uninitialized addr
Date: Wed,  2 Feb 2022 11:10:54 +0100	[thread overview]
Message-ID: <20220202101054.3924339-1-m.tretter@pengutronix.de> (raw)

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


             reply	other threads:[~2022-02-02 10:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 10:10 Michael Tretter [this message]
2022-02-03 10:16 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220202101054.3924339-1-m.tretter@pengutronix.de \
    --to=m.tretter@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox