Skip to content

Commit

Permalink
genetlink: only pass array to genl_register_family_with_ops()
Browse files Browse the repository at this point in the history
As suggested by David Miller, make genl_register_family_with_ops()
a macro and pass only the array, evaluating ARRAY_SIZE() in the
macro, this is a little safer.

The openvswitch has some indirection, assing ops/n_ops directly in
that code. This might ultimately just assign the pointers in the
family initializations, saving the struct genl_family_and_ops and
code (once mcast groups are handled differently.)

Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jmberg-intel authored and davem330 committed Nov 19, 2013
1 parent dbde497 commit c53ed74
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 53 deletions.
3 changes: 1 addition & 2 deletions drivers/net/team/team.c
Original file line number Diff line number Diff line change
Expand Up @@ -2699,8 +2699,7 @@ static int team_nl_init(void)
{
int err;

err = genl_register_family_with_ops(&team_nl_family, team_nl_ops,
ARRAY_SIZE(team_nl_ops));
err = genl_register_family_with_ops(&team_nl_family, team_nl_ops);
if (err)
return err;

Expand Down
3 changes: 1 addition & 2 deletions drivers/net/wireless/mac80211_hwsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -2148,8 +2148,7 @@ static int hwsim_init_netlink(void)

printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");

rc = genl_register_family_with_ops(&hwsim_genl_family,
hwsim_ops, ARRAY_SIZE(hwsim_ops));
rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops);
if (rc)
goto failure;

Expand Down
10 changes: 6 additions & 4 deletions fs/dlm/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ static int user_cmd(struct sk_buff *skb, struct genl_info *info)
return 0;
}

static struct genl_ops dlm_nl_ops = {
.cmd = DLM_CMD_HELLO,
.doit = user_cmd,
static struct genl_ops dlm_nl_ops[] = {
{
.cmd = DLM_CMD_HELLO,
.doit = user_cmd,
},
};

int __init dlm_netlink_init(void)
{
return genl_register_family_with_ops(&family, &dlm_nl_ops, 1);
return genl_register_family_with_ops(&family, dlm_nl_ops);
}

void dlm_netlink_exit(void)
Expand Down
3 changes: 1 addition & 2 deletions include/linux/genl_magic_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \

int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
{
int err = genl_register_family_with_ops(&ZZZ_genl_family,
ZZZ_genl_ops, ARRAY_SIZE(ZZZ_genl_ops));
int err = genl_register_family_with_ops(&ZZZ_genl_family, ZZZ_genl_ops);
if (err)
return err;
#undef GENL_mc_group
Expand Down
8 changes: 6 additions & 2 deletions include/net/genetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,19 @@ static inline int genl_register_family(struct genl_family *family)
*
* Return 0 on success or a negative error code.
*/
static inline int genl_register_family_with_ops(struct genl_family *family,
const struct genl_ops *ops, size_t n_ops)
static inline int _genl_register_family_with_ops(struct genl_family *family,
const struct genl_ops *ops,
size_t n_ops)
{
family->module = THIS_MODULE;
family->ops = ops;
family->n_ops = n_ops;
return __genl_register_family(family);
}

#define genl_register_family_with_ops(family, ops) \
_genl_register_family_with_ops((family), (ops), ARRAY_SIZE(ops))

int genl_unregister_family(struct genl_family *family);
int genl_register_mc_group(struct genl_family *family,
struct genl_multicast_group *grp);
Expand Down
3 changes: 1 addition & 2 deletions kernel/taskstats.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,7 @@ static int __init taskstats_init(void)
{
int rc;

rc = genl_register_family_with_ops(&family, taskstats_ops,
ARRAY_SIZE(taskstats_ops));
rc = genl_register_family_with_ops(&family, taskstats_ops);
if (rc)
return rc;

Expand Down
3 changes: 1 addition & 2 deletions net/core/drop_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ static int __init init_net_drop_monitor(void)
}

rc = genl_register_family_with_ops(&net_drop_monitor_family,
dropmon_ops,
ARRAY_SIZE(dropmon_ops));
dropmon_ops);
if (rc) {
pr_err("Could not create drop monitor netlink family\n");
return rc;
Expand Down
3 changes: 1 addition & 2 deletions net/hsr/hsr_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ int __init hsr_netlink_init(void)
if (rc)
goto fail_rtnl_link_register;

rc = genl_register_family_with_ops(&hsr_genl_family, hsr_ops,
ARRAY_SIZE(hsr_ops));
rc = genl_register_family_with_ops(&hsr_genl_family, hsr_ops);
if (rc)
goto fail_genl_register_family;

Expand Down
3 changes: 1 addition & 2 deletions net/ieee802154/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ int __init ieee802154_nl_init(void)
{
int rc;

rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops,
ARRAY_SIZE(ieee8021154_ops));
rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops);
if (rc)
return rc;

Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/tcp_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,7 @@ void __init tcp_metrics_init(void)
if (ret < 0)
goto cleanup;
ret = genl_register_family_with_ops(&tcp_metrics_nl_family,
tcp_metrics_nl_ops,
ARRAY_SIZE(tcp_metrics_nl_ops));
tcp_metrics_nl_ops);
if (ret < 0)
goto cleanup_subsys;
return;
Expand Down
3 changes: 1 addition & 2 deletions net/irda/irnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ static const struct genl_ops irda_nl_ops[] = {

int irda_nl_register(void)
{
return genl_register_family_with_ops(&irda_nl_family,
irda_nl_ops, ARRAY_SIZE(irda_nl_ops));
return genl_register_family_with_ops(&irda_nl_family, irda_nl_ops);
}

void irda_nl_unregister(void)
Expand Down
7 changes: 1 addition & 6 deletions net/l2tp/l2tp_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,8 @@ EXPORT_SYMBOL_GPL(l2tp_nl_unregister_ops);

static int l2tp_nl_init(void)
{
int err;

pr_info("L2TP netlink interface\n");
err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops,
ARRAY_SIZE(l2tp_nl_ops));

return err;
return genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops);
}

