Commit 0cfad075 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[NETLINK]: Avoid pointer in netlink_run_queue

I was looking at Patrick's fix to inet_diag and it occured
to me that we're using a pointer argument to return values
unnecessarily in netlink_run_queue.  Changing it to return
the value will allow the compiler to generate better code
since the value won't have to be memory-backed.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 007e3936
...@@ -220,7 +220,7 @@ struct nl_info { ...@@ -220,7 +220,7 @@ struct nl_info {
u32 pid; u32 pid;
}; };
extern void netlink_run_queue(struct sock *sk, unsigned int *qlen, extern unsigned int netlink_run_queue(struct sock *sk, unsigned int qlen,
int (*cb)(struct sk_buff *, int (*cb)(struct sk_buff *,
struct nlmsghdr *)); struct nlmsghdr *));
extern int nlmsg_notify(struct sock *sk, struct sk_buff *skb, extern int nlmsg_notify(struct sock *sk, struct sk_buff *skb,
......
...@@ -1320,7 +1320,7 @@ static void rtnetlink_rcv(struct sock *sk, int len) ...@@ -1320,7 +1320,7 @@ static void rtnetlink_rcv(struct sock *sk, int len)
do { do {
mutex_lock(&rtnl_mutex); mutex_lock(&rtnl_mutex);
netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg); qlen = netlink_run_queue(sk, qlen, &rtnetlink_rcv_msg);
mutex_unlock(&rtnl_mutex); mutex_unlock(&rtnl_mutex);
netdev_run_todo(); netdev_run_todo();
......
...@@ -845,7 +845,7 @@ static void inet_diag_rcv(struct sock *sk, int len) ...@@ -845,7 +845,7 @@ static void inet_diag_rcv(struct sock *sk, int len)
do { do {
mutex_lock(&inet_diag_mutex); mutex_lock(&inet_diag_mutex);
netlink_run_queue(sk, &qlen, &inet_diag_rcv_msg); qlen = netlink_run_queue(sk, qlen, &inet_diag_rcv_msg);
mutex_unlock(&inet_diag_mutex); mutex_unlock(&inet_diag_mutex);
} while (qlen); } while (qlen);
} }
......
...@@ -248,7 +248,7 @@ static void nfnetlink_rcv(struct sock *sk, int len) ...@@ -248,7 +248,7 @@ static void nfnetlink_rcv(struct sock *sk, int len)
do { do {
if (nfnl_trylock()) if (nfnl_trylock())
return; return;
netlink_run_queue(sk, &qlen, nfnetlink_rcv_msg); qlen = netlink_run_queue(sk, qlen, nfnetlink_rcv_msg);
__nfnl_unlock(); __nfnl_unlock();
} while (qlen); } while (qlen);
} }
......
...@@ -1629,7 +1629,7 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *, ...@@ -1629,7 +1629,7 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
/** /**
* nelink_run_queue - Process netlink receive queue. * nelink_run_queue - Process netlink receive queue.
* @sk: Netlink socket containing the queue * @sk: Netlink socket containing the queue
* @qlen: Place to store queue length upon entry * @qlen: Initial queue length
* @cb: Callback function invoked for each netlink message found * @cb: Callback function invoked for each netlink message found
* *
* Processes as much as there was in the queue upon entry and invokes * Processes as much as there was in the queue upon entry and invokes
...@@ -1639,35 +1639,37 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *, ...@@ -1639,35 +1639,37 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
* returns with a qlen != 0. * returns with a qlen != 0.
* *
* qlen must be initialized to 0 before the initial entry, afterwards * qlen must be initialized to 0 before the initial entry, afterwards
* the function may be called repeatedly until qlen reaches 0. * the function may be called repeatedly until the returned qlen is 0.
* *
* The callback function may return -EINTR to signal that processing * The callback function may return -EINTR to signal that processing
* of netlink messages shall be interrupted. In this case the message * of netlink messages shall be interrupted. In this case the message
* currently being processed will NOT be requeued onto the receive * currently being processed will NOT be requeued onto the receive
* queue. * queue.
*/ */
void netlink_run_queue(struct sock *sk, unsigned int *qlen, unsigned int netlink_run_queue(struct sock *sk, unsigned int qlen,
int (*cb)(struct sk_buff *, struct nlmsghdr *)) int (*cb)(struct sk_buff *, struct nlmsghdr *))
{ {
struct sk_buff *skb; struct sk_buff *skb;
if (!*qlen || *qlen > skb_queue_len(&sk->sk_receive_queue)) if (!qlen || qlen > skb_queue_len(&sk->sk_receive_queue))
*qlen = skb_queue_len(&sk->sk_receive_queue); qlen = skb_queue_len(&sk->sk_receive_queue);
for (; *qlen; (*qlen)--) { for (; qlen; qlen--) {
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
if (netlink_rcv_skb(skb, cb)) { if (netlink_rcv_skb(skb, cb)) {
if (skb->len) if (skb->len)
skb_queue_head(&sk->sk_receive_queue, skb); skb_queue_head(&sk->sk_receive_queue, skb);
else { else {
kfree_skb(skb); kfree_skb(skb);
(*qlen)--; qlen--;
} }
break; break;
} }
kfree_skb(skb); kfree_skb(skb);
} }
return qlen;
} }
/** /**
......
...@@ -485,7 +485,7 @@ static void genl_rcv(struct sock *sk, int len) ...@@ -485,7 +485,7 @@ static void genl_rcv(struct sock *sk, int len)
do { do {
if (genl_trylock()) if (genl_trylock())
return; return;
netlink_run_queue(sk, &qlen, genl_rcv_msg); qlen = netlink_run_queue(sk, qlen, genl_rcv_msg);
genl_unlock(); genl_unlock();
} while (qlen && genl_sock && genl_sock->sk_receive_queue.qlen); } while (qlen && genl_sock && genl_sock->sk_receive_queue.qlen);
} }
......
...@@ -1887,7 +1887,7 @@ static void xfrm_netlink_rcv(struct sock *sk, int len) ...@@ -1887,7 +1887,7 @@ static void xfrm_netlink_rcv(struct sock *sk, int len)
do { do {
mutex_lock(&xfrm_cfg_mutex); mutex_lock(&xfrm_cfg_mutex);
netlink_run_queue(sk, &qlen, &xfrm_user_rcv_msg); qlen = netlink_run_queue(sk, qlen, &xfrm_user_rcv_msg);
mutex_unlock(&xfrm_cfg_mutex); mutex_unlock(&xfrm_cfg_mutex);
} while (qlen); } while (qlen);
......
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