Commit c7b1b249 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by David S. Miller

[SCHED]: Use kmemdup & kzalloc where appropriate

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@mandriva.com>
parent b3ab09f9
...@@ -156,10 +156,9 @@ static int tcf_ipt_init(struct rtattr *rta, struct rtattr *est, ...@@ -156,10 +156,9 @@ static int tcf_ipt_init(struct rtattr *rta, struct rtattr *est,
rtattr_strlcpy(tname, tb[TCA_IPT_TABLE-1], IFNAMSIZ) >= IFNAMSIZ) rtattr_strlcpy(tname, tb[TCA_IPT_TABLE-1], IFNAMSIZ) >= IFNAMSIZ)
strcpy(tname, "mangle"); strcpy(tname, "mangle");
t = kmalloc(td->u.target_size, GFP_KERNEL); t = kmemdup(td, td->u.target_size, GFP_KERNEL);
if (unlikely(!t)) if (unlikely(!t))
goto err2; goto err2;
memcpy(t, td, td->u.target_size);
if ((err = ipt_init_target(t, tname, hook)) < 0) if ((err = ipt_init_target(t, tname, hook)) < 0)
goto err3; goto err3;
...@@ -256,13 +255,12 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int ...@@ -256,13 +255,12 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, int
** for foolproof you need to not assume this ** for foolproof you need to not assume this
*/ */
t = kmalloc(ipt->tcfi_t->u.user.target_size, GFP_ATOMIC); t = kmemdup(ipt->tcfi_t, ipt->tcfi_t->u.user.target_size, GFP_ATOMIC);
if (unlikely(!t)) if (unlikely(!t))
goto rtattr_failure; goto rtattr_failure;
c.bindcnt = ipt->tcf_bindcnt - bind; c.bindcnt = ipt->tcf_bindcnt - bind;
c.refcnt = ipt->tcf_refcnt - ref; c.refcnt = ipt->tcf_refcnt - ref;
memcpy(t, ipt->tcfi_t, ipt->tcfi_t->u.user.target_size);
strcpy(t->u.user.name, ipt->tcfi_t->u.kernel.target->name); strcpy(t->u.user.name, ipt->tcfi_t->u.kernel.target->name);
RTA_PUT(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t); RTA_PUT(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t);
......
...@@ -71,11 +71,10 @@ static int tcf_simp_release(struct tcf_defact *d, int bind) ...@@ -71,11 +71,10 @@ static int tcf_simp_release(struct tcf_defact *d, int bind)
static int alloc_defdata(struct tcf_defact *d, u32 datalen, void *defdata) static int alloc_defdata(struct tcf_defact *d, u32 datalen, void *defdata)
{ {
d->tcfd_defdata = kmalloc(datalen, GFP_KERNEL); d->tcfd_defdata = kmemdup(defdata, datalen, GFP_KERNEL);
if (unlikely(!d->tcfd_defdata)) if (unlikely(!d->tcfd_defdata))
return -ENOMEM; return -ENOMEM;
d->tcfd_datalen = datalen; d->tcfd_datalen = datalen;
memcpy(d->tcfd_defdata, defdata, datalen);
return 0; return 0;
} }
......
...@@ -217,7 +217,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -217,7 +217,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
/* Create new proto tcf */ /* Create new proto tcf */
err = -ENOBUFS; err = -ENOBUFS;
if ((tp = kmalloc(sizeof(*tp), GFP_KERNEL)) == NULL) if ((tp = kzalloc(sizeof(*tp), GFP_KERNEL)) == NULL)
goto errout; goto errout;
err = -EINVAL; err = -EINVAL;
tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND-1]); tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND-1]);
...@@ -247,7 +247,6 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg) ...@@ -247,7 +247,6 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
kfree(tp); kfree(tp);
goto errout; goto errout;
} }
memset(tp, 0, sizeof(*tp));
tp->ops = tp_ops; tp->ops = tp_ops;
tp->protocol = protocol; tp->protocol = protocol;
tp->prio = nprio ? : tcf_auto_prio(*back); tp->prio = nprio ? : tcf_auto_prio(*back);
......
...@@ -546,10 +546,9 @@ static int meta_var_change(struct meta_value *dst, struct rtattr *rta) ...@@ -546,10 +546,9 @@ static int meta_var_change(struct meta_value *dst, struct rtattr *rta)
{ {
int len = RTA_PAYLOAD(rta); int len = RTA_PAYLOAD(rta);
dst->val = (unsigned long) kmalloc(len, GFP_KERNEL); dst->val = (unsigned long)kmemdup(RTA_DATA(rta), len, GFP_KERNEL);
if (dst->val == 0UL) if (dst->val == 0UL)
return -ENOMEM; return -ENOMEM;
memcpy((void *) dst->val, RTA_DATA(rta), len);
dst->len = len; dst->len = len;
return 0; return 0;
} }
......
...@@ -34,12 +34,10 @@ static int em_nbyte_change(struct tcf_proto *tp, void *data, int data_len, ...@@ -34,12 +34,10 @@ static int em_nbyte_change(struct tcf_proto *tp, void *data, int data_len,
return -EINVAL; return -EINVAL;
em->datalen = sizeof(*nbyte) + nbyte->len; em->datalen = sizeof(*nbyte) + nbyte->len;
em->data = (unsigned long) kmalloc(em->datalen, GFP_KERNEL); em->data = (unsigned long)kmemdup(data, em->datalen, GFP_KERNEL);
if (em->data == 0UL) if (em->data == 0UL)
return -ENOBUFS; return -ENOBUFS;
memcpy((void *) em->data, data, em->datalen);
return 0; return 0;
} }
......
...@@ -251,12 +251,11 @@ static int tcf_em_validate(struct tcf_proto *tp, ...@@ -251,12 +251,11 @@ static int tcf_em_validate(struct tcf_proto *tp,
goto errout; goto errout;
em->data = *(u32 *) data; em->data = *(u32 *) data;
} else { } else {
void *v = kmalloc(data_len, GFP_KERNEL); void *v = kmemdup(data, data_len, GFP_KERNEL);
if (v == NULL) { if (v == NULL) {
err = -ENOBUFS; err = -ENOBUFS;
goto errout; goto errout;
} }
memcpy(v, data, data_len);
em->data = (unsigned long) v; em->data = (unsigned long) v;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment