From: Alexander Shiyan <shc_work@mail.ru>
To: barebox@lists.infradead.org
Subject: [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier
Date: Tue, 25 Dec 2018 09:59:22 +0300 [thread overview]
Message-ID: <20181225065923.15943-1-shc_work@mail.ru> (raw)
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>
---
common/imx-bbu-nand-fcb.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 8c276a43c..8383aeacf 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;
--
2.13.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2018-12-25 6:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-25 6:59 Alexander Shiyan [this message]
2018-12-25 6:59 ` [PATCH 2/2] imx-bbu-nand-fcb: Remove unused variable partition_size Alexander Shiyan
2019-01-03 9:24 ` [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier 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=20181225065923.15943-1-shc_work@mail.ru \
--to=shc_work@mail.ru \
--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