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>
 
                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);
 
                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))