Skip to content

Commit

Permalink
genetlink: statically initialize families
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jmberg-intel authored and davem330 committed Oct 27, 2016
1 parent a07ea4d commit 489111e
Show file tree
Hide file tree
Showing 37 changed files with 414 additions and 337 deletions.
1 change: 1 addition & 0 deletions drivers/acpi/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static const struct genl_multicast_group acpi_event_mcgrps[] = {
};

static struct genl_family acpi_event_genl_family = {
.module = THIS_MODULE,
.name = ACPI_GENL_FAMILY_NAME,
.version = ACPI_GENL_VERSION,
.maxattr = ACPI_GENL_ATTR_MAX,
Expand Down
21 changes: 13 additions & 8 deletions drivers/net/gtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,13 +1094,7 @@ static int gtp_genl_del_pdp(struct sk_buff *skb, struct genl_info *info)
return 0;
}

static struct genl_family gtp_genl_family = {
.name = "gtp",
.version = 0,
.hdrsize = 0,
.maxattr = GTPA_MAX,
.netnsok = true,
};
static struct genl_family gtp_genl_family;

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

static struct genl_family gtp_genl_family = {
.name = "gtp",
.version = 0,
.hdrsize = 0,
.maxattr = GTPA_MAX,
.netnsok = true,
.module = THIS_MODULE,
.ops = gtp_genl_ops,
.n_ops = ARRAY_SIZE(gtp_genl_ops),
};

static int __net_init gtp_net_init(struct net *net)
{
struct gtp_net *gn = net_generic(net, gtp_net_id);
Expand Down Expand Up @@ -1335,7 +1340,7 @@ static int __init gtp_init(void)
if (err < 0)
goto error_out;

err = genl_register_family_with_ops(&gtp_genl_family, gtp_genl_ops);
err = genl_register_family(&gtp_genl_family);
if (err < 0)
goto unreg_rtnl_link;

Expand Down
21 changes: 13 additions & 8 deletions drivers/net/macsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,13 +1421,7 @@ static void clear_tx_sa(struct macsec_tx_sa *tx_sa)
macsec_txsa_put(tx_sa);
}

static struct genl_family macsec_fam = {
.name = MACSEC_GENL_NAME,
.hdrsize = 0,
.version = MACSEC_GENL_VERSION,
.maxattr = MACSEC_ATTR_MAX,
.netnsok = true,
};
static struct genl_family macsec_fam;

static struct net_device *get_dev_from_nl(struct net *net,
struct nlattr **attrs)
Expand Down Expand Up @@ -2654,6 +2648,17 @@ static const struct genl_ops macsec_genl_ops[] = {
},
};

static struct genl_family macsec_fam = {
.name = MACSEC_GENL_NAME,
.hdrsize = 0,
.version = MACSEC_GENL_VERSION,
.maxattr = MACSEC_ATTR_MAX,
.netnsok = true,
.module = THIS_MODULE,
.ops = macsec_genl_ops,
.n_ops = ARRAY_SIZE(macsec_genl_ops),
};

