summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshengyong <shengyong1@huawei.com>2016-05-27 09:44:41 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-05-27 12:30:27 +0200
commit794d45b116fda05f03f83c495bd85f26c89dcc20 (patch)
tree6bd1aeddc6e11fa74b1200151645c884aa400252
parent78ae01bf2bd502c468df56cae85b0fe02f70c5d0 (diff)
downloadbarebox-794d45b116fda05f03f83c495bd85f26c89dcc20.tar.gz
barebox-794d45b116fda05f03f83c495bd85f26c89dcc20.tar.xz
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> Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/mtd/ubi/fastmap.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 5483bb97ae..f33c2dbb0b 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -128,8 +128,10 @@ static struct ubi_ainf_volume *add_vol(struct ubi_attach_info *ai, int vol_id,
if (vol_id > av->vol_id)
p = &(*p)->rb_left;
- else
+ else if (vol_id < av->vol_id)
p = &(*p)->rb_right;
+ else
+ return ERR_PTR(-EINVAL);
}
av = kmalloc(sizeof(struct ubi_ainf_volume), GFP_KERNEL);
@@ -687,6 +689,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
if (!av)
goto fail_bad;
+ if (PTR_ERR(av) == -EINVAL) {
+ ubi_err(ubi, "volume (ID %i) already exists",
+ fmvhdr->vol_id);
+ goto fail_bad;
+ }
ai->vols_found++;
if (ai->highest_vol_id < be32_to_cpu(fmvhdr->vol_id))