Skip to content

Commit b61a5ee

Browse files
jmberg-inteldavem330
authored andcommitted
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>
1 parent 1c582d9 commit b61a5ee

6 files changed

Lines changed: 47 additions & 119 deletions

File tree

‎net/wimax/op-msg.c‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,6 @@ int wimax_msg(struct wimax_dev *wimax_dev, const char *pipe_name,
321321
}
322322
EXPORT_SYMBOL_GPL(wimax_msg);
323323

324-
325-
static 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-
335324
/*
336325
* Relays a message from user space to the driver
337326
*
@@ -340,7 +329,6 @@ static const struct nla_policy wimax_gnl_msg_policy[WIMAX_GNL_ATTR_MAX + 1] = {
340329
*
341330
* This call will block while handling/relaying the message.
342331
*/
343-
static
344332
int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
345333
{
346334
int result, ifindex;
@@ -418,16 +406,3 @@ int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info)
418406
return result;
419407
}
420408

421-
422-
/*
423-
* Generic Netlink glue
424-
*/
425-
426-
struct 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-

‎net/wimax/op-reset.c‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,13 @@ int wimax_reset(struct wimax_dev *wimax_dev)
9292
EXPORT_SYMBOL(wimax_reset);
9393

9494

95-
static 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-
10295
/*
10396
* Exporting to user space over generic netlink
10497
*
10598
* Parse the reset command from user space, return error code.
10699
*
107100
* No attributes.
108101
*/
109-
static
110102
int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
111103
{
112104
int result, ifindex;
@@ -130,12 +122,3 @@ int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
130122
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
131123
return result;
132124
}
133-
134-
135-
struct 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-
};

‎net/wimax/op-rfkill.c‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -411,17 +411,6 @@ void wimax_rfkill_rm(struct wimax_dev *wimax_dev)
411411
* just query).
412412
*/
413413

414-
static 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-
424-
static
425414
int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
426415
{
427416
int result, ifindex;
@@ -457,13 +446,3 @@ int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
457446
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
458447
return result;
459448
}
460-
461-
462-
struct 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-

‎net/wimax/op-state-get.c‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
#include "debug-levels.h"
3434

3535

36-
static 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-
4336
/*
4437
* Exporting to user space over generic netlink
4538
*
@@ -48,7 +41,6 @@ static const struct nla_policy wimax_gnl_state_get_policy[WIMAX_GNL_ATTR_MAX + 1
4841
*
4942
* No attributes.
5043
*/
51-
static
5244
int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
5345
{
5446
int result, ifindex;
@@ -72,12 +64,3 @@ int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info)
7264
d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
7365
return result;
7466
}
75-
76-
77-
struct 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-
};

‎net/wimax/stack.c‎

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -402,22 +402,44 @@ void wimax_dev_init(struct wimax_dev *wimax_dev)
402402
}
403403
EXPORT_SYMBOL_GPL(wimax_dev_init);
404404

405-
/*
406-
* This extern is declared here because it's easier to keep track --
407-
* both declarations are a list of the same
408-
*/
409-
extern struct genl_ops
410-
wimax_gnl_msg_from_user,
411-
wimax_gnl_reset,
412-
wimax_gnl_rfkill,
413-
wimax_gnl_state_get;
405+
static const struct nla_policy wimax_gnl_policy[WIMAX_GNL_ATTR_MAX + 1] = {
406+
[WIMAX_GNL_RESET_IFIDX] = { .type = NLA_U32, },
407+
[WIMAX_GNL_RFKILL_IFIDX] = { .type = NLA_U32, },
408+
[WIMAX_GNL_RFKILL_STATE] = {
409+
.type = NLA_U32 /* enum wimax_rf_state */
410+
},
411+
[WIMAX_GNL_STGET_IFIDX] = { .type = NLA_U32, },
412+
[WIMAX_GNL_MSG_IFIDX] = { .type = NLA_U32, },
413+
[WIMAX_GNL_MSG_DATA] = {
414+
.type = NLA_UNSPEC, /* libnl doesn't grok BINARY yet */
415+
},
416+
};
414417

415-
static
416-
struct genl_ops *wimax_gnl_ops[] = {
417-
&wimax_gnl_msg_from_user,
418-
&wimax_gnl_reset,
419-
&wimax_gnl_rfkill,
420-
&wimax_gnl_state_get,
418+
static struct genl_ops wimax_gnl_ops[] = {
419+
{
420+
.cmd = WIMAX_GNL_OP_MSG_FROM_USER,
421+
.flags = GENL_ADMIN_PERM,
422+
.policy = wimax_gnl_policy,
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+
},
421443
};
422444

423445

@@ -567,45 +589,29 @@ struct genl_multicast_group wimax_gnl_mcg = {
567589
static
568590
int __init wimax_subsys_init(void)
569591
{
570-
int result, cnt;
592+
int result;
571593

572594
d_fnstart(4, NULL, "()\n");
573595
d_parse_params(D_LEVEL, D_LEVEL_SIZE, wimax_debug_params,
574596
"wimax.debug");
575597

576598
snprintf(wimax_gnl_family.name, sizeof(wimax_gnl_family.name),
577599
"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));
579602
if (unlikely(result < 0)) {
580603
printk(KERN_ERR "cannot register generic netlink family: %d\n",
581604
result);
582605
goto error_register_family;
583606
}
584607

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-
598608
result = genl_register_mc_group(&wimax_gnl_family, &wimax_gnl_mcg);
599609
if (result < 0)
600610
goto error_mc_group;
601611
d_fnend(4, NULL, "() = 0\n");
602612
return 0;
603613

604614
error_mc_group:
605-
error_register_ops:
606-
for (cnt--; cnt >= 0; cnt--)
607-
genl_unregister_ops(&wimax_gnl_family,
608-
wimax_gnl_ops[cnt]);
609615
genl_unregister_family(&wimax_gnl_family);
610616
error_register_family:
611617
d_fnend(4, NULL, "() = %d\n", result);
@@ -619,12 +625,7 @@ module_init(wimax_subsys_init);
619625
static
620626
void __exit wimax_subsys_exit(void)
621627
{
622-
int cnt;
623628
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]);
628629
genl_unregister_family(&wimax_gnl_family);
629630
}
630631
module_exit(wimax_subsys_exit);

‎net/wimax/wimax-internal.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ void wimax_id_table_release(void);
8484
int wimax_rfkill_add(struct wimax_dev *);
8585
void wimax_rfkill_rm(struct wimax_dev *);
8686

87+
/* generic netlink */
8788
extern struct genl_family wimax_gnl_family;
8889
extern struct genl_multicast_group wimax_gnl_mcg;
8990

91+
/* ops */
92+
int wimax_gnl_doit_msg_from_user(struct sk_buff *skb, struct genl_info *info);
93+
int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info);
94+
int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info);
95+
int wimax_gnl_doit_state_get(struct sk_buff *skb, struct genl_info *info);
96+
9097
#endif /* #ifdef __KERNEL__ */
9198
#endif /* #ifndef __WIMAX_INTERNAL_H__ */

0 commit comments

Comments
 (0)