static void l2tp_nl_cleanup(void)
Expand Down
2 changes: 1 addition & 1 deletion net/netfilter/ipvs/ip_vs_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3666,7 +3666,7 @@ static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
static int __init ip_vs_genl_register(void)
{
return genl_register_family_with_ops(&ip_vs_genl_family,
ip_vs_genl_ops, ARRAY_SIZE(ip_vs_genl_ops));
ip_vs_genl_ops);
}

static void ip_vs_genl_unregister(void)
Expand Down
2 changes: 1 addition & 1 deletion net/netlabel/netlabel_cipso_v4.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,5 +783,5 @@ static const struct genl_ops netlbl_cipsov4_ops[] = {
int __init netlbl_cipsov4_genl_init(void)
{
return genl_register_family_with_ops(&netlbl_cipsov4_gnl_family,
netlbl_cipsov4_ops, ARRAY_SIZE(netlbl_cipsov4_ops));
netlbl_cipsov4_ops);
}
2 changes: 1 addition & 1 deletion net/netlabel/netlabel_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,5 +779,5 @@ static const struct genl_ops netlbl_mgmt_genl_ops[] = {
int __init netlbl_mgmt_genl_init(void)
{
return genl_register_family_with_ops(&netlbl_mgmt_gnl_family,
netlbl_mgmt_genl_ops, ARRAY_SIZE(netlbl_mgmt_genl_ops));
netlbl_mgmt_genl_ops);
}
2 changes: 1 addition & 1 deletion net/netlabel/netlabel_unlabeled.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ static const struct genl_ops netlbl_unlabel_genl_ops[] = {
int __init netlbl_unlabel_genl_init(void)
{
return genl_register_family_with_ops(&netlbl_unlabel_gnl_family,
netlbl_unlabel_genl_ops, ARRAY_SIZE(netlbl_unlabel_genl_ops));
netlbl_unlabel_genl_ops);
}

/*
Expand Down
14 changes: 8 additions & 6 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,13 @@ static int genl_ctrl_event(int event, void *data)
return 0;
}

static struct genl_ops genl_ctrl_ops = {
.cmd = CTRL_CMD_GETFAMILY,
.doit = ctrl_getfamily,
.dumpit = ctrl_dumpfamily,
.policy = ctrl_policy,
static struct genl_ops genl_ctrl_ops[] = {
{
.cmd = CTRL_CMD_GETFAMILY,
.doit = ctrl_getfamily,
.dumpit = ctrl_dumpfamily,
.policy = ctrl_policy,
},
};

static struct genl_multicast_group notify_grp = {
Expand Down Expand Up @@ -954,7 +956,7 @@ static int __init genl_init(void)
for (i = 0; i < GENL_FAM_TAB_SIZE; i++)
INIT_LIST_HEAD(&family_ht[i]);

err = genl_register_family_with_ops(&genl_ctrl, &genl_ctrl_ops, 1);
err = genl_register_family_with_ops(&genl_ctrl, genl_ctrl_ops);
if (err < 0)
goto problem;

Expand Down
3 changes: 1 addition & 2 deletions net/nfc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1536,8 +1536,7 @@ int __init nfc_genl_init(void)
{
int rc;

rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops,
ARRAY_SIZE(nfc_genl_ops));
rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops);
if (rc)
return rc;

Expand Down
5 changes: 3 additions & 2 deletions net/openvswitch/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,9 @@ static int dp_register_genl(void)
for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) {
const struct genl_family_and_ops *f = &dp_genl_families[i];

err = genl_register_family_with_ops(f->family, f->ops,
f->n_ops);
f->family->ops = f->ops;
f->family->n_ops = f->n_ops;
err = genl_register_family(f->family);
if (err)
goto error;
n_registered++;
Expand Down
11 changes: 6 additions & 5 deletions net/tipc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ static struct genl_family tipc_genl_family = {
.maxattr = 0,
};

static struct genl_ops tipc_genl_ops = {
.cmd = TIPC_GENL_CMD,
.doit = handle_cmd,
static struct genl_ops tipc_genl_ops[] = {
{
.cmd = TIPC_GENL_CMD,
.doit = handle_cmd,
},
};

static int tipc_genl_family_registered;
Expand All @@ -87,8 +89,7 @@ int tipc_netlink_start(void)
{
int res;

res = genl_register_family_with_ops(&tipc_genl_family,
&tipc_genl_ops, 1);
res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops);
if (res) {
pr_err("Failed to register netlink interface\n");
return res;
Expand Down
4 changes: 2 additions & 2 deletions net/wimax/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ int __init wimax_subsys_init(void)

snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
"WiMAX");
result = genl_register_family_with_ops(&wimax_gnl_family, wimax_gnl_ops,
ARRAY_SIZE(wimax_gnl_ops));
result = genl_register_family_with_ops(&wimax_gnl_family,
wimax_gnl_ops);
if (unlikely(result < 0)) {
printk(KERN_ERR "cannot register generic netlink family: %d\n",
result);
Expand Down
3 changes: 1 addition & 2 deletions net/wireless/nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -11329,8 +11329,7 @@ int nl80211_init(void)
{
int err;

err = genl_register_family_with_ops(&nl80211_fam,
nl80211_ops, ARRAY_SIZE(nl80211_ops));
err = genl_register_family_with_ops(&nl80211_fam, nl80211_ops);
if (err)
return err;

Expand Down

0 comments on commit c53ed74

Please sign in to comment.