Commit 4fb09a87 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'genetlink'



Johannes Berg says:

====================
genetlink: reduce ops size and complexity (v2)

As before - reduce the complexity and data/code size of genetlink ops
by making them an array rather than a linked list. Most users already
use an array thanks to genl_register_family_with_ops(), so convert the
remaining ones allowing us to get rid of the list head in each op.

Also make them const, this just makes sense at that point and the security
people like making function pointers const as well :-)
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 1e9f3d6f 3f5ccd06
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2644,7 +2644,7 @@ static int team_nl_cmd_port_list_get(struct sk_buff *skb,
	return err;
}

static struct genl_ops team_nl_ops[] = {
static const struct genl_ops team_nl_ops[] = {
	{
		.cmd = TEAM_CMD_NOOP,
		.doit = team_nl_cmd_noop,
+1 −1
Original line number Diff line number Diff line
@@ -2097,7 +2097,7 @@ out:
}

/* Generic Netlink operations array */
static struct genl_ops hwsim_ops[] = {
static const struct genl_ops hwsim_ops[] = {
	{
		.cmd = HWSIM_CMD_REGISTER,
		.policy = hwsim_genl_policy,
+11 −12
Original line number Diff line number Diff line
@@ -39,9 +39,10 @@ struct genl_info;
 * @post_doit: called after an operation's doit callback, it may
 *	undo operations done by pre_doit, for example release locks
 * @attrbuf: buffer to store parsed attributes
 * @ops_list: list of all assigned operations
 * @family_list: family list
 * @mcast_groups: multicast groups list
 * @ops: the operations supported by this family (private)
 * @n_ops: number of operations supported by this family (private)
 */
struct genl_family {
	unsigned int		id;
@@ -51,14 +52,15 @@ struct genl_family {
	unsigned int		maxattr;
	bool			netnsok;
	bool			parallel_ops;
	int			(*pre_doit)(struct genl_ops *ops,
	int			(*pre_doit)(const struct genl_ops *ops,
					    struct sk_buff *skb,
					    struct genl_info *info);
	void			(*post_doit)(struct genl_ops *ops,
	void			(*post_doit)(const struct genl_ops *ops,
					     struct sk_buff *skb,
					     struct genl_info *info);
	struct nlattr **	attrbuf;	/* private */
	struct list_head	ops_list;	/* private */
	const struct genl_ops *	ops;		/* private */
	unsigned int		n_ops;		/* private */
	struct list_head	family_list;	/* private */
	struct list_head	mcast_groups;	/* private */
	struct module		*module;
@@ -110,16 +112,15 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
 * @ops_list: operations list
 */
struct genl_ops {
	u8			cmd;
	u8			internal_flags;
	unsigned int		flags;
	const struct nla_policy	*policy;
	int		       (*doit)(struct sk_buff *skb,
				       struct genl_info *info);
	int		       (*dumpit)(struct sk_buff *skb,
					 struct netlink_callback *cb);
	int		       (*done)(struct netlink_callback *cb);
	struct list_head	ops_list;
	u8			cmd;
	u8			internal_flags;
	u8			flags;
};

int __genl_register_family(struct genl_family *family);
@@ -131,18 +132,16 @@ static inline int genl_register_family(struct genl_family *family)
}

int __genl_register_family_with_ops(struct genl_family *family,
				    struct genl_ops *ops, size_t n_ops);
				    const struct genl_ops *ops, size_t n_ops);

static inline int genl_register_family_with_ops(struct genl_family *family,
	struct genl_ops *ops, size_t n_ops)
	const struct genl_ops *ops, size_t n_ops)
{
	family->module = THIS_MODULE;
	return __genl_register_family_with_ops(family, ops, n_ops);
}

int genl_unregister_family(struct genl_family *family);
int genl_register_ops(struct genl_family *, struct genl_ops *ops);
int genl_unregister_ops(struct genl_family *, struct genl_ops *ops);
int genl_register_mc_group(struct genl_family *family,
			   struct genl_multicast_group *grp);
void genl_unregister_mc_group(struct genl_family *family,
+14 −25
Original line number Diff line number Diff line
@@ -673,17 +673,18 @@ err:
	nlmsg_free(rep_skb);
}

static struct genl_ops taskstats_ops = {
static const struct genl_ops taskstats_ops[] = {
	{
		.cmd		= TASKSTATS_CMD_GET,
		.doit		= taskstats_user_cmd,
		.policy		= taskstats_cmd_get_policy,
		.flags		= GENL_ADMIN_PERM,
};

static struct genl_ops cgroupstats_ops = {
	},
	{
		.cmd		= CGROUPSTATS_CMD_GET,
		.doit		= cgroupstats_user_cmd,
		.policy		= cgroupstats_cmd_get_policy,
	},
};

/* Needed early in initialization */
@@ -702,26 +703,14 @@ static int __init taskstats_init(void)
{
	int rc;

	rc = genl_register_family(&family);
	rc = genl_register_family_with_ops(&family, taskstats_ops,
					   ARRAY_SIZE(taskstats_ops));
	if (rc)
		return rc;

	rc = genl_register_ops(&family, &taskstats_ops);
	if (rc < 0)
		goto err;

	rc = genl_register_ops(&family, &cgroupstats_ops);
	if (rc < 0)
		goto err_cgroup_ops;

	family_registered = 1;
	pr_info("registered taskstats version %d\n", TASKSTATS_GENL_VERSION);
	return 0;
err_cgroup_ops:
	genl_unregister_ops(&family, &taskstats_ops);
err:
	genl_unregister_family(&family);
	return rc;
}

/*
+1 −1
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ out:
	return NOTIFY_DONE;
}

static struct genl_ops dropmon_ops[] = {
static const struct genl_ops dropmon_ops[] = {
	{
		.cmd = NET_DM_CMD_CONFIG,
		.doit = net_dm_cmd_config,
Loading