[SCHED]: Use kmemdup & kzalloc where appropriate
authorArnaldo Carvalho de Melo <acme@mandriva.com>
Tue, 21 Nov 2006 03:19:40 +0000 (01:19 -0200)
committerDavid S. Miller <davem@sunset.davemloft.net>
Sun, 3 Dec 2006 05:30:18 +0000 (21:30 -0800)
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
net/sched/act_ipt.c
net/sched/act_simple.c
net/sched/cls_api.c
net/sched/em_meta.c
net/sched/em_nbyte.c
net/sched/ematch.c

index d8c9310da6e5676ab70e9201878c5cef14a559ec..a9608064a4c303cb884b0fc6913d1f68e2fd33ee 100644 (file)
@@ -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)
                strcpy(tname, "mangle");
 
-       t = kmalloc(td->u.target_size, GFP_KERNEL);
+       t = kmemdup(td, td->u.target_size, GFP_KERNEL);
        if (unlikely(!t))
                goto err2;
-       memcpy(t, td, td->u.target_size);
 
        if ((err = ipt_init_target(t, tname, hook)) < 0)
                goto err3;
@@ -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
        */
 
-       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))
                goto rtattr_failure;
 
        c.bindcnt = ipt->tcf_bindcnt - bind;
        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);
 
        RTA_PUT(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t);
index 901571a677072c8480b270df13f7d01c173a070c..5fe80854ca91cdf58d766c66ce1c8fccb8d882a2 100644 (file)
@@ -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)
 {
-       d->tcfd_defdata = kmalloc(datalen, GFP_KERNEL);
+       d->tcfd_defdata = kmemdup(defdata, datalen, GFP_KERNEL);
        if (unlikely(!d->tcfd_defdata))
                return -ENOMEM;
        d->tcfd_datalen = datalen;
-       memcpy(d->tcfd_defdata, defdata, datalen);
        return 0;
 }
 
index 37a1840216474d77c2ad534903059bbeb1a840ea..edb8fc97ae11a183734f700aa06bbf84d758f78e 100644 (file)
@@ -217,7 +217,7 @@ replay:
                /* Create new proto tcf */
 
                err = -ENOBUFS;
-               if ((tp = kmalloc(sizeof(*tp), GFP_KERNEL)) == NULL)
+               if ((tp = kzalloc(sizeof(*tp), GFP_KERNEL)) == NULL)
                        goto errout;
                err = -EINVAL;
                tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND-1]);
@@ -247,7 +247,6 @@ replay:
                        kfree(tp);
                        goto errout;
                }
-               memset(tp, 0, sizeof(*tp));
                tp->ops = tp_ops;
                tp->protocol = protocol;
                tp->prio = nprio ? : tcf_auto_prio(*back);
index d3ff3503326aa8cc341ab74212fa5821e2a9bf41..45d47d37155ead9727f5543b22e43cd0b3f87958 100644 (file)
@@ -546,10 +546,9 @@ static int meta_var_change(struct meta_value *dst, struct rtattr *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)
                return -ENOMEM;
-       memcpy((void *) dst->val, RTA_DATA(rta), len);
        dst->len = len;
        return 0;
 }
index cc80babfd79ff6870cd4b982f446721b67da777f..005db409be645a45abfd82f7694602874bc5b3ba 100644 (file)
@@ -34,12 +34,10 @@ static int em_nbyte_change(struct tcf_proto *tp, void *data, int data_len,
                return -EINVAL;
 
        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)
                return -ENOBUFS;
 
-       memcpy((void *) em->data, data, em->datalen);
-
        return 0;
 }
 
index 0fd0768a17c6cc9ab5b627bbfd94bee9c03b9657..8f8a16da72a8970acb1c11357ec228573b85cad4 100644 (file)
@@ -251,12 +251,11 @@ static int tcf_em_validate(struct tcf_proto *tp,
                                        goto errout;
                                em->data = *(u32 *) data;
                        } else {
-                               void *v = kmalloc(data_len, GFP_KERNEL);
+                               void *v = kmemdup(data, data_len, GFP_KERNEL);
                                if (v == NULL) {
                                        err = -ENOBUFS;
                                        goto errout;
                                }
-                               memcpy(v, data, data_len);
                                em->data = (unsigned long) v;
                        }
                }