Skip to content

Commit 489111e

Browse files
jmberg-inteldavem330
authored andcommitted
genetlink: statically initialize families
Instead of providing macros/inline functions to initialize the families, make all users initialize them statically and get rid of the macros. This reduces the kernel code size by about 1.6k on x86-64 (with allyesconfig). Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a07ea4d commit 489111e

37 files changed

+414
-337
lines changed

drivers/acpi/event.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static const struct genl_multicast_group acpi_event_mcgrps[] = {
8383
};
8484

8585
static struct genl_family acpi_event_genl_family = {
86+
.module = THIS_MODULE,
8687
.name = ACPI_GENL_FAMILY_NAME,
8788
.version = ACPI_GENL_VERSION,
8889
.maxattr = ACPI_GENL_ATTR_MAX,

drivers/net/gtp.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,13 +1094,7 @@ static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info)
10941094
return 0;
10951095
}
10961096

1097-
static struct genl_family gtp_genl_family = {
1098-
.name = "gtp",
1099-
.version = 0,
1100-
.hdrsize = 0,
1101-
.maxattr = GTPA_MAX,
1102-
.netnsok = true,
1103-
};
1097+
static struct genl_family gtp_genl_family;
11041098

11051099
static int gtp_genl_fill_info(struct sk_buff *skb, u32 snd_portid, u32 snd_seq,
11061100
u32 type, struct pdp_ctx *pctx)
@@ -1296,6 +1290,17 @@ static const struct genl_ops gtp_genl_ops[] = {
12961290
},
12971291
};
12981292

1293+
static struct genl_family gtp_genl_family = {
1294+
.name = "gtp",
1295+
.version = 0,
1296+
.hdrsize = 0,
1297+
.maxattr = GTPA_MAX,
1298+
.netnsok = true,
1299+
.module = THIS_MODULE,
1300+
.ops = gtp_genl_ops,
1301+
.n_ops = ARRAY_SIZE(gtp_genl_ops),
1302+
};
1303+
12991304
static int __net_init gtp_net_init(struct net *net)
13001305
{
13011306
struct gtp_net *gn = net_generic(net, gtp_net_id);
@@ -1335,7 +1340,7 @@ static int __init gtp_init(void)
13351340
if (err < 0)
13361341
goto error_out;
13371342

1338-
err = genl_register_family_with_ops(&gtp_genl_family, gtp_genl_ops);
1343+
err = genl_register_family(&gtp_genl_family);
13391344
if (err < 0)
13401345
goto unreg_rtnl_link;
13411346

drivers/net/macsec.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,13 +1421,7 @@ static void clear_tx_sa(struct macsec_tx_sa *tx_sa)
14211421
macsec_txsa_put(tx_sa);
14221422
}
14231423

1424-
static struct genl_family macsec_fam = {
1425-
.name = MACSEC_GENL_NAME,
1426-
.hdrsize = 0,
1427-
.version = MACSEC_GENL_VERSION,
1428-
.maxattr = MACSEC_ATTR_MAX,
1429-
.netnsok = true,
1430-
};
1424+
static struct genl_family macsec_fam;
14311425

14321426
static struct net_device *get_dev_from_nl(struct net *net,
14331427
struct nlattr **attrs)
@@ -2654,6 +2648,17 @@ static const struct genl_ops macsec_genl_ops[] = {
26542648
},
26552649
};
26562650

