diff mbox series

ubi: correct the calculation of fastmap size

Message ID 20240220024903.2477468-1-yi.zhang@huaweicloud.com
State Accepted
Headers show
Series ubi: correct the calculation of fastmap size | expand

Commit Message

Zhang Yi Feb. 20, 2024, 2:49 a.m. UTC
From: Zhang Yi <yi.zhang@huawei.com>

Now that the calculation of fastmap size in ubi_calc_fm_size() is
incorrect since it miss each user volume's ubi_fm_eba structure and the
Internal UBI volume info. Let's correct the calculation.

Cc: stable@vger.kernel.org
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
 drivers/mtd/ubi/fastmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Zhihao Cheng Feb. 20, 2024, 4:26 a.m. UTC | #1
在 2024/2/20 10:49, Zhang Yi 写道:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> Now that the calculation of fastmap size in ubi_calc_fm_size() is
> incorrect since it miss each user volume's ubi_fm_eba structure and the
> Internal UBI volume info. Let's correct the calculation.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> ---
>   drivers/mtd/ubi/fastmap.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)

Looks like the assertion 'ubi_assert(fm_pos <= ubi->fm_size)' has never 
failed in the real world, maybe the missing calculated size is too small 
(sizeof(struct ubi_fm_eba) * 129 = 8 * 129 = 1032) and hard to trigger 
an effective problem, or no one will create many volumes.

I have tested on several types of flashes, all ubi tests(from mtd-utils) 
are passed.

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>


> 
> diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
> index 2a728c31e6b8..9a4940874be5 100644
> --- a/drivers/mtd/ubi/fastmap.c
> +++ b/drivers/mtd/ubi/fastmap.c
> @@ -85,9 +85,10 @@ size_t ubi_calc_fm_size(struct ubi_device *ubi)
>   		sizeof(struct ubi_fm_scan_pool) +
>   		sizeof(struct ubi_fm_scan_pool) +
>   		(ubi->peb_count * sizeof(struct ubi_fm_ec)) +
> -		(sizeof(struct ubi_fm_eba) +
> -		(ubi->peb_count * sizeof(__be32))) +
> -		sizeof(struct ubi_fm_volhdr) * UBI_MAX_VOLUMES;
> +		((sizeof(struct ubi_fm_eba) +
> +		  sizeof(struct ubi_fm_volhdr)) *
> +		 (UBI_MAX_VOLUMES + UBI_INT_VOL_COUNT)) +
> +		(ubi->peb_count * sizeof(__be32));
>   	return roundup(size, ubi->leb_size);
>   }
>   
>
diff mbox series

Patch

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 2a728c31e6b8..9a4940874be5 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -85,9 +85,10 @@  size_t ubi_calc_fm_size(struct ubi_device *ubi)
 		sizeof(struct ubi_fm_scan_pool) +
 		sizeof(struct ubi_fm_scan_pool) +
 		(ubi->peb_count * sizeof(struct ubi_fm_ec)) +
-		(sizeof(struct ubi_fm_eba) +
-		(ubi->peb_count * sizeof(__be32))) +
-		sizeof(struct ubi_fm_volhdr) * UBI_MAX_VOLUMES;
+		((sizeof(struct ubi_fm_eba) +
+		  sizeof(struct ubi_fm_volhdr)) *
+		 (UBI_MAX_VOLUMES + UBI_INT_VOL_COUNT)) +
+		(ubi->peb_count * sizeof(__be32));
 	return roundup(size, ubi->leb_size);
 }