mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] ARM: imx/bbu-external-nand: Fix freeing image copy
Date: Thu, 14 Jul 2022 10:11:08 +0200	[thread overview]
Message-ID: <20220714081108.101094-2-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20220714081108.101094-1-u.kleine-koenig@pengutronix.de>

imx_bbu_external_nand_update() does:

	image = memdup(data->image, data->len);
	...
	for (...) {
		...
		image += now;
		...
	}
	...
	free(image)

So it's not the original pointer that is passed to free. This results in
a hang.

Instead use an offset variable and keep image constant.

Fixes: 93b564d9acc7 ("ARM: i.MX bbu-external-nand: Do not modify image")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-external-nand.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c
index 4d3493f9e1e0..40dbaabdc7fa 100644
--- a/arch/arm/mach-imx/imx-bbu-external-nand.c
+++ b/arch/arm/mach-imx/imx-bbu-external-nand.c
@@ -29,7 +29,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
 	int size_available, size_need;
 	int ret;
 	uint32_t num_bb = 0, bbt = 0;
-	loff_t nand_offset = 0;
+	loff_t nand_offset = 0, image_offset = 0;
 	int block = 0, len, now, blocksize;
 	void *image = NULL;
 
@@ -157,12 +157,12 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
 		if (ret)
 			goto out;
 
-		ret = write(fd, image, now);
+		ret = write(fd, image + image_offset, now);
 		if (ret < 0)
 			goto out;
 
 		len -= now;
-		image += now;
+		image_offset += now;
 		nand_offset += now;
 	}
 
-- 
2.36.1




  reply	other threads:[~2022-07-14  8:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  8:11 [PATCH 1/2] ARM: imx/bbu-external-nand: Rename offset -> nand_offset Uwe Kleine-König
2022-07-14  8:11 ` Uwe Kleine-König [this message]
2022-07-14  8:46 ` 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=20220714081108.101094-2-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@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