Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

genetlink: only pass array to genl_register_family_with_ops()

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 <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Johannes Berg and committed by
David S. Miller
c53ed742 dbde4979

+47 -53
+1 -2
drivers/net/team/team.c
··· 2699 2699 { 2700 2700 int err; 2701 2701 2702 - err = genl_register_family_with_ops(&team_nl_family, team_nl_ops, 2703 - ARRAY_SIZE(team_nl_ops)); 2702 + err = genl_register_family_with_ops(&team_nl_family, team_nl_ops); 2704 2703 if (err) 2705 2704 return err; 2706 2705
+1 -2
drivers/net/wireless/mac80211_hwsim.c
··· 2148 2148 2149 2149 printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); 2150 2150 2151 - rc = genl_register_family_with_ops(&hwsim_genl_family, 2152 - hwsim_ops, ARRAY_SIZE(hwsim_ops)); 2151 + rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops); 2153 2152 if (rc) 2154 2153 goto failure; 2155 2154
+6 -4
fs/dlm/netlink.c
··· 74 74 return 0; 75 75 } 76 76 77 - static struct genl_ops dlm_nl_ops = { 78 - .cmd = DLM_CMD_HELLO, 79 - .doit = user_cmd, 77 + static struct genl_ops dlm_nl_ops[] = { 78 + { 79 + .cmd = DLM_CMD_HELLO, 80 + .doit = user_cmd, 81 + }, 80 82 }; 81 83 82 84 int __init dlm_netlink_init(void) 83 85 { 84 - return genl_register_family_with_ops(&family, &dlm_nl_ops, 1); 86 + return genl_register_family_with_ops(&family, dlm_nl_ops); 85 87 } 86 88 87 89 void dlm_netlink_exit(void)
+1 -2
include/linux/genl_magic_func.h
··· 293 293 294 294 int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void) 295 295 { 296 - int err = genl_register_family_with_ops(&ZZZ_genl_family, 297 - ZZZ_genl_ops, ARRAY_SIZE(ZZZ_genl_ops)); 296 + int err = genl_register_family_with_ops(&ZZZ_genl_family, ZZZ_genl_ops); 298 297 if (err) 299 298 return err; 300 299 #undef GENL_mc_group
+6 -2
include/net/genetlink.h
··· 152 152 * 153 153 * Return 0 on success or a negative error code. 154 154 */ 155 - static inline int genl_register_family_with_ops(struct genl_family *family, 156 - const struct genl_ops *ops, size_t n_ops) 155 + static inline int _genl_register_family_with_ops(struct genl_family *family, 156 + const struct genl_ops *ops, 157 + size_t n_ops) 157 158 { 158 159 family->module = THIS_MODULE; 159 160 family->ops = ops; 160 161 family->n_ops = n_ops; 161 162 return __genl_register_family(family); 162 163 } 164 + 165 + #define genl_register_family_with_ops(family, ops) \ 166 + _genl_register_family_with_ops((family), (ops), ARRAY_SIZE(ops)) 163 167 164 168 int genl_unregister_family(struct genl_family *family); 165 169 int genl_register_mc_group(struct genl_family *family,
+1 -2
kernel/taskstats.c
··· 703 703 { 704 704 int rc; 705 705 706 - rc = genl_register_family_with_ops(&family, taskstats_ops, 707 - ARRAY_SIZE(taskstats_ops)); 706 + rc = genl_register_family_with_ops(&family, taskstats_ops); 708 707 if (rc) 709 708 return rc; 710 709
+1 -2
net/core/drop_monitor.c
··· 365 365 } 366 366 367 367 rc = genl_register_family_with_ops(&net_drop_monitor_family, 368 - dropmon_ops, 369 - ARRAY_SIZE(dropmon_ops)); 368 + dropmon_ops); 370 369 if (rc) { 371 370 pr_err("Could not create drop monitor netlink family\n"); 372 371 return rc;
+1 -2
net/hsr/hsr_netlink.c
··· 414 414 if (rc) 415 415 goto fail_rtnl_link_register; 416 416 417 - rc = genl_register_family_with_ops(&hsr_genl_family, hsr_ops, 418 - ARRAY_SIZE(hsr_ops)); 417 + rc = genl_register_family_with_ops(&hsr_genl_family, hsr_ops); 419 418 if (rc) 420 419 goto fail_genl_register_family; 421 420
+1 -2
net/ieee802154/netlink.c
··· 129 129 { 130 130 int rc; 131 131 132 - rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops, 133 - ARRAY_SIZE(ieee8021154_ops)); 132 + rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops); 134 133 if (rc) 135 134 return rc; 136 135
+1 -2
net/ipv4/tcp_metrics.c
··· 1082 1082 if (ret < 0) 1083 1083 goto cleanup; 1084 1084 ret = genl_register_family_with_ops(&tcp_metrics_nl_family, 1085 - tcp_metrics_nl_ops, 1086 - ARRAY_SIZE(tcp_metrics_nl_ops)); 1085 + tcp_metrics_nl_ops); 1087 1086 if (ret < 0) 1088 1087 goto cleanup_subsys; 1089 1088 return;
+1 -2
net/irda/irnetlink.c
··· 149 149 150 150 int irda_nl_register(void) 151 151 { 152 - return genl_register_family_with_ops(&irda_nl_family, 153 - irda_nl_ops, ARRAY_SIZE(irda_nl_ops)); 152 + return genl_register_family_with_ops(&irda_nl_family, irda_nl_ops); 154 153 } 155 154 156 155 void irda_nl_unregister(void)
+1 -6
net/l2tp/l2tp_netlink.c
··· 887 887 888 888 static int l2tp_nl_init(void) 889 889 { 890 - int err; 891 - 892 890 pr_info("L2TP netlink interface\n"); 893 - err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops, 894 - ARRAY_SIZE(l2tp_nl_ops)); 895 - 896 - return err; 891 + return genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops); 897 892 } 898 893 899 894 static void l2tp_nl_cleanup(void)
+1 -1
net/netfilter/ipvs/ip_vs_ctl.c
··· 3666 3666 static int __init ip_vs_genl_register(void) 3667 3667 { 3668 3668 return genl_register_family_with_ops(&ip_vs_genl_family, 3669 - ip_vs_genl_ops, ARRAY_SIZE(ip_vs_genl_ops)); 3669 + ip_vs_genl_ops); 3670 3670 } 3671 3671 3672 3672 static void ip_vs_genl_unregister(void)
+1 -1
net/netlabel/netlabel_cipso_v4.c
··· 783 783 int __init netlbl_cipsov4_genl_init(void) 784 784 { 785 785 return genl_register_family_with_ops(&netlbl_cipsov4_gnl_family, 786 - netlbl_cipsov4_ops, ARRAY_SIZE(netlbl_cipsov4_ops)); 786 + netlbl_cipsov4_ops); 787 787 }
+1 -1
net/netlabel/netlabel_mgmt.c
··· 779 779 int __init netlbl_mgmt_genl_init(void) 780 780 { 781 781 return genl_register_family_with_ops(&netlbl_mgmt_gnl_family, 782 - netlbl_mgmt_genl_ops, ARRAY_SIZE(netlbl_mgmt_genl_ops)); 782 + netlbl_mgmt_genl_ops); 783 783 }
+1 -1
net/netlabel/netlabel_unlabeled.c
··· 1397 1397 int __init netlbl_unlabel_genl_init(void) 1398 1398 { 1399 1399 return genl_register_family_with_ops(&netlbl_unlabel_gnl_family, 1400 - netlbl_unlabel_genl_ops, ARRAY_SIZE(netlbl_unlabel_genl_ops)); 1400 + netlbl_unlabel_genl_ops); 1401 1401 } 1402 1402 1403 1403 /*
+8 -6
net/netlink/genetlink.c
··· 906 906 return 0; 907 907 } 908 908 909 - static struct genl_ops genl_ctrl_ops = { 910 - .cmd = CTRL_CMD_GETFAMILY, 911 - .doit = ctrl_getfamily, 912 - .dumpit = ctrl_dumpfamily, 913 - .policy = ctrl_policy, 909 + static struct genl_ops genl_ctrl_ops[] = { 910 + { 911 + .cmd = CTRL_CMD_GETFAMILY, 912 + .doit = ctrl_getfamily, 913 + .dumpit = ctrl_dumpfamily, 914 + .policy = ctrl_policy, 915 + }, 914 916 }; 915 917 916 918 static struct genl_multicast_group notify_grp = { ··· 956 954 for (i = 0; i < GENL_FAM_TAB_SIZE; i++) 957 955 INIT_LIST_HEAD(&family_ht[i]); 958 956 959 - err = genl_register_family_with_ops(&genl_ctrl, &genl_ctrl_ops, 1); 957 + err = genl_register_family_with_ops(&genl_ctrl, genl_ctrl_ops); 960 958 if (err < 0) 961 959 goto problem; 962 960
+1 -2
net/nfc/netlink.c
··· 1536 1536 { 1537 1537 int rc; 1538 1538 1539 - rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops, 1540 - ARRAY_SIZE(nfc_genl_ops)); 1539 + rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops); 1541 1540 if (rc) 1542 1541 return rc; 1543 1542
+3 -2
net/openvswitch/datapath.c
··· 1817 1817 for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) { 1818 1818 const struct genl_family_and_ops *f = &dp_genl_families[i]; 1819 1819 1820 - err = genl_register_family_with_ops(f->family, f->ops, 1821 - f->n_ops); 1820 + f->family->ops = f->ops; 1821 + f->family->n_ops = f->n_ops; 1822 + err = genl_register_family(f->family); 1822 1823 if (err) 1823 1824 goto error; 1824 1825 n_registered++;
+6 -5
net/tipc/netlink.c
··· 76 76 .maxattr = 0, 77 77 }; 78 78 79 - static struct genl_ops tipc_genl_ops = { 80 - .cmd = TIPC_GENL_CMD, 81 - .doit = handle_cmd, 79 + static struct genl_ops tipc_genl_ops[] = { 80 + { 81 + .cmd = TIPC_GENL_CMD, 82 + .doit = handle_cmd, 83 + }, 82 84 }; 83 85 84 86 static int tipc_genl_family_registered; ··· 89 87 { 90 88 int res; 91 89 92 - res = genl_register_family_with_ops(&tipc_genl_family, 93 - &tipc_genl_ops, 1); 90 + res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops); 94 91 if (res) { 95 92 pr_err("Failed to register netlink interface\n"); 96 93 return res;
+2 -2
net/wimax/stack.c
··· 597 597 598 598 snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name), 599 599 "WiMAX"); 600 - result = genl_register_family_with_ops(&wimax_gnl_family, wimax_gnl_ops, 601 - ARRAY_SIZE(wimax_gnl_ops)); 600 + result = genl_register_family_with_ops(&wimax_gnl_family, 601 + wimax_gnl_ops); 602 602 if (unlikely(result < 0)) { 603 603 printk(KERN_ERR "cannot register generic netlink family: %d\n", 604 604 result);
+1 -2
net/wireless/nl80211.c
··· 11329 11329 { 11330 11330 int err; 11331 11331 11332 - err = genl_register_family_with_ops(&nl80211_fam, 11333 - nl80211_ops, ARRAY_SIZE(nl80211_ops)); 11332 + err = genl_register_family_with_ops(&nl80211_fam, nl80211_ops); 11334 11333 if (err) 11335 11334 return err; 11336 11335