Commit 6132c1d9 authored by Madhuparna Bhowmik's avatar Madhuparna Bhowmik Committed by David S. Miller

net: core: devlink.c: Hold devlink->lock from the beginning of devlink_dpipe_table_register()

devlink_dpipe_table_find() should be called under either
rcu_read_lock() or devlink->lock. devlink_dpipe_table_register()
calls devlink_dpipe_table_find() without holding the lock
and acquires it later. Therefore hold the devlink->lock
from the beginning of devlink_dpipe_table_register().
Suggested-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarMadhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 503ba7c6
...@@ -6878,26 +6878,33 @@ int devlink_dpipe_table_register(struct devlink *devlink, ...@@ -6878,26 +6878,33 @@ int devlink_dpipe_table_register(struct devlink *devlink,
void *priv, bool counter_control_extern) void *priv, bool counter_control_extern)
{ {
struct devlink_dpipe_table *table; struct devlink_dpipe_table *table;
int err = 0;
if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name))
return -EEXIST;
if (WARN_ON(!table_ops->size_get)) if (WARN_ON(!table_ops->size_get))
return -EINVAL; return -EINVAL;
mutex_lock(&devlink->lock);
if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name)) {
err = -EEXIST;
goto unlock;
}
table = kzalloc(sizeof(*table), GFP_KERNEL); table = kzalloc(sizeof(*table), GFP_KERNEL);
if (!table) if (!table) {
return -ENOMEM; err = -ENOMEM;
goto unlock;
}
table->name = table_name; table->name = table_name;
table->table_ops = table_ops; table->table_ops = table_ops;
table->priv = priv; table->priv = priv;
table->counter_control_extern = counter_control_extern; table->counter_control_extern = counter_control_extern;
mutex_lock(&devlink->lock);
list_add_tail_rcu(&table->list, &devlink->dpipe_table_list); list_add_tail_rcu(&table->list, &devlink->dpipe_table_list);
unlock:
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
return 0; return err;
} }
EXPORT_SYMBOL_GPL(devlink_dpipe_table_register); EXPORT_SYMBOL_GPL(devlink_dpipe_table_register);
......
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