/*
  * Insert a new pg_temp mapping
  */
-static void __insert_pg_mapping(struct ceph_pg_mapping *new,
-                               struct rb_root *root)
+static int __insert_pg_mapping(struct ceph_pg_mapping *new,
+                              struct rb_root *root)
 {
        struct rb_node **p = &root->rb_node;
        struct rb_node *parent = NULL;
                else if (new->pgid > pg->pgid)
                        p = &(*p)->rb_right;
                else
-                       BUG();
+                       return -EEXIST;
        }
 
        rb_link_node(&new->node, parent, p);
        rb_insert_color(&new->node, root);
+       return 0;
 }
 
 /*
                for (j = 0; j < n; j++)
                        ceph_decode_32(p, pg->osds[j]);
 
-               __insert_pg_mapping(pg, &map->pg_temp);
+               err = __insert_pg_mapping(pg, &map->pg_temp);
+               if (err)
+                       goto bad;
                dout(" added pg_temp %llx len %d\n", pgid, len);
        }
 
                        pg->len = pglen;
                        for (j = 0; j < len; j++)
                                ceph_decode_32(p, pg->osds[j]);
-                       __insert_pg_mapping(pg, &map->pg_temp);
+                       err = __insert_pg_mapping(pg, &map->pg_temp);
+                       if (err)
+                               goto bad;
                        dout(" added pg_temp %llx len %d\n", pgid, pglen);
                }
        }