mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 00:21:17 +00:00
sock_diag: Simplify sock_diag_handlers[] handling in __sock_diag_rcv_msg
The sock_diag_lock_handler() and sock_diag_unlock_handler() actually make the code less readable. Get rid of them and make the lock usage and access to sock_diag_handlers[] clear on the first sight. Signed-off-by: Mathias Krause <minipli@googlemail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
6e601a5356
commit
8e904550d0
1 changed files with 7 additions and 17 deletions
|
@ -97,21 +97,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(sock_diag_unregister);
|
EXPORT_SYMBOL_GPL(sock_diag_unregister);
|
||||||
|
|
||||||
static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
|
|
||||||
{
|
|
||||||
if (sock_diag_handlers[family] == NULL)
|
|
||||||
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
|
|
||||||
NETLINK_SOCK_DIAG, family);
|
|
||||||
|
|
||||||
mutex_lock(&sock_diag_table_mutex);
|
|
||||||
return sock_diag_handlers[family];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
|
|
||||||
{
|
|
||||||
mutex_unlock(&sock_diag_table_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -124,12 +109,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
||||||
if (req->sdiag_family >= AF_MAX)
|
if (req->sdiag_family >= AF_MAX)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
hndl = sock_diag_lock_handler(req->sdiag_family);
|
if (sock_diag_handlers[req->sdiag_family] == NULL)
|
||||||
|
request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
|
||||||
|
NETLINK_SOCK_DIAG, req->sdiag_family);
|
||||||
|
|
||||||
|
mutex_lock(&sock_diag_table_mutex);
|
||||||
|
hndl = sock_diag_handlers[req->sdiag_family];
|
||||||
if (hndl == NULL)
|
if (hndl == NULL)
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
else
|
else
|
||||||
err = hndl->dump(skb, nlh);
|
err = hndl->dump(skb, nlh);
|
||||||
sock_diag_unlock_handler(hndl);
|
mutex_unlock(&sock_diag_table_mutex);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue