Skip to contentSkip to conversation

mlx4: FIX error flow when initializing EQ table

PATCH Applied Yevgeny Petrilin 3 participants 4 messages Jun 7, 2009 – Jun 10, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mlx4: FIX error flow when initializing EQ table

If mlx4_create_eq() would fail for one of EQ's assigned for completion handling, the code would try to free the same EQ we failed to create.
The crash was found by Christoph Lameter

---
 drivers/net/mlx4/eq.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/net/mlx4/eq.c +3 -1
index 8830dcb..dee1887 100644
@@ -623,8 +623,10 @@ int mlx4_init_eq_table(struct mlx4_dev *dev)
 		err = mlx4_create_eq(dev, dev->caps.num_cqs + MLX4_NUM_SPARE_EQE,
 				     (dev->flags & MLX4_FLAG_MSI_X) ? i : 0,
 				     &priv->eq_table.eq[i]);
-		if (err)
+		if (err) {
+			--i;
 			goto err_out_unmap;
+		}
 	}
 
 	err = mlx4_create_eq(dev, MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
Signature · 1 line
1.6.1.3
maintainer Applied
#1 lore raw

From: Yevgeny Petrilin <[email protected]>
Date: Sun, 07 Jun 2009 18:16:09 +0300

Quoted 6 lines

If mlx4_create_eq() would fail for one of EQ's assigned for completion handling, the code would try to free the same EQ we failed to create.
The crash was found by Christoph Lameter

Applied, thanks.

#2 lore raw
In reply to Yevgeny Petrilin
Quoted 5 lines

If mlx4_create_eq() would fail for one of EQ's assigned for completion handling, the code would try to free the same EQ we failed to create.
The crash was found by Christoph Lameter

Thanks, good catch. However looking at the code it seems that a simpler way to fix this would be as below. Can you confirm that this works too?

---
 drivers/net/mlx4/eq.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx4/eq.c +3 -3
index 8830dcb..033817e 100644
@@ -677,12 +677,12 @@ err_out_async:
 	mlx4_free_eq(dev, &priv->eq_table.eq[dev->caps.num_comp_vectors]);
 
 err_out_comp:
-	i = dev->caps.num_comp_vectors - 1;
+	i = dev->caps.num_comp_vectors;
 
 err_out_unmap:
-	while (i >= 0) {
-		mlx4_free_eq(dev, &priv->eq_table.eq[i]);
+	while (i > 0) {
 		--i;
+		mlx4_free_eq(dev, &priv->eq_table.eq[i]);
 	}
 	mlx4_unmap_clr_int(dev);
 	mlx4_free_irqs(dev);
#3 lore raw
Quoted 22 lines · Roland Dreier
Quoted 4 lines

If mlx4_create_eq() would fail for one of EQ's assigned for completion handling, the code would try to free the same EQ we failed to create.
The crash was found by Christoph Lameter

Thanks, good catch. However looking at the code it seems that a simpler way to fix this would be as below. Can you confirm that this works too?

---
 drivers/net/mlx4/eq.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx4/eq.c +1 -1
index 8830dcb..033817e 100644
@@ -677,12 +677,12 @@ err_out_async:
 	mlx4_free_eq(dev, &priv->eq_table.eq[dev->caps.num_comp_vectors]);
 
 err_out_comp:
-	i = dev->caps.num_comp_vectors - 1;
+	i = dev->caps.num_comp_vectors;

drivers/net/mlx4/eq.c err_out_async: · line 688

Quoted 10 lines
drivers/net/mlx4/eq.c +2 -2
 
 err_out_unmap:
-	while (i >= 0) {
-		mlx4_free_eq(dev, &priv->eq_table.eq[i]);
+	while (i > 0) {
 		--i;
+		mlx4_free_eq(dev, &priv->eq_table.eq[i]);
 	}
 	mlx4_unmap_clr_int(dev);
 	mlx4_free_irqs(dev);

Yes, it also works
Yevgeny