Skip to content

Commit

Permalink
net: core: devlink.c: Hold devlink->lock from the beginning of devlin…
Browse files Browse the repository at this point in the history
…k_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: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Madhuparna Bhowmik authored and David S. Miller committed Feb 24, 2020
1 parent 503ba7c commit 6132c1d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -6878,26 +6878,33 @@ int devlink_dpipe_table_register(struct devlink *devlink,
void *priv, bool counter_control_extern)
{
struct devlink_dpipe_table *table;

if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name))
return -EEXIST;
int err = 0;

if (WARN_ON(!table_ops->size_get))
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);
if (!table)
return -ENOMEM;
if (!table) {
err = -ENOMEM;
goto unlock;
}

table->name = table_name;
table->table_ops = table_ops;
table->priv = priv;
table->counter_control_extern = counter_control_extern;

mutex_lock(&devlink->lock);
list_add_tail_rcu(&table->list, &devlink->dpipe_table_list);
unlock:
mutex_unlock(&devlink->lock);
return 0;
return err;
}
EXPORT_SYMBOL_GPL(devlink_dpipe_table_register);

Expand Down

0 comments on commit 6132c1d

Please sign in to comment.