mirror of
https://github.com/torvalds/linux.git
synced 2024-12-04 18:13:04 +00:00
wimax: use genl_register_family_with_ops()
This simplifies the code since there's no longer a need to have error handling in the registration. Unfortunately it means more extern function declarations are needed, but the overall goal would seem to justify this. Due to the removal of duplication in the netlink policies, this reduces the size of wimax by almost 1k. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
1c582d915d
commit
b61a5eea59
@ -321,17 +321,6 @@ int wimax_msg(struct wimax_dev *wimax_dev, const char *pipe_name,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(wimax_msg);
|
EXPORT_SYMBOL_GPL(wimax_msg);
|
||||||
|
|
||||||
|
|
||||||
static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
|
|
||||||
[WIMAX_GNL_MSG_IFIDX] = {
|
|
||||||
.type = NLA_U32,
|
|
||||||
},
|
|
||||||
[WIMAX_GNL_MSG_DATA] = {
|
|
||||||
.type = NLA_UNSPEC, /* libnl doesn't grok BINARY yet */
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Relays a message from user space to the driver
|
* Relays a message from user space to the driver
|
||||||
*
|
*
|
||||||
@ -340,7 +329,6 @@ static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
|
|||||||
*
|
*
|
||||||
* This call will block while handling/relaying the message.
|
* This call will block while handling/relaying the message.
|
||||||
*/
|
*/
|
||||||
static
|
|
||||||
int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
|
int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
int result, ifindex;
|
int result, ifindex;
|
||||||
@ -418,16 +406,3 @@ error_no_wimax_dev:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Generic Netlink glue
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct genl_ops wimax_gnl_msg_from_user = {
|
|
||||||
.cmd = WIMAX_GNL_OP_MSG_FROM_USER,
|
|
||||||
.flags = GENL_ADMIN_PERM,
|
|
||||||
.policy = wimax_gnl_msg_policy,
|
|
||||||
.doit = wimax_gnl_doit_msg_from_user,
|
|
||||||
.dumpit = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
@ -92,13 +92,6 @@ int wimax_reset(struct wimax_dev *wimax_dev)
|
|||||||
EXPORT_SYMBOL(wimax_reset);
|
EXPORT_SYMBOL(wimax_reset);
|
||||||
|
|
||||||
|
|
||||||
static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] = {
|
|
||||||
[WIMAX_GNL_RESET_IFIDX] = {
|
|
||||||
.type = NLA_U32,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exporting to user space over generic netlink
|
* Exporting to user space over generic netlink
|
||||||
*
|
*
|
||||||
@ -106,7 +99,6 @@ static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] =
|
|||||||
*
|
*
|
||||||
* No attributes.
|
* No attributes.
|
||||||
*/
|
*/
|
||||||
static
|
|
||||||
int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
|
int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
int result, ifindex;
|
int result, ifindex;
|
||||||
@ -130,12 +122,3 @@ error_no_wimax_dev:
|
|||||||
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
|
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct genl_ops wimax_gnl_reset = {
|
|
||||||
.cmd = WIMAX_GNL_OP_RESET,
|
|
||||||
.flags = GENL_ADMIN_PERM,
|
|
||||||
.policy = wimax_gnl_reset_policy,
|
|
||||||
.doit = wimax_gnl_doit_reset,
|
|
||||||
.dumpit = NULL,
|
|
||||||
};
|
|
||||||
|
@ -411,17 +411,6 @@ void wimax_rfkill_rm(struct wimax_dev *wimax_dev)
|
|||||||
* just query).
|
* just query).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const struct nla_policy wimax_gnl_rfkill_policy[WIMAX_GNL_ATTR_MAX + 1] = {
|
|
||||||
[WIMAX_GNL_RFKILL_IFIDX] = {
|
|
||||||
.type = NLA_U32,
|
|
||||||
},
|
|
||||||
[WIMAX_GNL_RFKILL_STATE] = {
|
|
||||||
.type = NLA_U32 /* enum wimax_rf_state */
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static
|
|
||||||
int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
|
int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
int result, ifindex;
|
int result, ifindex;
|
||||||
@ -457,13 +446,3 @@ error_no_wimax_dev:
|
|||||||
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
|
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct genl_ops wimax_gnl_rfkill = {
|
|
||||||
.cmd = WIMAX_GNL_OP_RFKILL,
|
|
||||||
.flags = GENL_ADMIN_PERM,
|
|
||||||
.policy = wimax_gnl_rfkill_policy,
|
|
||||||
.doit = wimax_gnl_doit_rfkill,
|
|
||||||
.dumpit = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
@ -33,13 +33,6 @@
|
|||||||
#include "debug-levels.h"
|
#include "debug-levels.h"
|
||||||
|
|
||||||
|
|
||||||
static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1] = {
|
|
||||||
[WIMAX_GNL_STGET_IFIDX] = {
|
|
||||||
.type = NLA_U32,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exporting to user space over generic netlink
|
* Exporting to user space over generic netlink
|
||||||
*
|
*
|
||||||
@ -48,7 +41,6 @@ static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1
|
|||||||
*
|
*
|
||||||
* No attributes.
|
* No attributes.
|
||||||
*/
|
*/
|
||||||
static
|
|
||||||
int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
|
int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
|
||||||
{
|
{
|
||||||
int result, ifindex;
|
int result, ifindex;
|
||||||
@ -72,12 +64,3 @@ error_no_wimax_dev:
|
|||||||
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
|
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct genl_ops wimax_gnl_state_get = {
|
|
||||||
.cmd = WIMAX_GNL_OP_STATE_GET,
|
|
||||||
.flags = GENL_ADMIN_PERM,
|
|
||||||
.policy = wimax_gnl_state_get_policy,
|
|
||||||
.doit = wimax_gnl_doit_state_get,
|
|
||||||
.dumpit = NULL,
|
|
||||||
};
|
|
||||||
|
@ -402,22 +402,44 @@ void wimax_dev_init(struct wimax_dev *wimax_dev)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(wimax_dev_init);
|
EXPORT_SYMBOL_GPL(wimax_dev_init);
|
||||||
|
|
||||||
/*
|
static const struct nla_policy wimax_gnl_policy[WIMAX_GNL_ATTR_MAX + 1] = {
|
||||||
* This extern is declared here because it's easier to keep track --
|
[WIMAX_GNL_RESET_IFIDX] = { .type = NLA_U32, },
|
||||||
* both declarations are a list of the same
|
[WIMAX_GNL_RFKILL_IFIDX] = { .type = NLA_U32, },
|
||||||
*/
|
[WIMAX_GNL_RFKILL_STATE] = {
|
||||||
extern struct genl_ops
|
.type = NLA_U32 /* enum wimax_rf_state */
|
||||||
wimax_gnl_msg_from_user,
|
},
|
||||||
wimax_gnl_reset,
|
[WIMAX_GNL_STGET_IFIDX] = { .type = NLA_U32, },
|
||||||
wimax_gnl_rfkill,
|
[WIMAX_GNL_MSG_IFIDX] = { .type = NLA_U32, },
|
||||||
wimax_gnl_state_get;
|
[WIMAX_GNL_MSG_DATA] = {
|
||||||
|
.type = NLA_UNSPEC, /* libnl doesn't grok BINARY yet */
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
static
|
static struct genl_ops wimax_gnl_ops[] = {
|
||||||
struct genl_ops *wimax_gnl_ops[] = {
|
{
|
||||||
&wimax_gnl_msg_from_user,
|
.cmd = WIMAX_GNL_OP_MSG_FROM_USER,
|
||||||
&wimax_gnl_reset,
|
.flags = GENL_ADMIN_PERM,
|
||||||
&wimax_gnl_rfkill,
|
.policy = wimax_gnl_policy,
|
||||||
&wimax_gnl_state_get,
|
.doit = wimax_gnl_doit_msg_from_user,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.cmd = WIMAX_GNL_OP_RESET,
|
||||||
|
.flags = GENL_ADMIN_PERM,
|
||||||
|
.policy = wimax_gnl_policy,
|
||||||
|
.doit = wimax_gnl_doit_reset,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.cmd = WIMAX_GNL_OP_RFKILL,
|
||||||
|
.flags = GENL_ADMIN_PERM,
|
||||||
|
.policy = wimax_gnl_policy,
|
||||||
|
.doit = wimax_gnl_doit_rfkill,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.cmd = WIMAX_GNL_OP_STATE_GET,
|
||||||
|
.flags = GENL_ADMIN_PERM,
|
||||||
|
.policy = wimax_gnl_policy,
|
||||||
|
.doit = wimax_gnl_doit_state_get,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -567,7 +589,7 @@ struct genl_multicast_group wimax_gnl_mcg = {
|
|||||||
static
|
static
|
||||||
int __init wimax_subsys_init(void)
|
int __init wimax_subsys_init(void)
|
||||||
{
|
{
|
||||||
int result, cnt;
|
int result;
|
||||||
|
|
||||||
d_fnstart(4, NULL, "()\n");
|
d_fnstart(4, NULL, "()\n");
|
||||||
d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params,
|
d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params,
|
||||||
@ -575,26 +597,14 @@ int __init wimax_subsys_init(void)
|
|||||||
|
|
||||||
snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
|
snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
|
||||||
"WiMAX");
|
"WiMAX");
|
||||||
result = genl_register_family(&wimax_gnl_family);
|
result = genl_register_family_with_ops(&wimax_gnl_family, wimax_gnl_ops,
|
||||||
|
ARRAY_SIZE(wimax_gnl_ops));
|
||||||
if (unlikely(result < 0)) {
|
if (unlikely(result < 0)) {
|
||||||
printk(KERN_ERR "cannot register generic netlink family: %d\n",
|
printk(KERN_ERR "cannot register generic netlink family: %d\n",
|
||||||
result);
|
result);
|
||||||
goto error_register_family;
|
goto error_register_family;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cnt = 0; cnt < ARRAY_SIZE(wimax_gnl_ops); cnt++) {
|
|
||||||
result = genl_register_ops(&wimax_gnl_family,
|
|
||||||
wimax_gnl_ops[cnt]);
|
|
||||||
d_printf(4, NULL, "registering generic netlink op code "
|
|
||||||
"%u: %d\n", wimax_gnl_ops[cnt]->cmd, result);
|
|
||||||
if (unlikely(result < 0)) {
|
|
||||||
printk(KERN_ERR "cannot register generic netlink op "
|
|
||||||
"code %u: %d\n",
|
|
||||||
wimax_gnl_ops[cnt]->cmd, result);
|
|
||||||
goto error_register_ops;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = genl_register_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
|
result = genl_register_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
goto error_mc_group;
|
goto error_mc_group;
|
||||||
@ -602,10 +612,6 @@ int __init wimax_subsys_init(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_mc_group:
|
error_mc_group:
|
||||||
error_register_ops:
|
|
||||||
for (cnt--; cnt >= 0; cnt--)
|
|
||||||
genl_unregister_ops(&wimax_gnl_family,
|
|
||||||
wimax_gnl_ops[cnt]);
|
|
||||||
genl_unregister_family(&wimax_gnl_family);
|
genl_unregister_family(&wimax_gnl_family);
|
||||||
error_register_family:
|
error_register_family:
|
||||||
d_fnend(4, NULL, "() = %d\n", result);
|
d_fnend(4, NULL, "() = %d\n", result);
|
||||||
@ -619,12 +625,7 @@ module_init(wimax_subsys_init);
|
|||||||
static
|
static
|
||||||
void __exit wimax_subsys_exit(void)
|
void __exit wimax_subsys_exit(void)
|
||||||
{
|
{
|
||||||
int cnt;
|
|
||||||
wimax_id_table_release();
|
wimax_id_table_release();
|
||||||
genl_unregister_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
|
|
||||||
for (cnt = ARRAY_SIZE(wimax_gnl_ops) - 1; cnt >= 0; cnt--)
|
|
||||||
genl_unregister_ops(&wimax_gnl_family,
|
|
||||||
wimax_gnl_ops[cnt]);
|
|
||||||
genl_unregister_family(&wimax_gnl_family);
|
genl_unregister_family(&wimax_gnl_family);
|
||||||
}
|
}
|
||||||
module_exit(wimax_subsys_exit);
|
module_exit(wimax_subsys_exit);
|
||||||
|
@ -84,8 +84,15 @@ void wimax_id_table_release(void);
|
|||||||
int wimax_rfkill_add(struct wimax_dev *);
|
int wimax_rfkill_add(struct wimax_dev *);
|
||||||
void wimax_rfkill_rm(struct wimax_dev *);
|
void wimax_rfkill_rm(struct wimax_dev *);
|
||||||
|
|
||||||
|
/* generic netlink */
|
||||||
extern struct genl_family wimax_gnl_family;
|
extern struct genl_family wimax_gnl_family;
|
||||||
extern struct genl_multicast_group wimax_gnl_mcg;
|
extern struct genl_multicast_group wimax_gnl_mcg;
|
||||||
|
|
||||||
|
/* ops */
|
||||||
|
int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info);
|
||||||
|
|
||||||
#endif /* #ifdef __KERNEL__ */
|
#endif /* #ifdef __KERNEL__ */
|
||||||
#endif /* #ifndef __WIMAX_INTERNAL_H__ */
|
#endif /* #ifndef __WIMAX_INTERNAL_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user