mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 10:41:38 -04:00
[INET]: Consolidate xxx_frag_alloc()
Just perform the kzalloc() allocation and setup common fields in the inet_frag_queue(). Then return the result to the caller to initialize the rest. The inet_frag_alloc() may return NULL, so check the return value before doing the container_of(). This looks ugly, but the xxx_frag_alloc() will be removed soon. The xxx_expire() timer callbacks are patches, because the argument is now the inet_frag_queue, not the protocol specific queue. Signed-off-by: Pavel Emelyanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
parent
2588fe1d78
commit
e521db9d79
5 changed files with 41 additions and 36 deletions
|
|
@ -209,3 +209,20 @@ struct inet_frag_queue *inet_frag_intern(struct inet_frag_queue *qp_in,
|
|||
return qp;
|
||||
}
|
||||
EXPORT_SYMBOL(inet_frag_intern);
|
||||
|
||||
struct inet_frag_queue *inet_frag_alloc(struct inet_frags *f)
|
||||
{
|
||||
struct inet_frag_queue *q;
|
||||
|
||||
q = kzalloc(f->qsize, GFP_ATOMIC);
|
||||
if (q == NULL)
|
||||
return NULL;
|
||||
|
||||
atomic_add(f->qsize, &f->mem);
|
||||
setup_timer(&q->timer, f->frag_expire, (unsigned long)q);
|
||||
spin_lock_init(&q->lock);
|
||||
atomic_set(&q->refcnt, 1);
|
||||
|
||||
return q;
|
||||
}
|
||||
EXPORT_SYMBOL(inet_frag_alloc);
|
||||
|
|
|
|||
|
|
@ -158,12 +158,10 @@ static __inline__ void ip4_frag_free(struct inet_frag_queue *q)
|
|||
|
||||
static __inline__ struct ipq *frag_alloc_queue(void)
|
||||
{
|
||||
struct ipq *qp = kzalloc(sizeof(struct ipq), GFP_ATOMIC);
|
||||
struct inet_frag_queue *q;
|
||||
|
||||
if (!qp)
|
||||
return NULL;
|
||||
atomic_add(sizeof(struct ipq), &ip4_frags.mem);
|
||||
return qp;
|
||||
q = inet_frag_alloc(&ip4_frags);
|
||||
return q ? container_of(q, struct ipq, q) : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -199,7 +197,9 @@ static void ip_evictor(void)
|
|||
*/
|
||||
static void ip_expire(unsigned long arg)
|
||||
{
|
||||
struct ipq *qp = (struct ipq *) arg;
|
||||
struct ipq *qp;
|
||||
|
||||
qp = container_of((struct inet_frag_queue *) arg, struct ipq, q);
|
||||
|
||||
spin_lock(&qp->q.lock);
|
||||
|
||||
|
|
@ -249,13 +249,6 @@ static struct ipq *ip_frag_create(struct iphdr *iph, u32 user, unsigned int h)
|
|||
qp->user = user;
|
||||
qp->peer = sysctl_ipfrag_max_dist ? inet_getpeer(iph->saddr, 1) : NULL;
|
||||
|
||||
/* Initialize a timer for this entry. */
|
||||
init_timer(&qp->q.timer);
|
||||
qp->q.timer.data = (unsigned long) qp; /* pointer to queue */
|
||||
qp->q.timer.function = ip_expire; /* expire function */
|
||||
spin_lock_init(&qp->q.lock);
|
||||
atomic_set(&qp->q.refcnt, 1);
|
||||
|
||||
return ip_frag_intern(qp, h);
|
||||
|
||||
out_nomem:
|
||||
|
|
@ -653,6 +646,7 @@ void __init ipfrag_init(void)
|
|||
ip4_frags.skb_free = NULL;
|
||||
ip4_frags.qsize = sizeof(struct ipq);
|
||||
ip4_frags.equal = ip4_frag_equal;
|
||||
ip4_frags.frag_expire = ip_expire;
|
||||
inet_frags_init(&ip4_frags);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue