diff options
author | Amir Vadai <amirv@mellanox.com> | 2014-11-02 09:26:14 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-11-03 12:28:13 -0500 |
commit | 0a98455666ec87378148a1dde97f1ce5baf75a64 (patch) | |
tree | bfba09b40f2718ed459973f8673efe5acb3f9d8a | |
parent | 6e8066999800d90d52af5c84ac49ebf683d14cdc (diff) |
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: Amir Vadai <amirv@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx4/main.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index 90de6e1ad06e..9f821964a1b9 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c | |||
@@ -901,9 +901,12 @@ static ssize_t set_port_type(struct device *dev, | |||
901 | struct mlx4_priv *priv = mlx4_priv(mdev); | 901 | struct mlx4_priv *priv = mlx4_priv(mdev); |
902 | enum mlx4_port_type types[MLX4_MAX_PORTS]; | 902 | enum mlx4_port_type types[MLX4_MAX_PORTS]; |
903 | enum mlx4_port_type new_types[MLX4_MAX_PORTS]; | 903 | enum mlx4_port_type new_types[MLX4_MAX_PORTS]; |
904 | static DEFINE_MUTEX(set_port_type_mutex); | ||
904 | int i; | 905 | int i; |
905 | int err = 0; | 906 | int err = 0; |
906 | 907 | ||
908 | mutex_lock(&set_port_type_mutex); | ||
909 | |||
907 | if (!strcmp(buf, "ib\n")) | 910 | if (!strcmp(buf, "ib\n")) |
908 | info->tmp_type = MLX4_PORT_TYPE_IB; | 911 | info->tmp_type = MLX4_PORT_TYPE_IB; |
909 | else if (!strcmp(buf, "eth\n")) | 912 | else if (!strcmp(buf, "eth\n")) |
@@ -912,7 +915,8 @@ static ssize_t set_port_type(struct device *dev, | |||
912 | info->tmp_type = MLX4_PORT_TYPE_AUTO; | 915 | info->tmp_type = MLX4_PORT_TYPE_AUTO; |
913 | else { | 916 | else { |
914 | mlx4_err(mdev, "%s is not supported port type\n", buf); | 917 | mlx4_err(mdev, "%s is not supported port type\n", buf); |
915 | return -EINVAL; | 918 | err = -EINVAL; |
919 | goto err_out; | ||
916 | } | 920 | } |
917 | 921 | ||
918 | mlx4_stop_sense(mdev); | 922 | mlx4_stop_sense(mdev); |
@@ -958,6 +962,9 @@ static ssize_t set_port_type(struct device *dev, | |||
958 | out: | 962 | out: |
959 | mlx4_start_sense(mdev); | 963 | mlx4_start_sense(mdev); |
960 | mutex_unlock(&priv->port_mutex); | 964 | mutex_unlock(&priv->port_mutex); |
965 | err_out: | ||
966 | mutex_unlock(&set_port_type_mutex); | ||
967 | |||
961 | return err ? err : count; | 968 | return err ? err : count; |
962 | } | 969 | } |
963 | 970 | ||