diff options
author | ZhaoLong Wang <wangzhaolong1@huawei.com> | 2024-01-13 14:06:01 +0100 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2024-02-25 21:39:08 +0100 |
commit | 9277b3a64953c09e88a33adf59fb085e0a87d357 (patch) | |
tree | 9e0d4b3286fa4520b428a0c9e639b937acc56ab6 | |
parent | ubi: fix slab-out-of-bounds in ubi_eba_get_ldesc+0xfb/0x130 (diff) | |
download | linux-9277b3a64953c09e88a33adf59fb085e0a87d357.tar.xz linux-9277b3a64953c09e88a33adf59fb085e0a87d357.zip |
ubi: Correct the number of PEBs after a volume resize failure
In the error handling path `out_acc` of `ubi_resize_volume()`,
when `pebs < 0`, it indicates that the volume table record failed to
update when the volume was shrunk. In this case, the number of `ubi->avail_pebs`
and `ubi->rsvd_pebs` should be restored to their previous values to prevent
the UBI layer from reporting an incorrect number of available PEBs.
Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r-- | drivers/mtd/ubi/vmt.c | 9 |
1 files 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: |