libceph: check pointer before assigned to "c->rules[]"
authorLi Qiong <liqiong@nfschina.com>
Tue, 14 Jun 2022 07:10:59 +0000 (15:10 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 2 Aug 2022 22:54:12 +0000 (00:54 +0200)
It should be better to check pointer firstly, then assign it
to c->rules[]. Refine code a little bit.

Signed-off-by: Li Qiong <liqiong@nfschina.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
net/ceph/osdmap.c

index 2823bb3..5283ee9 100644 (file)
@@ -571,10 +571,10 @@ static struct crush_map *crush_decode(void *pbyval, void *end)
                        goto bad;
 #endif
                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);
+               c->rules[i] = r;
                r->len = yes;
                ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */
                ceph_decode_need(p, end, r->len*3*sizeof(u32), bad);