Commit 68297dbb authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by Jakub Kicinski
Browse files

rtnetlink: Remove __rtnl_link_register()



link_ops is protected by link_ops_mutex and no longer needs RTNL,
so we have no reason to have __rtnl_link_register() separately.

Let's remove it and call rtnl_link_register() from ifb.ko and
dummy.ko.

Note that both modules' init() work on init_net only, so we need
not export pernet_ops_rwsem and can use rtnl_net_lock() there.

Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20241108004823.29419-4-kuniyu@amazon.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 6b57ff21
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -166,27 +166,22 @@ static int __init dummy_init_one(void)

static int __init dummy_init_module(void)
{
	bool need_unregister = false;
	int i, err = 0;

	down_write(&pernet_ops_rwsem);
	rtnl_lock();
	err = __rtnl_link_register(&dummy_link_ops);
	err = rtnl_link_register(&dummy_link_ops);
	if (err < 0)
		goto out;
		return err;

	rtnl_net_lock(&init_net);

	for (i = 0; i < numdummies && !err; i++) {
		err = dummy_init_one();
		cond_resched();
	}
	if (err < 0)
		need_unregister = true;

out:
	rtnl_unlock();
	up_write(&pernet_ops_rwsem);
	rtnl_net_unlock(&init_net);

	if (need_unregister)
	if (err < 0)
		rtnl_link_unregister(&dummy_link_ops);

	return err;
+6 −11
Original line number Diff line number Diff line
@@ -424,27 +424,22 @@ static int __init ifb_init_one(int index)

static int __init ifb_init_module(void)
{
	bool need_unregister = false;
	int i, err;

	down_write(&pernet_ops_rwsem);
	rtnl_lock();
	err = __rtnl_link_register(&ifb_link_ops);
	err = rtnl_link_register(&ifb_link_ops);
	if (err < 0)
		goto out;
		return err;

	rtnl_net_lock(&init_net);

	for (i = 0; i < numifbs && !err; i++) {
		err = ifb_init_one(i);
		cond_resched();
	}
	if (err)
		need_unregister = true;

out:
	rtnl_unlock();
	up_write(&pernet_ops_rwsem);
	rtnl_net_unlock(&init_net);

	if (need_unregister)
	if (err)
		rtnl_link_unregister(&ifb_link_ops);

	return err;
+0 −2
Original line number Diff line number Diff line
@@ -164,8 +164,6 @@ struct rtnl_link_ops {
						   int *prividx, int attr);
};

int __rtnl_link_register(struct rtnl_link_ops *ops);

int rtnl_link_register(struct rtnl_link_ops *ops);
void rtnl_link_unregister(struct rtnl_link_ops *ops);

+0 −1
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ static bool init_net_initialized;
 * outside.
 */
DECLARE_RWSEM(pernet_ops_rwsem);
EXPORT_SYMBOL_GPL(pernet_ops_rwsem);

#define MIN_PERNET_OPS_ID	\
	((sizeof(struct net_generic) + sizeof(void *) - 1) / sizeof(void *))
+7 −28
Original line number Diff line number Diff line
@@ -495,20 +495,21 @@ static void rtnl_link_ops_put(struct rtnl_link_ops *ops, int srcu_index)
}

/**
 * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
 * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
 * @ops: struct rtnl_link_ops * to register
 *
 * The caller must hold the rtnl_mutex. This function should be used
 * by drivers that create devices during module initialization. It
 * must be called before registering the devices.
 *
 * Returns 0 on success or a negative error code.
 */
int __rtnl_link_register(struct rtnl_link_ops *ops)
int rtnl_link_register(struct rtnl_link_ops *ops)
{
	struct rtnl_link_ops *tmp;
	int err;

	/* Sanity-check max sizes to avoid stack buffer overflow. */
	if (WARN_ON(ops->maxtype > RTNL_MAX_TYPE ||
		    ops->slave_maxtype > RTNL_SLAVE_MAX_TYPE))
		return -EINVAL;

	/* The check for alloc/setup is here because if ops
	 * does not have that filled up, it is not possible
	 * to use the ops for creating device. So do not
@@ -536,28 +537,6 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)

	return err;
}
EXPORT_SYMBOL_GPL(__rtnl_link_register);

/**
 * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
 * @ops: struct rtnl_link_ops * to register
 *
 * Returns 0 on success or a negative error code.
 */
int rtnl_link_register(struct rtnl_link_ops *ops)
{
	int err;

	/* Sanity-check max sizes to avoid stack buffer overflow. */
	if (WARN_ON(ops->maxtype > RTNL_MAX_TYPE ||
		    ops->slave_maxtype > RTNL_SLAVE_MAX_TYPE))
		return -EINVAL;

	rtnl_lock();
	err = __rtnl_link_register(ops);
	rtnl_unlock();
	return err;
}
EXPORT_SYMBOL_GPL(rtnl_link_register);

static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)