aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2013-11-14 11:14:42 -0500
committerDavid S. Miller <davem@davemloft.net>2013-11-14 17:10:40 -0500
commitb61a5eea5904198d45e775c342be010a23decbe3 (patch)
tree1b1a6b78601a8d414a46344e1f3ef9ab5fae510e
parent1c582d915da13ca21ad375ae04ec1bd6193418b2 (diff)
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>
-rw-r--r--net/wimax/op-msg.c25
-rw-r--r--net/wimax/op-reset.c17
-rw-r--r--net/wimax/op-rfkill.c21
-rw-r--r--net/wimax/op-state-get.c17
-rw-r--r--net/wimax/stack.c79
-rw-r--r--net/wimax/wimax-internal.h7
6 files changed, 47 insertions, 119 deletions
diff --git a/net/wimax/op-msg.c b/net/wimax/op-msg.c
index 0694d62e4dbc..ff19cbeaf607 100644
--- a/net/wimax/op-msg.c
+++ b/net/wimax/op-msg.c
@@ -321,17 +321,6 @@ int wimax_msg(struct wimax_dev *wimax_dev, const char *pipe_name,
321} 321}
322EXPORT_SYMBOL_GPL(wimax_msg); 322EXPORT_SYMBOL_GPL(wimax_msg);
323 323
324
325static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
326 [WIMAX_GNL_MSG_IFIDX] = {
327 .type = NLA_U32,
328 },
329 [WIMAX_GNL_MSG_DATA] = {
330 .type = NLA_UNSPEC, /* libnl doesn't grok BINARY yet */
331 },
332};
333
334
335/* 324/*
336 * Relays a message from user space to the driver 325 * Relays a message from user space to the driver
337 * 326 *
@@ -340,7 +329,6 @@ static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
340 * 329 *
341 * This call will block while handling/relaying the message. 330 * This call will block while handling/relaying the message.
342 */ 331 */
343static
344int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info) 332int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
345{ 333{
346 int result, ifindex; 334 int result, ifindex;
@@ -418,16 +406,3 @@ error_no_wimax_dev:
418 return result; 406 return result;
419} 407}
420 408
421
422/*
423 * Generic Netlink glue
424 */
425
426struct genl_ops wimax_gnl_msg_from_user = {
427 .cmd = WIMAX_GNL_OP_MSG_FROM_USER,
428 .flags = GENL_ADMIN_PERM,
429 .policy = wimax_gnl_msg_policy,
430 .doit = wimax_gnl_doit_msg_from_user,
431 .dumpit = NULL,
432};
433
diff --git a/net/wimax/op-reset.c b/net/wimax/op-reset.c
index 7ceffe39d70e..eb4580784d9d 100644
--- a/net/wimax/op-reset.c
+++ b/net/wimax/op-reset.c
@@ -92,13 +92,6 @@ int wimax_reset(struct wimax_dev *wimax_dev)
92EXPORT_SYMBOL(wimax_reset); 92EXPORT_SYMBOL(wimax_reset);
93 93
94 94
95static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] = {
96 [WIMAX_GNL_RESET_IFIDX] = {
97 .type = NLA_U32,
98 },
99};
100
101
102/* 95/*
103 * Exporting to user space over generic netlink 96 * Exporting to user space over generic netlink
104 * 97 *
@@ -106,7 +99,6 @@ static const struct nla_policy wimax_gnl_reset_policy[WIMAX_GNL_ATTR_MAX + 1] =
106 * 99 *
107 * No attributes. 100 * No attributes.
108 */ 101 */
109static
110int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info) 102int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
111{ 103{
112 int result, ifindex; 104 int result, ifindex;
@@ -130,12 +122,3 @@ error_no_wimax_dev:
130 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); 122 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
131 return result; 123 return result;
132} 124}
133
134
135struct genl_ops wimax_gnl_reset = {
136 .cmd = WIMAX_GNL_OP_RESET,
137 .flags = GENL_ADMIN_PERM,
138 .policy = wimax_gnl_reset_policy,
139 .doit = wimax_gnl_doit_reset,
140 .dumpit = NULL,
141};
diff --git a/net/wimax/op-rfkill.c b/net/wimax/op-rfkill.c
index 7ab60babdd22..403078d670a9 100644
--- a/net/wimax/op-rfkill.c
+++ b/net/wimax/op-rfkill.c
@@ -411,17 +411,6 @@ void wimax_rfkill_rm(struct wimax_dev *wimax_dev)
411 * just query). 411 * just query).
412 */ 412 */
413 413
414static const struct nla_policy wimax_gnl_rfkill_policy[WIMAX_GNL_ATTR_MAX + 1] = {
415 [WIMAX_GNL_RFKILL_IFIDX] = {
416 .type = NLA_U32,
417 },
418 [WIMAX_GNL_RFKILL_STATE] = {
419 .type = NLA_U32 /* enum wimax_rf_state */
420 },
421};
422
423
424static
425int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info) 414int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
426{ 415{
427 int result, ifindex; 416 int result, ifindex;
@@ -457,13 +446,3 @@ error_no_wimax_dev:
457 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); 446 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
458 return result; 447 return result;
459} 448}
460
461
462struct genl_ops wimax_gnl_rfkill = {
463 .cmd = WIMAX_GNL_OP_RFKILL,
464 .flags = GENL_ADMIN_PERM,
465 .policy = wimax_gnl_rfkill_policy,
466 .doit = wimax_gnl_doit_rfkill,
467 .dumpit = NULL,
468};
469
diff --git a/net/wimax/op-state-get.c b/net/wimax/op-state-get.c
index aff8776e2d41..995c08c827b5 100644
--- a/net/wimax/op-state-get.c
+++ b/net/wimax/op-state-get.c
@@ -33,13 +33,6 @@
33#include "debug-levels.h" 33#include "debug-levels.h"
34 34
35 35
36static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1] = {
37 [WIMAX_GNL_STGET_IFIDX] = {
38 .type = NLA_U32,
39 },
40};
41
42
43/* 36/*
44 * Exporting to user space over generic netlink 37 * Exporting to user space over generic netlink
45 * 38 *
@@ -48,7 +41,6 @@ static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1
48 * 41 *
49 * No attributes. 42 * No attributes.
50 */ 43 */
51static
52int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info) 44int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
53{ 45{
54 int result, ifindex; 46 int result, ifindex;
@@ -72,12 +64,3 @@ error_no_wimax_dev:
72 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result); 64 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
73 return result; 65 return result;
74} 66}
75
76
77struct genl_ops wimax_gnl_state_get = {
78 .cmd = WIMAX_GNL_OP_STATE_GET,
79 .flags = GENL_ADMIN_PERM,
80 .policy = wimax_gnl_state_get_policy,
81 .doit = wimax_gnl_doit_state_get,
82 .dumpit = NULL,
83};
diff --git a/net/wimax/stack.c b/net/wimax/stack.c
index a6470ac39498..4b7f15a50087 100644
--- a/net/wimax/stack.c
+++ b/net/wimax/stack.c
@@ -402,22 +402,44 @@ void wimax_dev_init(struct wimax_dev *wimax_dev)
402} 402}
403EXPORT_SYMBOL_GPL(wimax_dev_init); 403EXPORT_SYMBOL_GPL(wimax_dev_init);
404 404
405/* 405static const struct nla_policy wimax_gnl_policy[WIMAX_GNL_ATTR_MAX + 1] = {
406 * This extern is declared here because it's easier to keep track -- 406 [WIMAX_GNL_RESET_IFIDX] = { .type = NLA_U32, },
407 * both declarations are a list of the same 407 [WIMAX_GNL_RFKILL_IFIDX] = { .type = NLA_U32, },
408 */ 408 [WIMAX_GNL_RFKILL_STATE] = {
409extern struct genl_ops 409 .type = NLA_U32 /* enum wimax_rf_state */
410 wimax_gnl_msg_from_user, 410 },
411 wimax_gnl_reset, 411 [WIMAX_GNL_STGET_IFIDX] = { .type = NLA_U32, },
412 wimax_gnl_rfkill, 412 [WIMAX_GNL_MSG_IFIDX] = { .type = NLA_U32, },
413 wimax_gnl_state_get; 413 [WIMAX_GNL_MSG_DATA] = {
414 .type = NLA_UNSPEC, /* libnl doesn't grok BINARY yet */
415 },
416};
414 417
415static 418static struct genl_ops wimax_gnl_ops[] = {
416struct genl_ops *wimax_gnl_ops[] = { 419 {
417 &wimax_gnl_msg_from_user, 420 .cmd = WIMAX_GNL_OP_MSG_FROM_USER,
418 &wimax_gnl_reset, 421 .flags = GENL_ADMIN_PERM,
419 &wimax_gnl_rfkill, 422 .policy = wimax_gnl_policy,
420 &wimax_gnl_state_get, 423 .doit = wimax_gnl_doit_msg_from_user,
424 },
425 {
426 .cmd = WIMAX_GNL_OP_RESET,
427 .flags = GENL_ADMIN_PERM,
428 .policy = wimax_gnl_policy,
429 .doit = wimax_gnl_doit_reset,
430 },
431 {
432 .cmd = WIMAX_GNL_OP_RFKILL,
433 .flags = GENL_ADMIN_PERM,
434 .policy = wimax_gnl_policy,
435 .doit = wimax_gnl_doit_rfkill,
436 },
437 {
438 .cmd = WIMAX_GNL_OP_STATE_GET,
439 .flags = GENL_ADMIN_PERM,
440 .policy = wimax_gnl_policy,
441 .doit = wimax_gnl_doit_state_get,
442 },
421}; 443};
422 444
423 445
@@ -567,7 +589,7 @@ struct genl_multicast_group wimax_gnl_mcg = {
567static 589static
568int __init wimax_subsys_init(void) 590int __init wimax_subsys_init(void)
569{ 591{
570 int result, cnt; 592 int result;
571 593
572 d_fnstart(4, NULL, "()\n"); 594 d_fnstart(4, NULL, "()\n");
573 d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params, 595 d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params,
@@ -575,26 +597,14 @@ int __init wimax_subsys_init(void)
575 597
576 snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name), 598 snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
577 "WiMAX"); 599 "WiMAX");
578 result = genl_register_family(&wimax_gnl_family); 600 result = genl_register_family_with_ops(&wimax_gnl_family, wimax_gnl_ops,
601 ARRAY_SIZE(wimax_gnl_ops));
579 if (unlikely(result < 0)) { 602 if (unlikely(result < 0)) {
580 printk(KERN_ERR "cannot register generic netlink family: %d\n", 603 printk(KERN_ERR "cannot register generic netlink family: %d\n",
581 result); 604 result);
582 goto error_register_family; 605 goto error_register_family;
583 } 606 }
584 607
585 for (cnt = 0; cnt < ARRAY_SIZE(wimax_gnl_ops); cnt++) {
586 result = genl_register_ops(&wimax_gnl_family,
587 wimax_gnl_ops[cnt]);
588 d_printf(4, NULL, "registering generic netlink op code "
589 "%u: %d\n", wimax_gnl_ops[cnt]->cmd, result);
590 if (unlikely(result < 0)) {
591 printk(KERN_ERR "cannot register generic netlink op "
592 "code %u: %d\n",
593 wimax_gnl_ops[cnt]->cmd, result);
594 goto error_register_ops;
595 }
596 }
597
598 result = genl_register_mc_group(&wimax_gnl_family, &wimax_gnl_mcg); 608 result = genl_register_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
599 if (result < 0) 609 if (result < 0)
600 goto error_mc_group; 610 goto error_mc_group;
@@ -602,10 +612,6 @@ int __init wimax_subsys_init(void)
602 return 0; 612 return 0;
603 613
604error_mc_group: 614error_mc_group:
605error_register_ops:
606 for (cnt--; cnt >= 0; cnt--)
607 genl_unregister_ops(&wimax_gnl_family,
608 wimax_gnl_ops[cnt]);
609 genl_unregister_family(&wimax_gnl_family); 615 genl_unregister_family(&wimax_gnl_family);
610error_register_family: 616error_register_family:
611 d_fnend(4, NULL, "() = %d\n", result); 617 d_fnend(4, NULL, "() = %d\n", result);
@@ -619,12 +625,7 @@ module_init(wimax_subsys_init);
619static 625static
620void __exit wimax_subsys_exit(void) 626void __exit wimax_subsys_exit(void)
621{ 627{
622 int cnt;
623 wimax_id_table_release(); 628 wimax_id_table_release();
624 genl_unregister_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
625 for (cnt = ARRAY_SIZE(wimax_gnl_ops) - 1; cnt >= 0; cnt--)
626 genl_unregister_ops(&wimax_gnl_family,
627 wimax_gnl_ops[cnt]);
628 genl_unregister_family(&wimax_gnl_family); 629 genl_unregister_family(&wimax_gnl_family);
629} 630}
630module_exit(wimax_subsys_exit); 631module_exit(wimax_subsys_exit);
diff --git a/net/wimax/wimax-internal.h b/net/wimax/wimax-internal.h
index 5dcd9c067bf0..8567d3079a83 100644
--- a/net/wimax/wimax-internal.h
+++ b/net/wimax/wimax-internal.h
@@ -84,8 +84,15 @@ void wimax_id_table_release(void);
84int wimax_rfkill_add(struct wimax_dev *); 84int wimax_rfkill_add(struct wimax_dev *);
85void wimax_rfkill_rm(struct wimax_dev *); 85void wimax_rfkill_rm(struct wimax_dev *);
86 86
87/* generic netlink */
87extern struct genl_family wimax_gnl_family; 88extern struct genl_family wimax_gnl_family;
88extern struct genl_multicast_group wimax_gnl_mcg; 89extern struct genl_multicast_group wimax_gnl_mcg;
89 90
91/* ops */
92int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info);
93int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info);
94int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info);
95int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info);
96
90#endif /* #ifdef __KERNEL__ */ 97#endif /* #ifdef __KERNEL__ */
91#endif /* #ifndef __WIMAX_INTERNAL_H__ */ 98#endif /* #ifndef __WIMAX_INTERNAL_H__ */