[PATCH 08/15] ARM: i.MX bbu-external-nand: Do not modify image

Sascha Hauer s.hauer at pengutronix.de
Mon May 17 11:54:17 PDT 2021


struct bbu_data::image is const, so do not modify the image, but create
a copy instead.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx-bbu-external-nand.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c
index 8aa4f152a1..0f7cc51caf 100644
--- a/arch/arm/mach-imx/imx-bbu-external-nand.c
+++ b/arch/arm/mach-imx/imx-bbu-external-nand.c
@@ -39,7 +39,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
 	uint32_t num_bb = 0, bbt = 0;
 	loff_t offset = 0;
 	int block = 0, len, now, blocksize;
-	void *image = data->image;
+	void *image = NULL;
 
 	ret = stat(data->devicefile, &s);
 	if (ret)
@@ -55,6 +55,12 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
 	if (ret)
 		goto out;
 
+	image = memdup(data->image, data->len);
+	if (!image) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	blocksize = meminfo.erasesize;
 
 	size_need = data->len;
@@ -172,6 +178,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_
 
 out:
 	close(fd);
+	free(image);
 
 	return ret;
 }
-- 
2.29.2




More information about the barebox mailing list