libceph: use struct_size() for kmalloc() in crush_decode()
[sfrench/cifs-2.6.git] / net / ceph / osdmap.c
index 98c0ff3d644174fe9f5ce30fedfd617c5236539b..48a31dc9161ccba6e971fde3680033dbebbe3732 100644 (file)
@@ -495,9 +495,8 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
                          / sizeof(struct crush_rule_step))
                        goto bad;
 #endif
-               r = c->rules[i] = kmalloc(sizeof(*r) +
-                                         yes*sizeof(struct crush_rule_step),
-                                         GFP_NOFS);
+               r = kmalloc(struct_size(r, steps, yes), GFP_NOFS);
+               c->rules[i] = r;
                if (r == NULL)
                        goto badmem;
                dout(" rule %d is at %p\n", i, r);