diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c index a563b3b..946a3e9 100644 --- a/arch/arm/mach-imx/imx-bbu-internal.c +++ b/arch/arm/mach-imx/imx-bbu-internal.c @@ -87,6 +87,7 @@ const void *buf, int image_len) { int fd, ret, offset = 0; + struct stat st; fd = open(devicefile, O_RDWR | O_CREAT); if (fd < 0) @@ -101,6 +102,15 @@ if (imx_handler->handler.flags & IMX_BBU_FLAG_KEEP_HEAD) offset += imx_handler->flash_header_offset; + ret = fstat(fd, &st); + if (ret) + goto err_close; + + if (image_len > st.st_size) { + ret = -ENOSPC; + goto err_close; + } + ret = imx_bbu_protect(fd, imx_handler, devicefile, offset, image_len, 0); if (ret)