static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
struct net_device *dev)
{
Expand Down Expand Up @@ -3461,7 +3466,7 @@ static int __init macsec_init(void)
if (err)
goto notifier;

err = genl_register_family_with_ops(&macsec_fam, macsec_genl_ops);
err = genl_register_family(&macsec_fam);
if (err)
goto rtnl;

Expand Down
22 changes: 14 additions & 8 deletions drivers/net/team/team.c
Original file line number Diff line number Diff line change
Expand Up @@ -2150,12 +2150,7 @@ static struct rtnl_link_ops team_link_ops __read_mostly = {
* Generic netlink custom interface
***********************************/

static struct genl_family team_nl_family = {
.name = TEAM_GENL_NAME,
.version = TEAM_GENL_VERSION,
.maxattr = TEAM_ATTR_MAX,
.netnsok = true,
};
static struct genl_family team_nl_family;

static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
[TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, },
Expand Down Expand Up @@ -2745,6 +2740,18 @@ static const struct genl_multicast_group team_nl_mcgrps[] = {
{ .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME, },
};

static struct genl_family team_nl_family = {
.name = TEAM_GENL_NAME,
.version = TEAM_GENL_VERSION,
.maxattr = TEAM_ATTR_MAX,
.netnsok = true,
.module = THIS_MODULE,
.ops = team_nl_ops,
.n_ops = ARRAY_SIZE(team_nl_ops),
.mcgrps = team_nl_mcgrps,
.n_mcgrps = ARRAY_SIZE(team_nl_mcgrps),
};

static int team_nl_send_multicast(struct sk_buff *skb,
struct team *team, u32 portid)
{
Expand All @@ -2768,8 +2775,7 @@ static int team_nl_send_event_port_get(struct team *team,

static int team_nl_init(void)
{
return genl_register_family_with_ops_groups(&team_nl_family, team_nl_ops,
team_nl_mcgrps);
return genl_register_family(&team_nl_family);
}

static void team_nl_fini(void)
Expand Down
26 changes: 15 additions & 11 deletions drivers/net/wireless/mac80211_hwsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,8 @@ struct hwsim_radiotap_ack_hdr {
__le16 rt_chbitmask;
} __packed;

/* MAC80211_HWSIM netlinf family */
static struct genl_family hwsim_genl_family = {
.hdrsize = 0,
.name = "MAC80211_HWSIM",
.version = 1,
.maxattr = HWSIM_ATTR_MAX,
.netnsok = true,
};
/* MAC80211_HWSIM netlink family */
static struct genl_family hwsim_genl_family;

enum hwsim_multicast_groups {
HWSIM_MCGRP_CONFIG,
Expand Down Expand Up @@ -3234,6 +3228,18 @@ static const struct genl_ops hwsim_ops[] = {
},
};

static struct genl_family hwsim_genl_family = {
.name = "MAC80211_HWSIM",
.version = 1,
.maxattr = HWSIM_ATTR_MAX,
.netnsok = true,
.module = THIS_MODULE,
.ops = hwsim_ops,
.n_ops = ARRAY_SIZE(hwsim_ops),
.mcgrps = hwsim_mcgrps,
.n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
};

static void destroy_radio(struct work_struct *work)
{
struct mac80211_hwsim_data *data =
Expand Down Expand Up @@ -3287,9 +3293,7 @@ static int hwsim_init_netlink(void)

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

rc = genl_register_family_with_ops_groups(&hwsim_genl_family,
hwsim_ops,
hwsim_mcgrps);
rc = genl_register_family(&hwsim_genl_family);
if (rc)
goto failure;

Expand Down
1 change: 1 addition & 0 deletions drivers/scsi/pmcraid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ static struct genl_multicast_group pmcraid_mcgrps[] = {
};

static struct genl_family pmcraid_event_family = {
.module = THIS_MODULE,
.name = "pmcraid",
.version = 1,
.maxattr = PMCRAID_AEN_ATTR_MAX,
Expand Down
1 change: 1 addition & 0 deletions drivers/target/target_core_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static const struct genl_multicast_group tcmu_mcgrps[] = {

/* Our generic netlink family */
static struct genl_family tcmu_genl_family = {
.module = THIS_MODULE,
.hdrsize = 0,
.name = "TCM-USER",
.version = 1,
Expand Down
1 change: 1 addition & 0 deletions drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,7 @@ static const struct genl_multicast_group thermal_event_mcgrps[] = {
};

static struct genl_family thermal_event_genl_family = {
.module = THIS_MODULE,
.name = THERMAL_GENL_FAMILY_NAME,
.version = THERMAL_GENL_VERSION,
.maxattr = THERMAL_GENL_ATTR_MAX,
Expand Down
15 changes: 10 additions & 5 deletions fs/dlm/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
static uint32_t dlm_nl_seqnum;
static uint32_t listener_nlportid;

static struct genl_family family = {
.name = DLM_GENL_NAME,
.version = DLM_GENL_VERSION,
};
static struct genl_family family;

static int prepare_data(u8 cmd, struct sk_buff **skbp, size_t size)
{
Expand Down Expand Up @@ -75,9 +72,17 @@ static struct genl_ops dlm_nl_ops[] = {
},
};

static struct genl_family family = {
.name = DLM_GENL_NAME,
.version = DLM_GENL_VERSION,
.ops = dlm_nl_ops,
.n_ops = ARRAY_SIZE(dlm_nl_ops),
.module = THIS_MODULE,
};

int __init dlm_netlink_init(void)
{
return genl_register_family_with_ops(&family, dlm_nl_ops);
return genl_register_family(&family);
}

void dlm_netlink_exit(void)
Expand Down
1 change: 1 addition & 0 deletions fs/quota/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static const struct genl_multicast_group quota_mcgrps[] = {

/* Netlink family structure for quota */
static struct genl_family quota_genl_family = {
.module = THIS_MODULE,
.hdrsize = 0,
.name = "VFS_DQUOT",
.version = 1,
Expand Down
2 changes: 1 addition & 1 deletion include/linux/drbd_genl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* genl_magic_func.h
* generates an entry in the static genl_ops array,
* and static register/unregister functions to
* genl_register_family_with_ops().
* genl_register_family().
*
* flags and handler:
* GENL_op_init( .doit = x, .dumpit = y, .flags = something)
Expand Down
28 changes: 16 additions & 12 deletions include/linux/genl_magic_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,7 @@ static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
* {{{2
*/
#define ZZZ_genl_family CONCAT_(GENL_MAGIC_FAMILY, _genl_family)
static struct genl_family ZZZ_genl_family __read_mostly = {
.name = __stringify(GENL_MAGIC_FAMILY),
.version = GENL_MAGIC_VERSION,
#ifdef GENL_MAGIC_FAMILY_HDRSZ
.hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ),
#endif
.maxattr = ARRAY_SIZE(drbd_tla_nl_policy)-1,
};

static struct genl_family ZZZ_genl_family;
/*
* Magic: define multicast groups
* Magic: define multicast group registration helper
Expand Down Expand Up @@ -301,11 +293,23 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \
#undef GENL_mc_group
#define GENL_mc_group(group)

static struct genl_family ZZZ_genl_family __read_mostly = {
.name = __stringify(GENL_MAGIC_FAMILY),
.version = GENL_MAGIC_VERSION,
#ifdef GENL_MAGIC_FAMILY_HDRSZ
.hdrsize = NLA_ALIGN(GENL_MAGIC_FAMILY_HDRSZ),
#endif
.maxattr = ARRAY_SIZE(drbd_tla_nl_policy)-1,
.ops = ZZZ_genl_ops,
.n_ops = ARRAY_SIZE(ZZZ_genl_ops),
.mcgrps = ZZZ_genl_mcgrps,
.n_mcgrps = ARRAY_SIZE(ZZZ_genl_mcgrps),
.module = THIS_MODULE,
};

int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
{
return genl_register_family_with_ops_groups(&ZZZ_genl_family, \
ZZZ_genl_ops, \
ZZZ_genl_mcgrps);
return genl_register_family(&ZZZ_genl_family);
}

void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void)
Expand Down
71 changes: 12 additions & 59 deletions include/net/genetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ struct genl_info;
* Note that unbind() will not be called symmetrically if the
* generic netlink family is removed while there are still open
* sockets.
* @attrbuf: buffer to store parsed attributes
* @family_list: family list
* @mcgrps: multicast groups used by this family (private)
* @n_mcgrps: number of multicast groups (private)
* @attrbuf: buffer to store parsed attributes (private)
* @family_list: family list (private)
* @mcgrps: multicast groups used by this family
* @n_mcgrps: number of multicast groups
* @mcgrp_offset: starting number of multicast group IDs in this family
* @ops: the operations supported by this family (private)
* @n_ops: number of operations supported by this family (private)
* (private)
* @ops: the operations supported by this family
* @n_ops: number of operations supported by this family
*/
struct genl_family {
unsigned int id; /* private */
Expand All @@ -64,10 +65,10 @@ struct genl_family {
int (*mcast_bind)(struct net *net, int group);
void (*mcast_unbind)(struct net *net, int group);
struct nlattr ** attrbuf; /* private */
const struct genl_ops * ops; /* private */
const struct genl_multicast_group *mcgrps; /* private */
unsigned int n_ops; /* private */
unsigned int n_mcgrps; /* private */
const struct genl_ops * ops;
const struct genl_multicast_group *mcgrps;
unsigned int n_ops;
unsigned int n_mcgrps;
unsigned int mcgrp_offset; /* private */
struct list_head family_list; /* private */
struct module *module;
Expand Down Expand Up @@ -132,55 +133,7 @@ struct genl_ops {
u8 flags;
};

int __genl_register_family(struct genl_family *family);

static inline int genl_register_family(struct genl_family *family)
{
family->module = THIS_MODULE;
return __genl_register_family(family);
}

/**
* genl_register_family_with_ops - register a generic netlink family with ops
* @family: generic netlink family
* @ops: operations to be registered
* @n_ops: number of elements to register
*
* Registers the specified family and operations from the specified table.
* Only one family may be registered with the same family name or identifier.
*
* Either a doit or dumpit callback must be specified for every registered
* operation or the function will fail. Only one operation structure per
* command identifier may be registered.
*
* See include/net/genetlink.h for more documenation on the operations
* structure.
*
* Return 0 on success or a negative error code.
*/
static inline int
_genl_register_family_with_ops_grps(struct genl_family *family,
const struct genl_ops *ops, size_t n_ops,
const struct genl_multicast_group *mcgrps,
size_t n_mcgrps)
{
family->module = THIS_MODULE;
family->ops = ops;
family->n_ops = n_ops;
family->mcgrps = mcgrps;
family->n_mcgrps = n_mcgrps;
return __genl_register_family(family);
}

#define genl_register_family_with_ops(family, ops) \
_genl_register_family_with_ops_grps((family), \
(ops), ARRAY_SIZE(ops), \
NULL, 0)
#define genl_register_family_with_ops_groups(family, ops, grps) \
_genl_register_family_with_ops_grps((family), \
(ops), ARRAY_SIZE(ops), \
(grps), ARRAY_SIZE(grps))

int genl_register_family(struct genl_family *family);
int genl_unregister_family(struct genl_family *family);
void genl_notify(struct genl_family *family, struct sk_buff *skb,
struct genl_info *info, u32 group, gfp_t flags);
Expand Down
Loading

0 comments on commit 489111e

Please sign in to comment.