#include <linux/list.h>
#include <linux/rhashtable.h>
#include <linux/netdevice.h>
+#include <linux/mutex.h>
#include <trace/events/mlxsw.h>
#include "reg.h"
struct mlxsw_sp_acl_tcam_group {
struct mlxsw_sp_acl_tcam *tcam;
u16 id;
+ struct mutex lock; /* guards region list updates */
struct list_head region_list;
unsigned int region_count;
};
int err;
group->tcam = tcam;
+ mutex_init(&group->lock);
INIT_LIST_HEAD(&group->region_list);
err = mlxsw_sp_acl_tcam_group_id_get(tcam, &group->id);
{
struct mlxsw_sp_acl_tcam *tcam = group->tcam;
+ mutex_destroy(&group->lock);
mlxsw_sp_acl_tcam_group_id_put(tcam, group->id);
WARN_ON(!list_empty(&group->region_list));
}
struct list_head *pos;
int err;
- if (group->region_count == group->tcam->max_group_size)
- return -ENOBUFS;
+ mutex_lock(&group->lock);
+ if (group->region_count == group->tcam->max_group_size) {
+ err = -ENOBUFS;
+ goto err_region_count_check;
+ }
if (next_region) {
/* If the next region is defined, place the new one
goto err_group_update;
group->region_count++;
+ mutex_unlock(&group->lock);
return 0;
err_group_update:
list_del(®ion->list);
+err_region_count_check:
+ mutex_unlock(&group->lock);
return err;
}
{
struct mlxsw_sp_acl_tcam_group *group = region->group;
+ mutex_lock(&group->lock);
list_del(®ion->list);
group->region_count--;
mlxsw_sp_acl_tcam_group_update(mlxsw_sp, group);
+ mutex_unlock(&group->lock);
}
static int