Skip to contentSkip to conversation

net/mlx4_core: Fix error handling in mlx4_init_port_info.

PATCH Superseded Tarick Bedeir 3 participants 3 messages Apr 27, 2018 – May 13, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx4_core: Fix error handling in mlx4_init_port_info.

Avoid exiting the function with a lingering sysfs file (if the first call to device_create_file() fails while the second succeeds), and avoid calling devlink_port_unregister() twice.

In other words, either mlx4_init_port_info() succeeds and returns zero, or it fails, returns non-zero, and requires no cleanup.

---
 drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/main.c +3 -1
index 4d84cab77105..e8a3a45d0b53 100644
@@ -3007,6 +3007,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
 		mlx4_err(dev, "Failed to create file for port %d\n", port);
 		devlink_port_unregister(&info->devlink_port);
 		info->port = -1;
+		return err;
 	}
 
 	sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
@@ -3028,9 +3029,10 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
 				   &info->port_attr);
 		devlink_port_unregister(&info->devlink_port);
 		info->port = -1;
+		return err;
 	}
 
-	return err;
+	return 0;
 }
 
 static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 27 lines · Tarick Bedeir

Avoid exiting the function with a lingering sysfs file (if the first call to device_create_file() fails while the second succeeds), and avoid calling devlink_port_unregister() twice.

In other words, either mlx4_init_port_info() succeeds and returns zero, or it fails, returns non-zero, and requires no cleanup.

---
  drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/main.c +1 -0
index 4d84cab77105..e8a3a45d0b53 100644
@@ -3007,6 +3007,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  		mlx4_err(dev, "Failed to create file for port %d\n", port);
  		devlink_port_unregister(&info->devlink_port);
  		info->port = -1;
+		return err;
  	}
 
  	sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
@@ -3028,9 +3029,10 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  				   &info->port_attr);

drivers/net/ethernet/mellanox/mlx4/main.c static int mlx4_init_port_info(struct mlx4_dev *dev, int port) · line 3038

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/main.c +2 -1
  		devlink_port_unregister(&info->devlink_port);
  		info->port = -1;
+		return err;
  	}
 
-	return err;
+	return 0;
  }
 
  static void mlx4_cleanup_port_info(struct mlx4_port_info *info)

Thanks Tarick.

#2 lore raw
Quoted 41 lines · Tariq Toukan
Quoted 26 lines · Tarick Bedeir

Avoid exiting the function with a lingering sysfs file (if the first call to device_create_file() fails while the second succeeds), and avoid calling devlink_port_unregister() twice.

In other words, either mlx4_init_port_info() succeeds and returns zero, or it fails, returns non-zero, and requires no cleanup.

---
  drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx4/main.c +1 -0
index 4d84cab77105..e8a3a45d0b53 100644
@@ -3007,6 +3007,7 @@ static int mlx4_init_port_info(struct mlx4_dev 
 *dev, int port)
           mlx4_err(dev, "Failed to create file for port %d\n", port);
           devlink_port_unregister(&info->devlink_port);
           info->port = -1;
+        return err;
       }
       sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
@@ -3028,9 +3029,10 @@ static int mlx4_init_port_info(struct mlx4_dev 
 *dev, int port)

drivers/net/ethernet/mellanox/mlx4/main.c static int mlx4_init_port_info(struct mlx4_dev · line 3038

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx4/main.c +2 -1
                      &info->port_attr);
           devlink_port_unregister(&info->devlink_port);
           info->port = -1;
+        return err;
       }
-    return err;
+    return 0;
   }
   static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
 
Quoted 1 line

Thanks Tarick.

Actually, you need to add a Fixes line:

Fixes 096335b3f983 ("mlx4_core: Allow dynamic MTU configuration for IB ports")