net/mlx5e: kTLS, Simplify error unwind in mlx5e_ktls_set_feature_rx()
Subsystems (5)
PATCH 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 error cases in conditionals, keep the main flow unconditional, and destroy the accel TCP flow tables in a single place. Use goto to unlock on the early return.
No functional change intended.
---
Only compile-tested on top of net-next 7ccc5e05043b (arm64, W=1). I do not have a crypto-enabled ConnectX NIC to run it on.
.../mellanox/mlx5/core/en_accel/ktls.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +13 -10
@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)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); - } +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; + enable = false; } - }else { -mlx5e_accel_fs_tcp_destroy (priv->fs); } -mutex_unlock (&priv->state_lock); +if (!enable) +mlx5e_accel_fs_tcp_destroy (priv->fs); + +out_unlock: +mutex_unlock (&priv->state_lock);return err; }
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko 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 error cases in conditionals, keep the main flow unconditional, and destroy the accel TCP flow tables in a single place. Use goto to unlock on the early return.
Quoted 5 lines
No functional change intended.
Suggested-by Simon Horman <[email protected]>Signed-off-by Xuanqiang Luo <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Tariq Toukan
maintainerQuoted 11 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 error cases in conditionals, keep the main flow unconditional, and destroy the accel TCP flow tables in a single place. Use goto to unlock on the early return.
No functional change intended.
Thanks for following up on this.
The change is correct, I see no functional change.
However, we can simplify the code further.
See below suggestion where code is flat, the same size, and leaves the enable argument alone.
Quoted 37 lines
Suggested-by Simon Horman <[email protected]>Signed-off-by Xuanqiang Luo <[email protected]>---
Only compile-tested on top of net-next7ccc5e05043b(arm64, W=1). I do not have a crypto-enabled ConnectX NIC to run it on..../mellanox/mlx5/core/en_accel/ktls.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +8
-9@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable)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); - } +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; + enable = false; } - }else { -mlx5e_accel_fs_tcp_destroy (priv->fs); }
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable) · line 158
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +5
-1-mutex_unlock (&priv->state_lock); +if (!enable) +mlx5e_accel_fs_tcp_destroy (priv->fs); + +out_unlock: +mutex_unlock (&priv->state_lock);return err; }
Suggestion:
mutex_lock(&priv->state_lock);
if (!enable) {
mlx5e_accel_fs_tcp_destroy(priv->fs);
goto out_unlock;
}
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;
Quoted 12 lines · On 2026/11/17 at 6:27 Tariq Toukan wrote:
Quoted 9 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 error cases in conditionals, keep the main flow unconditional, and destroy the accel TCP flow tables in a single place. Use goto to unlock on the early return.
Quoted 9 lines
Quoted 2 lines
No functional change intended.
Thanks for following up on this.
The change is correct, I see no functional change.However, we can simplify the code further.
See below suggestion where code is flat, the same size, and leaves the enable argument alone.
Thanks, that's cleaner.
I'll send v2 with this form.
Thanks!
Xuanqiang
Quoted 69 lines
Quoted 36 lines
Suggested-by Simon Horman <[email protected]>Link https://lore.kernel.org/ all/[email protected]/Signed-off-by Xuanqiang Luo <[email protected]>---
Only compile-tested on top of net-next7ccc5e05043b(arm64, W=1). I do not have a crypto-enabled ConnectX NIC to run it on..../mellanox/mlx5/core/en_accel/ktls.c | 23 +++++++++++--------
1 file changed, 13 insertions(+), 10 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +8
-8@@ -137,19 +137,22 @@ int mlx5e_ktls_set_feature_rx(struct net_device *netdev, bool enable) 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); - } + 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; + enable = false; } - } else {drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c int mlx5e_ktls_set_feature_rx(struct net_device · line 157
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +5
-2- mlx5e_accel_fs_tcp_destroy(priv->fs); } - mutex_unlock(&priv->state_lock); + if (!enable) + mlx5e_accel_fs_tcp_destroy(priv->fs); + +out_unlock: + mutex_unlock(&priv->state_lock); return err; }Suggestion:
mutex_lock(&priv->state_lock);
if (!enable) {
mlx5e_accel_fs_tcp_destroy(priv->fs);
gotoout_unlock;
}err =
mlx5e_accel_fs_tcp_create(priv->fs);
if (err ||priv->ktls_rx_was_enabled)
gotoout_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;