Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c53ed742 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller
Browse files

genetlink: only pass array to genl_register_family_with_ops()



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: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dbde4979
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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;

+1 −2
Original line number Diff line number Diff line
@@ -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;

+6 −4
Original line number Diff line number Diff line
@@ -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 = {
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)
+1 −2
Original line number Diff line number Diff line
@@ -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
+6 −2
Original line number Diff line number Diff line
@@ -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);
Loading