* [PATCH 1/2] ARM: imx/bbu-external-nand: Rename offset -> nand_offset
@ 2022-07-14 8:11 Uwe Kleine-König
2022-07-14 8:11 ` [PATCH 2/2] ARM: imx/bbu-external-nand: Fix freeing image copy Uwe Kleine-König
2022-07-14 8:46 ` [PATCH 1/2] ARM: imx/bbu-external-nand: Rename offset -> nand_offset Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2022-07-14 8:11 UTC (permalink / raw)
To: barebox
The next commit introduces a new offset variable for image. To be better
able to differentiate the two, pick a better name for the already
existing one. There is no functional change.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
arch/arm/mach-imx/imx-bbu-external-nand.c | 26 +++++++++++------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c
index 392497e43423..4d3493f9e1e0 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 offset = 0;
+ loff_t nand_offset = 0;
int block = 0, len, now, blocksize;
void *image = NULL;
@@ -61,27 +61,27 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
* Collect bad blocks and construct BBT
*/
while (size_need > 0) {
- ret = ioctl(fd, MEMGETBADBLOCK, &offset);
+ ret = ioctl(fd, MEMGETBADBLOCK, &nand_offset);
if (ret < 0)
goto out;
if (ret) {
- if (!offset) {
+ if (!nand_offset) {
printf("1st block is bad. This is not supported\n");
ret = -EINVAL;
goto out;
}
- debug("bad block at 0x%08llx\n", offset);
+ debug("bad block at 0x%08llx\n", nand_offset);
num_bb++;
bbt |= (1 << block);
- offset += blocksize;
+ nand_offset += blocksize;
block++;
continue;
}
size_need -= blocksize;
size_available -= blocksize;
- offset += blocksize;
+ nand_offset += blocksize;
block++;
if (size_available < 0) {
@@ -124,7 +124,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
}
len = data->len;
- offset = 0;
+ nand_offset = 0;
/* last chance before erasing the flash */
ret = bbu_confirm(data);
@@ -137,13 +137,13 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
while (len > 0) {
now = min(len, blocksize);
- ret = ioctl(fd, MEMGETBADBLOCK, &offset);
+ ret = ioctl(fd, MEMGETBADBLOCK, &nand_offset);
if (ret < 0)
goto out;
if (ret) {
- offset += blocksize;
- if (lseek(fd, offset, SEEK_SET) != offset) {
+ nand_offset += blocksize;
+ if (lseek(fd, nand_offset, SEEK_SET) != nand_offset) {
ret = -errno;
goto out;
}
@@ -151,9 +151,9 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
continue;
}
- debug("writing %d bytes at 0x%08llx\n", now, offset);
+ debug("writing %d bytes at 0x%08llx\n", now, nand_offset);
- ret = erase(fd, blocksize, offset);
+ ret = erase(fd, blocksize, nand_offset);
if (ret)
goto out;
@@ -163,7 +163,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
len -= now;
image += now;
- offset += now;
+ nand_offset += now;
}
ret = 0;
base-commit: 298727bc7931fe878fd72a1fa6f35c18bd7c593c
--
2.36.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] ARM: imx/bbu-external-nand: Fix freeing image copy
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
2022-07-14 8:46 ` [PATCH 1/2] ARM: imx/bbu-external-nand: Rename offset -> nand_offset Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2022-07-14 8:11 UTC (permalink / raw)
To: barebox
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] ARM: imx/bbu-external-nand: Rename offset -> nand_offset
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 ` [PATCH 2/2] ARM: imx/bbu-external-nand: Fix freeing image copy Uwe Kleine-König
@ 2022-07-14 8:46 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-07-14 8:46 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Thu, Jul 14, 2022 at 10:11:07AM +0200, Uwe Kleine-König wrote:
> The next commit introduces a new offset variable for image. To be better
> able to differentiate the two, pick a better name for the already
> existing one. There is no functional change.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> arch/arm/mach-imx/imx-bbu-external-nand.c | 26 +++++++++++------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c
> index 392497e43423..4d3493f9e1e0 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 offset = 0;
> + loff_t nand_offset = 0;
> int block = 0, len, now, blocksize;
> void *image = NULL;
>
> @@ -61,27 +61,27 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
> * Collect bad blocks and construct BBT
> */
> while (size_need > 0) {
> - ret = ioctl(fd, MEMGETBADBLOCK, &offset);
> + ret = ioctl(fd, MEMGETBADBLOCK, &nand_offset);
> if (ret < 0)
> goto out;
>
> if (ret) {
> - if (!offset) {
> + if (!nand_offset) {
> printf("1st block is bad. This is not supported\n");
> ret = -EINVAL;
> goto out;
> }
>
> - debug("bad block at 0x%08llx\n", offset);
> + debug("bad block at 0x%08llx\n", nand_offset);
> num_bb++;
> bbt |= (1 << block);
> - offset += blocksize;
> + nand_offset += blocksize;
> block++;
> continue;
> }
> size_need -= blocksize;
> size_available -= blocksize;
> - offset += blocksize;
> + nand_offset += blocksize;
> block++;
>
> if (size_available < 0) {
> @@ -124,7 +124,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
> }
>
> len = data->len;
> - offset = 0;
> + nand_offset = 0;
>
> /* last chance before erasing the flash */
> ret = bbu_confirm(data);
> @@ -137,13 +137,13 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
> while (len > 0) {
> now = min(len, blocksize);
>
> - ret = ioctl(fd, MEMGETBADBLOCK, &offset);
> + ret = ioctl(fd, MEMGETBADBLOCK, &nand_offset);
> if (ret < 0)
> goto out;
>
> if (ret) {
> - offset += blocksize;
> - if (lseek(fd, offset, SEEK_SET) != offset) {
> + nand_offset += blocksize;
> + if (lseek(fd, nand_offset, SEEK_SET) != nand_offset) {
> ret = -errno;
> goto out;
> }
> @@ -151,9 +151,9 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
> continue;
> }
>
> - debug("writing %d bytes at 0x%08llx\n", now, offset);
> + debug("writing %d bytes at 0x%08llx\n", now, nand_offset);
>
> - ret = erase(fd, blocksize, offset);
> + ret = erase(fd, blocksize, nand_offset);
> if (ret)
> goto out;
>
> @@ -163,7 +163,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
>
> len -= now;
> image += now;
> - offset += now;
> + nand_offset += now;
> }
>
> ret = 0;
>
> base-commit: 298727bc7931fe878fd72a1fa6f35c18bd7c593c
> --
> 2.36.1
>
>
>
--
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 |
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-14 8:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] ARM: imx/bbu-external-nand: Fix freeing image copy Uwe Kleine-König
2022-07-14 8:46 ` [PATCH 1/2] ARM: imx/bbu-external-nand: Rename offset -> nand_offset Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox