Skip to content

Commit e96a8a3

Browse files
shengyongrichardweinberger
authored andcommitted
UBI: Fastmap: Do not add vol if it already exists
During fastmap attaching, check if a volume already exists when adding the volume to volume tree. NOTE that the issue cannot happen, only if the on-flash fastmap data is modified. Signed-off-by: Sheng Yong <shengyong1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent e8d266c commit e96a8a3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/mtd/ubi/fastmap.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ static struct ubi_ainf_volume *add_vol(struct ubi_attach_info *ai, int vol_id,
192192

193193
if (vol_id > av->vol_id)
194194
p = &(*p)->rb_left;
195-
else
195+
else if (vol_id < av->vol_id)
196196
p = &(*p)->rb_right;
197+
else
198+
return ERR_PTR(-EINVAL);
197199
}
198200

199201
av = kmalloc(sizeof(struct ubi_ainf_volume), GFP_KERNEL);
@@ -748,6 +750,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
748750

749751
if (!av)
750752
goto fail_bad;
753+
if (PTR_ERR(av) == -EINVAL) {
754+
ubi_err(ubi, "volume (ID %i) already exists",
755+
fmvhdr->vol_id);
756+
goto fail_bad;
757+
}
751758

752759
ai->vols_found++;
753760
if (ai->highest_vol_id < be32_to_cpu(fmvhdr->vol_id))

0 commit comments

Comments
 (0)