Commit 0a984556 authored by Amir Vadai's avatar Amir Vadai Committed by David S. Miller

net/mlx4_core: Protect port type setting by mutex

We need to protect set_port_type() for concurrency, as the sysfs code could
call it from mutliple contexts in parallel.

The port_mutex is not enough because we need to protect from concurrent
modification of 'info' and stopping of the port sensing work.
Signed-off-by: default avatarAmir Vadai <amirv@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6e806699
...@@ -901,9 +901,12 @@ static ssize_t set_port_type(struct device *dev, ...@@ -901,9 +901,12 @@ static ssize_t set_port_type(struct device *dev,
struct mlx4_priv *priv = mlx4_priv(mdev); struct mlx4_priv *priv = mlx4_priv(mdev);
enum mlx4_port_type types[MLX4_MAX_PORTS]; enum mlx4_port_type types[MLX4_MAX_PORTS];
enum mlx4_port_type new_types[MLX4_MAX_PORTS]; enum mlx4_port_type new_types[MLX4_MAX_PORTS];
static DEFINE_MUTEX(set_port_type_mutex);
int i; int i;
int err = 0; int err = 0;
mutex_lock(&set_port_type_mutex);
if (!strcmp(buf, "ib\n")) if (!strcmp(buf, "ib\n"))
info->tmp_type = MLX4_PORT_TYPE_IB; info->tmp_type = MLX4_PORT_TYPE_IB;
else if (!strcmp(buf, "eth\n")) else if (!strcmp(buf, "eth\n"))
...@@ -912,7 +915,8 @@ static ssize_t set_port_type(struct device *dev, ...@@ -912,7 +915,8 @@ static ssize_t set_port_type(struct device *dev,
info->tmp_type = MLX4_PORT_TYPE_AUTO; info->tmp_type = MLX4_PORT_TYPE_AUTO;
else { else {
mlx4_err(mdev, "%s is not supported port type\n", buf); mlx4_err(mdev, "%s is not supported port type\n", buf);
return -EINVAL; err = -EINVAL;
goto err_out;
} }
mlx4_stop_sense(mdev); mlx4_stop_sense(mdev);
...@@ -958,6 +962,9 @@ static ssize_t set_port_type(struct device *dev, ...@@ -958,6 +962,9 @@ static ssize_t set_port_type(struct device *dev,
out: out:
mlx4_start_sense(mdev); mlx4_start_sense(mdev);
mutex_unlock(&priv->port_mutex); mutex_unlock(&priv->port_mutex);
err_out:
mutex_unlock(&set_port_type_mutex);
return err ? err : count; return err ? err : count;
} }
......
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