2023-05-04 03:02:12

by ZhaoLong Wang

[permalink] [raw]
Subject: [PATCH -next,V2 2/2] ubi: Correct the number of PEBs after a volume resize failure

In the error handing path `out_acc` of the ubi_resize_volume(),
when `pebs < 0`, it means that the volume table record fails to be
updated when the volume is shrinked. In this case, the number of
ubi->avail_pebs` and `ubi->rsvd_pebs` should also be restored,
otherwise the UBI will display an incorrect number of available PEBs.

Signed-off-by: ZhaoLong Wang <[email protected]>
---
drivers/mtd/ubi/vmt.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 97294def01eb..990571287e84 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -515,13 +515,12 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
out_acc:
spin_lock(&ubi->volumes_lock);
vol->reserved_pebs = reserved_pebs - pebs;
- if (pebs > 0) {
- ubi->rsvd_pebs -= pebs;
- ubi->avail_pebs += pebs;
+ ubi->rsvd_pebs -= pebs;
+ ubi->avail_pebs += pebs;
+ if (pebs > 0)
ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs);
- } else {
+ else
ubi_eba_copy_table(vol, old_eba_tbl, reserved_pebs);
- }
vol->eba_tbl = old_eba_tbl;
spin_unlock(&ubi->volumes_lock);
out_free:
--
2.31.1


2023-05-04 12:20:57

by Zhihao Cheng

[permalink] [raw]
Subject: Re: [PATCH -next,V2 2/2] ubi: Correct the number of PEBs after a volume resize failure

?? 2023/5/4 10:53, ZhaoLong Wang ะด??:
> In the error handing path `out_acc` of the ubi_resize_volume(),
> when `pebs < 0`, it means that the volume table record fails to be
> updated when the volume is shrinked. In this case, the number of
> ubi->avail_pebs` and `ubi->rsvd_pebs` should also be restored,
> otherwise the UBI will display an incorrect number of available PEBs.
>
> Signed-off-by: ZhaoLong Wang <[email protected]>
> ---
> drivers/mtd/ubi/vmt.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>

Reviewed-by: Zhihao Cheng <[email protected]>

> diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
> index 97294def01eb..990571287e84 100644
> --- a/drivers/mtd/ubi/vmt.c
> +++ b/drivers/mtd/ubi/vmt.c
> @@ -515,13 +515,12 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
> out_acc:
> spin_lock(&ubi->volumes_lock);
> vol->reserved_pebs = reserved_pebs - pebs;
> - if (pebs > 0) {
> - ubi->rsvd_pebs -= pebs;
> - ubi->avail_pebs += pebs;
> + ubi->rsvd_pebs -= pebs;
> + ubi->avail_pebs += pebs;
> + if (pebs > 0)
> ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs);
> - } else {
> + else
> ubi_eba_copy_table(vol, old_eba_tbl, reserved_pebs);
> - }
> vol->eba_tbl = old_eba_tbl;
> spin_unlock(&ubi->volumes_lock);
> out_free:
>