diff options
author | Alexander Shiyan <shc_work@mail.ru> | 2018-12-25 09:59:22 +0300 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-01-03 10:31:15 +0100 |
commit | 6b35641c326a0a1b98fa77fab995bf77872747d8 (patch) | |
tree | 38a650844f39d9727f44efa354264e58e9ca1b8b /common/imx-bbu-nand-fcb.c | |
parent | fbb3f53cb46db4d91f4234733d36ce557649322e (diff) | |
download | barebox-6b35641c326a0a1b98fa77fab995bf77872747d8.tar.gz barebox-6b35641c326a0a1b98fa77fab995bf77872747d8.tar.xz |
imx-bbu-nand-fcb: Check the required space a bit earlier
If the partition size is too small for imx_bbu_nand_update(),
this can lead to an infinite loop in the imx_bbu_firmware_fcb_start_page()
function, because imx_bbu_firmware_max_blocks() returns zero.
Fix this by place imx_bbu_firmware_max_blocks() a bit early.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/imx-bbu-nand-fcb.c')
-rw-r--r-- | common/imx-bbu-nand-fcb.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c index 8c276a43c0..8383aeacf7 100644 --- a/common/imx-bbu-nand-fcb.c +++ b/common/imx-bbu-nand-fcb.c @@ -1224,6 +1224,12 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat mtd = bcb_cdev->mtd; partition_size = mtd->size; + num_blocks_fw = imx_bbu_firmware_max_blocks(mtd); + if (num_blocks_fw < 1) { + pr_err("Not enough space for firmware\n"); + return -ENOSPC; + } + for (i = 0; i < 4; i++) { read_fcb(mtd, i, &fcb); if (fcb) @@ -1329,8 +1335,6 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat pr_info("Refreshing existing firmware\n"); } - num_blocks_fw = imx_bbu_firmware_max_blocks(mtd); - if (num_blocks_fw * mtd->erasesize < fw_size) { pr_err("Not enough space for update\n"); return -ENOSPC; |