Commit ee775b56 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by David S. Miller

devlink: Simplify internal devlink params implementation

Reduce extra indirection from devlink_params_*() API. Such change
makes it clear that we can drop devlink->lock from these flows, because
everything is executed when the devlink is not registered yet.
Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b0e77fcc
...@@ -4925,45 +4925,6 @@ static int devlink_nl_cmd_param_set_doit(struct sk_buff *skb, ...@@ -4925,45 +4925,6 @@ static int devlink_nl_cmd_param_set_doit(struct sk_buff *skb,
info, DEVLINK_CMD_PARAM_NEW); info, DEVLINK_CMD_PARAM_NEW);
} }
static int devlink_param_register_one(struct devlink *devlink,
unsigned int port_index,
struct list_head *param_list,
const struct devlink_param *param,
enum devlink_command cmd)
{
struct devlink_param_item *param_item;
if (devlink_param_find_by_name(param_list, param->name))
return -EEXIST;
if (param->supported_cmodes == BIT(DEVLINK_PARAM_CMODE_DRIVERINIT))
WARN_ON(param->get || param->set);
else
WARN_ON(!param->get || !param->set);
param_item = kzalloc(sizeof(*param_item), GFP_KERNEL);
if (!param_item)
return -ENOMEM;
param_item->param = param;
list_add_tail(&param_item->list, param_list);
return 0;
}
static void devlink_param_unregister_one(struct devlink *devlink,
unsigned int port_index,
struct list_head *param_list,
const struct devlink_param *param,
enum devlink_command cmd)
{
struct devlink_param_item *param_item;
param_item = devlink_param_find_by_name(param_list, param->name);
WARN_ON(!param_item);
list_del(&param_item->list);
kfree(param_item);
}
static int devlink_nl_cmd_port_param_get_dumpit(struct sk_buff *msg, static int devlink_nl_cmd_port_param_get_dumpit(struct sk_buff *msg,
struct netlink_callback *cb) struct netlink_callback *cb)
{ {
...@@ -10092,73 +10053,6 @@ static int devlink_param_verify(const struct devlink_param *param) ...@@ -10092,73 +10053,6 @@ static int devlink_param_verify(const struct devlink_param *param)
return devlink_param_driver_verify(param); return devlink_param_driver_verify(param);
} }
static int __devlink_param_register_one(struct devlink *devlink,
unsigned int port_index,
struct list_head *param_list,
const struct devlink_param *param,
enum devlink_command reg_cmd)
{
int err;
err = devlink_param_verify(param);
if (err)
return err;
return devlink_param_register_one(devlink, port_index,
param_list, param, reg_cmd);
}
static int __devlink_params_register(struct devlink *devlink,
unsigned int port_index,
struct list_head *param_list,
const struct devlink_param *params,
size_t params_count,
enum devlink_command reg_cmd,
enum devlink_command unreg_cmd)
{
const struct devlink_param *param = params;
int i;
int err;
mutex_lock(&devlink->lock);
for (i = 0; i < params_count; i++, param++) {
err = __devlink_param_register_one(devlink, port_index,
param_list, param, reg_cmd);
if (err)
goto rollback;
}
mutex_unlock(&devlink->lock);
return 0;
rollback:
if (!i)
goto unlock;
for (param--; i > 0; i--, param--)
devlink_param_unregister_one(devlink, port_index, param_list,
param, unreg_cmd);
unlock:
mutex_unlock(&devlink->lock);
return err;
}
static void __devlink_params_unregister(struct devlink *devlink,
unsigned int port_index,
struct list_head *param_list,
const struct devlink_param *params,
size_t params_count,
enum devlink_command cmd)
{
const struct devlink_param *param = params;
int i;
mutex_lock(&devlink->lock);
for (i = 0; i < params_count; i++, param++)
devlink_param_unregister_one(devlink, 0, param_list, param,
cmd);
mutex_unlock(&devlink->lock);
}
/** /**
* devlink_params_register - register configuration parameters * devlink_params_register - register configuration parameters
* *
...@@ -10172,12 +10066,25 @@ int devlink_params_register(struct devlink *devlink, ...@@ -10172,12 +10066,25 @@ int devlink_params_register(struct devlink *devlink,
const struct devlink_param *params, const struct devlink_param *params,
size_t params_count) size_t params_count)
{ {
const struct devlink_param *param = params;
int i, err;
ASSERT_DEVLINK_NOT_REGISTERED(devlink); ASSERT_DEVLINK_NOT_REGISTERED(devlink);
return __devlink_params_register(devlink, 0, &devlink->param_list, for (i = 0; i < params_count; i++, param++) {
params, params_count, err = devlink_param_register(devlink, param);
DEVLINK_CMD_PARAM_NEW, if (err)
DEVLINK_CMD_PARAM_DEL); goto rollback;
}
return 0;
rollback:
if (!i)
return err;
for (param--; i > 0; i--, param--)
devlink_param_unregister(devlink, param);
return err;
} }
EXPORT_SYMBOL_GPL(devlink_params_register); EXPORT_SYMBOL_GPL(devlink_params_register);
...@@ -10191,11 +10098,13 @@ void devlink_params_unregister(struct devlink *devlink, ...@@ -10191,11 +10098,13 @@ void devlink_params_unregister(struct devlink *devlink,
const struct devlink_param *params, const struct devlink_param *params,
size_t params_count) size_t params_count)
{ {
const struct devlink_param *param = params;
int i;
ASSERT_DEVLINK_NOT_REGISTERED(devlink); ASSERT_DEVLINK_NOT_REGISTERED(devlink);
return __devlink_params_unregister(devlink, 0, &devlink->param_list, for (i = 0; i < params_count; i++, param++)
params, params_count, devlink_param_unregister(devlink, param);
DEVLINK_CMD_PARAM_DEL);
} }
EXPORT_SYMBOL_GPL(devlink_params_unregister); EXPORT_SYMBOL_GPL(devlink_params_unregister);
...@@ -10211,15 +10120,26 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister); ...@@ -10211,15 +10120,26 @@ EXPORT_SYMBOL_GPL(devlink_params_unregister);
int devlink_param_register(struct devlink *devlink, int devlink_param_register(struct devlink *devlink,
const struct devlink_param *param) const struct devlink_param *param)
{ {
int err; struct devlink_param_item *param_item;
ASSERT_DEVLINK_NOT_REGISTERED(devlink); ASSERT_DEVLINK_NOT_REGISTERED(devlink);
mutex_lock(&devlink->lock); WARN_ON(devlink_param_verify(param));
err = __devlink_param_register_one(devlink, 0, &devlink->param_list, WARN_ON(devlink_param_find_by_name(&devlink->param_list, param->name));
param, DEVLINK_CMD_PARAM_NEW);
mutex_unlock(&devlink->lock); if (param->supported_cmodes == BIT(DEVLINK_PARAM_CMODE_DRIVERINIT))
return err; WARN_ON(param->get || param->set);
else
WARN_ON(!param->get || !param->set);
param_item = kzalloc(sizeof(*param_item), GFP_KERNEL);
if (!param_item)
return -ENOMEM;
param_item->param = param;
list_add_tail(&param_item->list, &devlink->param_list);
return 0;
} }
EXPORT_SYMBOL_GPL(devlink_param_register); EXPORT_SYMBOL_GPL(devlink_param_register);
...@@ -10231,12 +10151,15 @@ EXPORT_SYMBOL_GPL(devlink_param_register); ...@@ -10231,12 +10151,15 @@ EXPORT_SYMBOL_GPL(devlink_param_register);
void devlink_param_unregister(struct devlink *devlink, void devlink_param_unregister(struct devlink *devlink,
const struct devlink_param *param) const struct devlink_param *param)
{ {
struct devlink_param_item *param_item;
ASSERT_DEVLINK_NOT_REGISTERED(devlink); ASSERT_DEVLINK_NOT_REGISTERED(devlink);
mutex_lock(&devlink->lock); param_item =
devlink_param_unregister_one(devlink, 0, &devlink->param_list, param, devlink_param_find_by_name(&devlink->param_list, param->name);
DEVLINK_CMD_PARAM_DEL); WARN_ON(!param_item);
mutex_unlock(&devlink->lock); list_del(&param_item->list);
kfree(param_item);
} }
EXPORT_SYMBOL_GPL(devlink_param_unregister); EXPORT_SYMBOL_GPL(devlink_param_unregister);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment