mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier
@ 2018-12-25  6:59 Alexander Shiyan
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander Shiyan @ 2018-12-25  6:59 UTC (permalink / raw)
  To: barebox

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] imx-bbu-nand-fcb: Remove unused variable partition_size
  2018-12-25  6:59 [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier Alexander Shiyan
@ 2018-12-25  6:59 ` Alexander Shiyan
  2019-01-03  9:24 ` [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Shiyan @ 2018-12-25  6:59 UTC (permalink / raw)
  To: barebox

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 common/imx-bbu-nand-fcb.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 8383aeacf..a29a1bf91 100644
--- a/common/imx-bbu-nand-fcb.c
+++ b/common/imx-bbu-nand-fcb.c
@@ -1198,9 +1198,8 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat
 	int ret, i;
 	struct fcb_block *fcb = NULL;
 	void *fw = NULL, *fw_orig = NULL;
-	unsigned fw_size, partition_size;
 	enum filetype filetype;
-	unsigned num_blocks_fw;
+	unsigned num_blocks_fw, fw_size;
 	int used = 0;
 	int fw_orig_len;
 	int used_refresh = 0, unused_refresh = 0;
@@ -1222,7 +1221,6 @@ 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) {
-- 
2.13.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier
  2018-12-25  6:59 [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier Alexander Shiyan
  2018-12-25  6:59 ` [PATCH 2/2] imx-bbu-nand-fcb: Remove unused variable partition_size Alexander Shiyan
@ 2019-01-03  9:24 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2019-01-03  9:24 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Tue, Dec 25, 2018 at 09:59:22AM +0300, Alexander Shiyan wrote:
> 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(-)

Applied, thanks

Sascha

> 
> 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
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-03  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-25  6:59 [PATCH 1/2] imx-bbu-nand-fcb: Check the required space a bit earlier Alexander Shiyan
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox