net: Use non-zero allocations in dst_alloc().
Subsystems (4)
David Miller
maintainerRFC PATCH v4 6/8 net: Use non-zero allocations in dst_alloc().
Make dst_alloc() and it's users explicitly initialize the entire entry.
The zero'ing done by kmem_cache_zalloc() was almost entirely redundant.
Signed-off-by David S. Miller <[email protected]>
--- net/core/dst.c | 20 ++++++++++-- net/decnet/dn_route.c | 2 + net/ipv4/route.c | 81 ++++++++++++++++++++++++++++-------------------- net/ipv6/route.c | 8 ++++- net/xfrm/xfrm_policy.c | 1 + 5 files changed, 74 insertions(+), 38 deletions(-)
net/core/dst.c +17 -3
@@ -175,22 +175,36 @@ void *dst_alloc(struct dst_ops *ops, struct net_device *dev,if (ops->gc (ops))return NULL ; } - dst =kmem_cache_zalloc (ops->kmem_cachep,GFP_ATOMIC ); + dst =kmem_cache_alloc (ops->kmem_cachep,GFP_ATOMIC );if (!dst)return NULL ; - dst->ops = ops; + dst->child =NULL ; dst->dev = dev;if (dev)dev_hold (dev); + dst->ops = ops;dst_init_metrics (dst, dst_default_metrics, true); + dst->expires =0UL ; dst->path = dst; + dst->neighbour =NULL ; + dst->hh =NULL ; +#ifdef CONFIG_XFRM + dst->xfrm =NULL ; +#endif dst->input = dst_discard; dst->output = dst_discard; - + dst->error =0 ; dst->obsolete = initial_obsolete; + dst->header_len =0 ; + dst->trailer_len =0 ; +#ifdef CONFIG_IP_ROUTE_CLASSID + dst->tclassid =0 ; +#endif atomic_set (&dst->__refcnt, initial_ref); + dst->__use =0 ; dst->lastuse = jiffies; dst->flags = flags; + dst->next =NULL ;#if RT_CACHE_DEBUG >=2 atomic_inc (&dst_total);#endif
net/decnet/dn_route.c +2 -0
@@ -1129,6 +1129,7 @@ make_route:if (rt ==NULL ) goto e_nobufs; +memset (&rt->fld,0 ,sizeof (rt->fld)); rt->fld.saddr = oldflp->saddr; rt->fld.daddr = oldflp->daddr; rt->fld.flowidn_oif = oldflp->flowidn_oif;
@@ -1398,6 +1399,7 @@ make_route:if (rt ==NULL ) goto e_nobufs; +memset (&rt->fld,0 ,sizeof (rt->fld)); rt->rt_saddr = fld.saddr; rt->rt_daddr = fld.daddr; rt->rt_gateway = fld.daddr;
net/ipv4/route.c +47 -34
157 lines not on this page · raw message
net/ipv6/route.c +7 -1
@@ -223,7 +223,11 @@ static struct rt6_info ip6_blk_hole_entry_template = {static inline struct rt6_info *ip6_dst_alloc (struct dst_ops *ops,struct net_device *dev) { -return (struct rt6_info *)dst_alloc (ops, dev,0 ,0 ,0 ); +struct rt6_info *rt =dst_alloc (ops, dev,0 ,0 ,0 ); + +memset (&rt->rt6i_table,0 ,sizeof (*rt) -sizeof (struct dst_entry )); + +return rt; }static void ip6_dst_destroy (struct dst_entry *dst)
@@ -880,6 +884,8 @@ struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *dst_ori rt =dst_alloc (&ip6_dst_blackhole_ops, ort->dst.dev,1 ,0 ,0 );if (rt) { +memset (&rt->rt6i_table,0 ,sizeof (*rt) -sizeof (struct dst_entry )); + new = &rt->dst; new->__use =1 ;
net/xfrm/xfrm_policy.c +1 -0
@@ -1349,6 +1349,7 @@ static inline struct xfrm_dst *xfrm_alloc_dst(struct net *net, int family)BUG (); } xdst =dst_alloc (dst_ops,NULL ,0 ,0 ,0 ); +memset (&xdst->u.rt6.rt6i_table,0 ,sizeof (*xdst) -sizeof (struct dst_entry ));xfrm_policy_put_afinfo (afinfo);if (likely (xdst))
Signature · 1 line
1.7.4.1