]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
genetlink: only pass array to genl_register_family_with_ops()
authorJohannes Berg <johannes.berg@intel.com>
Tue, 19 Nov 2013 14:19:31 +0000 (15:19 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 19 Nov 2013 21:39:05 +0000 (16:39 -0500)
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>
22 files changed:
drivers/net/team/team.c
drivers/net/wireless/mac80211_hwsim.c
fs/dlm/netlink.c
include/linux/genl_magic_func.h
include/net/genetlink.h
kernel/taskstats.c
net/core/drop_monitor.c
net/hsr/hsr_netlink.c
net/ieee802154/netlink.c
net/ipv4/tcp_metrics.c
net/irda/irnetlink.c
net/l2tp/l2tp_netlink.c
net/netfilter/ipvs/ip_vs_ctl.c
net/netlabel/netlabel_cipso_v4.c
net/netlabel/netlabel_mgmt.c
net/netlabel/netlabel_unlabeled.c
net/netlink/genetlink.c
net/nfc/netlink.c
net/openvswitch/datapath.c
net/tipc/netlink.c
net/wimax/stack.c
net/wireless/nl80211.c

index 6390254beb7d2b8a577a177f234949bdc709da06..f55758b0840e896e0421cd5266ba0d16be4ea03b 100644 (file)
@@ -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;
 
index cfc3fda79a2d8522ed963154a64c107a6f45ada8..9df7bc91a26f54c9812718e481c538895aa5b4f8 100644 (file)
@@ -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;
 
index 60a327863b1122e246b79bf91ecdf23136eccac9..e7cfbaf8d0e2ed66b404c259dcd64c2d4ccd5f54 100644 (file)
@@ -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)
index 023bc346b877f08bd75be65edaba526af7314558..47086030ab315cd28a94f75d9fb1562d534b2b2b 100644 (file)
@@ -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
index e96385d46b48b666d68d8b64e9e03ffda518476d..9bd52a4c5e17bb727bafd18f3cf5eec3f54d7264 100644 (file)
@@ -152,8 +152,9 @@ 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;
@@ -161,6 +162,9 @@ static inline int genl_register_family_with_ops(struct genl_family *family,
        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);
index 76595cd9d211a41c4f59bba07ff38026bc0f398d..13d2f7cd65dbfd851eaa61cf08645994c9fd0037 100644 (file)
@@ -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;
 
index f9fe2f22d20bcc5ff813bdd22c1263c5aa816367..0efc5028ba9d7072feb5846592396e8dd301237a 100644 (file)
@@ -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;
index 3b9205d2afc425cce8da26d86e1a21ad86626cf4..f182260be76d5fce1180e71e99c580b5c81b6e30 100644 (file)
@@ -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;
 
index 3ffcdbb56aabd0dfaa0885401f2a039680e59c34..1a81709a4717ea8f285015d2ede270fe396fa63d 100644 (file)
@@ -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;
 
index 8c121b523eee524d1552411a9cfef31c7e898bad..06493736fbc826842876180a24510d9e348cb7f3 100644 (file)
@@ -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;
index bf5d7d476daefdb37f57e9354b795b0d875c7a23..a37b81fe04798e0c8cb0196f72b2cf97e4b610b7 100644 (file)
@@ -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)
index 57db66e24f1fcc78f8cdbd95d3e02744c8f20e43..4cfd722e91536c1de137ec64f1e33bbc7fc5e1ea 100644 (file)
@@ -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)
index fc8a04ed88547fc033a1b92179aa056779bb767a..393498704691df817d9d9f48f30fbc8cd287a04d 100644 (file)
@@ -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)
index 706691739b991f65de4b7a1e441c50cb480aed66..69345cebe3a3e397beffbe56536bf971fb81ddf9 100644 (file)
@@ -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);
 }
index 7de6f660b80a554d25feeeb328749e581e7205ee..8ef83ee97c6ad0fa934bbbe3d4988003e9ee287b 100644 (file)
@@ -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);
 }
index 76ee9252daa774d073ffd3d90f9690c368f89312..43817d73ccf997b69ec15da814e274404e08a2c7 100644 (file)
@@ -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);
 }
 
 /*
index f54215d7b8f302c5e6b82ef77dafcd440c09be02..c68ce73619b551a92de19fcb2a53f343c85e2d9f 100644 (file)
@@ -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 = {
@@ -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;
 
index f5585611c098977cd4553303ef0d7e92c3a11606..fe6760d328a01abe4ec9f6f34930dc9231980f08 100644 (file)
@@ -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;
 
index 91e1c927a46542dd838ebadbb9e63e3831706472..8ec8b73033e0b2e6d2ad59c52931b547dbada3d5 100644 (file)
@@ -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++;
index 8bcd4985d0fb341f795346f06c55d1f059c4c643..9f72a6376362e613cb87185acbb3581174c45592 100644 (file)
@@ -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;
@@ -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;
index 47170c9495f14322e6c83ab504134e49e98b31dd..6328afe9031940bcdf6954f32b4615b50aea66d5 100644 (file)
@@ -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);
index 58c43c8e149fb236ccec6c8701d76ca0d21db206..1b6c5dd4dccfc739cae7d8bad58e8815241b65a2 100644 (file)
@@ -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;