Skip to contentSkip to conversation

net/mlx5e: kTLS, Simplify error unwind in mlx5e_ktls_set_feature_rx()

PATCH In review Xuanqiang Luo 3 participants 3 messages Nov 18

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

PATCH v2 1/1 net/mlx5e: kTLS, Simplify error unwind in mlx5e_ktls_set_feature_rx()

From: Xuanqiang Luo <[email protected]>

mlx5e_ktls_set_feature_rx() has become harder to follow: the error handling is nested in the conditions and the main flow is conditional.

Handle the disable case first, handle the error cases in conditionals, and keep the main flow unconditional. Use goto to unlock on the early returns.

No functional change intended.

---
Changes:
v2:
- Handle the disable case first and keep the enable argument unchanged, instead of reusing it as a flag to destroy the tables. (Suggested by Tariq.)

v1: https://lore.kernel.org/all/[email protected]/

 .../mellanox/mlx5/core/en_accel/ktls.c        | 27 ++++++++++---------
 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +15 -12
index 3cc1213c2f68..2358ad1f2331 100644
@@ -135,21 +135,24 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)
 	int err = 0;
 
 	mutex_lock(&priv->state_lock);
-	if (enable) {
-		err = mlx5e_accel_fs_tcp_create(priv->fs);
-		if (!err && !priv->ktls_rx_was_enabled) {
-			priv->ktls_rx_was_enabled = true;
-			err = mlx5e_safe_reopen_channels(priv);
-			if (err) {
-				priv->ktls_rx_was_enabled = false;
-				mlx5e_accel_fs_tcp_destroy(priv->fs);
-			}
-		}
-	} else {
+	if (!enable) {
 		mlx5e_accel_fs_tcp_destroy(priv->fs);
+		goto out_unlock;
 	}
-	mutex_unlock(&priv->state_lock);
 
+	err = mlx5e_accel_fs_tcp_create(priv->fs);
+	if (err || priv->ktls_rx_was_enabled)
+		goto out_unlock;
+
+	priv->ktls_rx_was_enabled = true;
+	err = mlx5e_safe_reopen_channels(priv);
+	if (err) {
+		priv->ktls_rx_was_enabled = false;
+		mlx5e_accel_fs_tcp_destroy(priv->fs);
+	}
+
+out_unlock:
+	mutex_unlock(&priv->state_lock);
 	return err;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

From: Xuanqiang Luo <[email protected]>

mlx5e_ktls_set_feature_rx() has become harder to follow: the error handling is nested in the conditions and the main flow is conditional.

Handle the disable case first, handle the error cases in conditionals, and keep the main flow unconditional. Use goto to unlock on the early returns.

Quoted 6 lines

No functional change intended.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Xuanqiang Luo
Quoted 15 lines · Xuanqiang Luo

From: Xuanqiang Luo <[email protected]>

mlx5e_ktls_set_feature_rx() has become harder to follow: the error handling is nested in the conditions and the main flow is conditional.

Handle the disable case first, handle the error cases in conditionals, and keep the main flow unconditional. Use goto to unlock on the early returns.

No functional change intended.

Quoted 9 lines

---
Changes:
v2:
- Handle the disable case first and keep the enable argument unchanged, instead of reusing it as a flag to destroy the tables. (Suggested by Tariq.)

v1: https://lore.kernel.org/all/[email protected]/

Thanks for the update, this is what I had in mind.