cls_bpf: Use kmemdup instead of duplicating it in cls_bpf_prog_from_ops
authorYueHaibing <yuehaibing@huawei.com>
Sat, 28 Jul 2018 10:35:15 +0000 (18:35 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 29 Jul 2018 20:19:49 +0000 (13:19 -0700)
Replace calls to kmalloc followed by a memcpy with a direct call to
kmemdup.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/cls_bpf.c

index 66e0ac9811f9e3811a9b3b19bb453022c7004879..fa6fe2fe0f32b521ccb7a77f4e19693e08baf859 100644 (file)
@@ -349,12 +349,10 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)
        if (bpf_size != nla_len(tb[TCA_BPF_OPS]))
                return -EINVAL;
 
-       bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
+       bpf_ops = kmemdup(nla_data(tb[TCA_BPF_OPS]), bpf_size, GFP_KERNEL);
        if (bpf_ops == NULL)
                return -ENOMEM;
 
-       memcpy(bpf_ops, nla_data(tb[TCA_BPF_OPS]), bpf_size);
-
        fprog_tmp.len = bpf_num_ops;
        fprog_tmp.filter = bpf_ops;