2651+
static struct genl_family macsec_fam = {
2652+
.name = MACSEC_GENL_NAME,
2653+
.hdrsize = 0,
2654+
.version = MACSEC_GENL_VERSION,
2655+
.maxattr = MACSEC_ATTR_MAX,
2656+
.netnsok = true,
2657+
.module = THIS_MODULE,
2658+
.ops = macsec_genl_ops,
2659+
.n_ops = ARRAY_SIZE(macsec_genl_ops),
2660+
};
2661+
26572662
static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
26582663
struct net_device *dev)
26592664
{
@@ -3461,7 +3466,7 @@ static int __init macsec_init(void)
34613466
if (err)
34623467
goto notifier;
34633468

3464-
err = genl_register_family_with_ops(&macsec_fam, macsec_genl_ops);
3469+
err = genl_register_family(&macsec_fam);
34653470
if (err)
34663471
goto rtnl;
34673472

drivers/net/team/team.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,12 +2150,7 @@ static struct rtnl_link_ops team_link_ops __read_mostly = {
21502150
* Generic netlink custom interface
21512151
***********************************/
21522152

2153-
static struct genl_family team_nl_family = {
2154-
.name = TEAM_GENL_NAME,
2155-
.version = TEAM_GENL_VERSION,
2156-
.maxattr = TEAM_ATTR_MAX,
2157-
.netnsok = true,
2158-
};
2153+
static struct genl_family team_nl_family;
21592154

21602155
static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
21612156
[TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, },
@@ -2745,6 +2740,18 @@ static const struct genl_multicast_group team_nl_mcgrps[] = {
27452740
{ .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
27462741
};
27472742

2743+
static struct genl_family team_nl_family = {
2744+
.name = TEAM_GENL_NAME,
2745+
.version = TEAM_GENL_VERSION,
2746+
.maxattr = TEAM_ATTR_MAX,
2747+
.netnsok = true,
2748+
.module = THIS_MODULE,
2749+
.ops = team_nl_ops,
2750+
.n_ops = ARRAY_SIZE(team_nl_ops),
2751+
.mcgrps = team_nl_mcgrps,
2752+
.n_mcgrps = ARRAY_SIZE(team_nl_mcgrps),
2753+
};
2754+
27482755
static int team_nl_send_multicast(struct sk_buff *skb,
27492756
struct team *team, u32 portid)
27502757
{
@@ -2768,8 +2775,7 @@ static int team_nl_send_event_port_get(struct team *team,
27682775

27692776
static int team_nl_init(void)
27702777
{
2771-
return genl_register_family_with_ops_groups(&team_nl_family, team_nl_ops,
2772-
team_nl_mcgrps);
2778+
return genl_register_family(&team_nl_family);
27732779
}
27742780

27752781
static void team_nl_fini(void)

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,8 @@ struct hwsim_radiotap_ack_hdr {
587587
__le16 rt_chbitmask;
588588
} __packed;
589589

590-
/* MAC80211_HWSIM netlinf family */
591-
static struct genl_family hwsim_genl_family = {
592-
.hdrsize = 0,
593-
.name = "MAC80211_HWSIM",
594-
.version = 1,
595-
.maxattr = HWSIM_ATTR_MAX,
596-
.netnsok = true,
597-
};
590+
/* MAC80211_HWSIM netlink family */
591+
static struct genl_family hwsim_genl_family;
598592

599593
enum hwsim_multicast_groups {
600594
HWSIM_MCGRP_CONFIG,
@@ -3234,6 +3228,18 @@ static const struct genl_ops hwsim_ops[] = {
32343228
},
32353229
};
32363230

3231+
static struct genl_family hwsim_genl_family = {
3232+
.name = "MAC80211_HWSIM",
3233+
.version = 1,
3234+
.maxattr = HWSIM_ATTR_MAX,
3235+
.netnsok = true,
3236+
.module = THIS_MODULE,
3237+
.ops = hwsim_ops,
3238+
.n_ops = ARRAY_SIZE(hwsim_ops),
3239+
.mcgrps = hwsim_mcgrps,
3240+
.n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
3241+
};
3242+
32373243
static void destroy_radio(struct work_struct *work)
32383244
{
32393245
struct mac80211_hwsim_data *data =
@@ -3287,9 +3293,7 @@ static int hwsim_init_netlink(void)
32873293

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

3290-
rc = genl_register_family_with_ops_groups(&hwsim_genl_family,
3291-
hwsim_ops,
3292-
hwsim_mcgrps);
3296+
rc = genl_register_family(&hwsim_genl_family);
32933297
if (rc)
32943298
goto failure;
32953299

drivers/scsi/pmcraid.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ static struct genl_multicast_group pmcraid_mcgrps[] = {
13691369
};
13701370

13711371
static struct genl_family pmcraid_event_family = {
1372+
.module = THIS_MODULE,
13721373
.name = "pmcraid",
13731374
.version = 1,
13741375
.maxattr = PMCRAID_AEN_ATTR_MAX,

drivers/target/target_core_user.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static const struct genl_multicast_group tcmu_mcgrps[] = {
148148

149149
/* Our generic netlink family */
150150
static struct genl_family tcmu_genl_family = {
151+
.module = THIS_MODULE,
151152
.hdrsize = 0,
152153
.name = "TCM-USER",
153154
.version = 1,

drivers/thermal/thermal_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,7 @@ static const struct genl_multicast_group thermal_event_mcgrps[] = {
21642164
};
21652165

21662166
static struct genl_family thermal_event_genl_family = {
2167+
.module = THIS_MODULE,
21672168
.name = THERMAL_GENL_FAMILY_NAME,
21682169
.version = THERMAL_GENL_VERSION,
21692170
.maxattr = THERMAL_GENL_ATTR_MAX,

fs/dlm/netlink.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
static uint32_t dlm_nl_seqnum;
1717
static uint32_t listener_nlportid;
1818

19-
static struct genl_family family = {
20-
.name = DLM_GENL_NAME,
21-
.version = DLM_GENL_VERSION,
22-
};
19+
static struct genl_family family;
2320

2421
static int prepare_data(u8 cmd, struct sk_buff **skbp, size_t size)
2522
{
@@ -75,9 +72,17 @@ static struct genl_ops dlm_nl_ops[] = {
7572
},
7673
};
7774

75+
static struct genl_family family = {
76+
.name = DLM_GENL_NAME,
77+
.version = DLM_GENL_VERSION,
78+
.ops = dlm_nl_ops,
79+
.n_ops = ARRAY_SIZE(dlm_nl_ops),
80+
.module = THIS_MODULE,
81+
};
82+
7883
int __init dlm_netlink_init(void)
7984
{
80-
return genl_register_family_with_ops(&family, dlm_nl_ops);
85+
return genl_register_family(&family);
8186
}
8287

8388
void dlm_netlink_exit(void)

fs/quota/netlink.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static const struct genl_multicast_group quota_mcgrps[] = {
1313

1414
/* Netlink family structure for quota */
1515
static struct genl_family quota_genl_family = {
16+
.module = THIS_MODULE,
1617
.hdrsize = 0,
1718
.name = "VFS_DQUOT",
1819
.version = 1,

include/linux/drbd_genl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
* genl_magic_func.h
6868
* generates an entry in the static genl_ops array,
6969
* and static register/unregister functions to
70-
* genl_register_family_with_ops().
70+
* genl_register_family().
7171
*
7272
* flags and handler:
7373
* GENL_op_init( .doit = x, .dumpit = y, .flags = something)

include/linux/genl_magic_func.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,7 @@ static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
259259
* {{{2
260260
*/
261261
#define ZZZ_genl_family CONCAT_(GENL_MAGIC_FAMILY, _genl_family)
262-
static struct genl_family ZZZ_genl_family __read_mostly = {
263-
.name = __stringify(GENL_MAGIC_FAMILY),
264-
.version = GENL_MAGIC_VERSION,
265-
#ifdef GENL_MAGIC_FAMILY_HDRSZ
266-
.hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ),
267-
#endif
268-
.maxattr = ARRAY_SIZE(drbd_tla_nl_policy)-1,
269-
};
270-
262+
static struct genl_family ZZZ_genl_family;
271263
/*
272264
* Magic: define multicast groups
273265
* Magic: define multicast group registration helper
@@ -301,11 +293,23 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \
301293
#undef GENL_mc_group
302294
#define GENL_mc_group(group)
303295

296+
static struct genl_family ZZZ_genl_family __read_mostly = {
297+
.name = __stringify(GENL_MAGIC_FAMILY),
298+
.version = GENL_MAGIC_VERSION,
299+
#ifdef GENL_MAGIC_FAMILY_HDRSZ
300+
.hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ),
301+
#endif
302+
.maxattr = ARRAY_SIZE(drbd_tla_nl_policy)-1,
303+
.ops = ZZZ_genl_ops,
304+
.n_ops = ARRAY_SIZE(ZZZ_genl_ops),
305+
.mcgrps = ZZZ_genl_mcgrps,
306+
.n_mcgrps = ARRAY_SIZE(ZZZ_genl_mcgrps),
307+
.module = THIS_MODULE,
308+
};
309+
304310
int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
305311
{
306-
return genl_register_family_with_ops_groups(&ZZZ_genl_family, \
307-
ZZZ_genl_ops, \
308-
ZZZ_genl_mcgrps);
312+
return genl_register_family(&ZZZ_genl_family);
309313
}
310314

311315
void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void)

include/net/genetlink.h

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ struct genl_info;
3939
* Note that unbind() will not be called symmetrically if the
4040
* generic netlink family is removed while there are still open
4141
* sockets.
42-
* @attrbuf: buffer to store parsed attributes
43-
* @family_list: family list
44-
* @mcgrps: multicast groups used by this family (private)
45-
* @n_mcgrps: number of multicast groups (private)
42+
* @attrbuf: buffer to store parsed attributes (private)
43+
* @family_list: family list (private)
44+
* @mcgrps: multicast groups used by this family
45+
* @n_mcgrps: number of multicast groups
4646
* @mcgrp_offset: starting number of multicast group IDs in this family
47-
* @ops: the operations supported by this family (private)
48-
* @n_ops: number of operations supported by this family (private)
47+
* (private)
48+
* @ops: the operations supported by this family
49+
* @n_ops: number of operations supported by this family
4950
*/
5051
struct genl_family {
5152
unsigned int id; /* private */
@@ -64,10 +65,10 @@ struct genl_family {
6465
int (*mcast_bind)(struct net *net, int group);
6566
void (*mcast_unbind)(struct net *net, int group);
6667
struct nlattr ** attrbuf; /* private */
67-
const struct genl_ops * ops; /* private */
68-
const struct genl_multicast_group *mcgrps; /* private */
69-
unsigned int n_ops; /* private */
70-
unsigned int n_mcgrps; /* private */
68+
const struct genl_ops * ops;
69+
const struct genl_multicast_group *mcgrps;
70+
unsigned int n_ops;
71+
unsigned int n_mcgrps;
7172
unsigned int mcgrp_offset; /* private */
7273
struct list_head family_list; /* private */
7374
struct module *module;
@@ -132,55 +133,7 @@ struct genl_ops {
132133
u8 flags;
133134
};
134135

135-
int __genl_register_family(struct genl_family *family);
136-
137-
static inline int genl_register_family(struct genl_family *family)
138-
{
139-
family->module = THIS_MODULE;
140-
return __genl_register_family(family);
141-
}
142-
143-
/**
144-
* genl_register_family_with_ops - register a generic netlink family with ops
145-
* @family: generic netlink family
146-
* @ops: operations to be registered
147-
* @n_ops: number of elements to register
148-
*
149-
* Registers the specified family and operations from the specified table.
150-
* Only one family may be registered with the same family name or identifier.
151-
*
152-
* Either a doit or dumpit callback must be specified for every registered
153-
* operation or the function will fail. Only one operation structure per
154-
* command identifier may be registered.
155-
*
156-
* See include/net/genetlink.h for more documenation on the operations
157-
* structure.
158-
*
159-
* Return 0 on success or a negative error code.
160-
*/
161-
static inline int
162-
_genl_register_family_with_ops_grps(struct genl_family *family,
163-
const struct genl_ops *ops, size_t n_ops,
164-
const struct genl_multicast_group *mcgrps,
165-
size_t n_mcgrps)
166-
{
167-
family->module = THIS_MODULE;
168-
family->ops = ops;
169-
family->n_ops = n_ops;
170-
family->mcgrps = mcgrps;
171-
family->n_mcgrps = n_mcgrps;
172-
return __genl_register_family(family);
173-
}
174-
175-
#define genl_register_family_with_ops(family, ops) \
176-
_genl_register_family_with_ops_grps((family), \
177-
(ops), ARRAY_SIZE(ops), \
178-
NULL, 0)
179-
#define genl_register_family_with_ops_groups(family, ops, grps) \
180-
_genl_register_family_with_ops_grps((family), \
181-
(ops), ARRAY_SIZE(ops), \
182-
(grps), ARRAY_SIZE(grps))
183-
136+
int genl_register_family(struct genl_family *family);
184137
int genl_unregister_family(struct genl_family *family);
185138
void genl_notify(struct genl_family *family, struct sk_buff *skb,
186139
struct genl_info *info, u32 group, gfp_t flags);

0 commit comments

Comments
 (0)