*/
struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
{
- struct ceph_monmap *m;
+ struct ceph_monmap *m = 0;
int i, err = -EINVAL;
ceph_fsid_t fsid;
+ u32 epoch, num_mon;
dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p));
+ ceph_decode_need(&p, end, 2*sizeof(u32) + 2*sizeof(u64), bad);
+ ceph_decode_copy(&p, &fsid, sizeof(fsid));
+ ceph_decode_32(&p, epoch);
+ ceph_decode_32(&p, num_mon);
+ ceph_decode_need(&p, end, num_mon*sizeof(m->mon_inst[0]), bad);
+
/* The encoded and decoded sizes match. */
- m = kmalloc(end-p, GFP_NOFS);
+ m = kmalloc(sizeof(*m) + sizeof(m->mon_inst[0])*num_mon, GFP_NOFS);
if (m == NULL)
return ERR_PTR(-ENOMEM);
+ m->fsid = fsid;
+ m->epoch = epoch;
+ m->num_mon = num_mon;
+ ceph_decode_copy(&p, m->mon_inst, num_mon*sizeof(m->mon_inst[0]));
- ceph_decode_need(&p, end, 2*sizeof(u32) + 2*sizeof(u64), bad);
- ceph_decode_copy(&p, &m->fsid, sizeof(fsid));
- ceph_decode_32(&p, m->epoch);
- ceph_decode_32(&p, m->num_mon);
- ceph_decode_need(&p, end, m->num_mon*sizeof(m->mon_inst[0]), bad);
- ceph_decode_copy(&p, m->mon_inst, m->num_mon*sizeof(m->mon_inst[0]));
if (p != end)
goto bad;