]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: lag: Check for LAG device before creating debugfs
authorShay Drory <shayd@nvidia.com>
Mon, 30 Mar 2026 19:40:13 +0000 (22:40 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 2 Apr 2026 03:10:40 +0000 (20:10 -0700)
__mlx5_lag_dev_add_mdev() may return 0 (success) even when an error
occurs that is handled gracefully. Consequently, the initialization
flow proceeds to call mlx5_ldev_add_debugfs() even when there is no
valid LAG context.

mlx5_ldev_add_debugfs() blindly created the debugfs directory and
attributes. This exposed interfaces (like the members file) that rely on
a valid ldev pointer, leading to potential NULL pointer dereferences if
accessed when ldev is NULL.

Add a check to verify that mlx5_lag_dev(dev) returns a valid pointer
before attempting to create the debugfs entries.

Fixes: 7f46a0b7327a ("net/mlx5: Lag, add debugfs to query hardware lag state")
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260330194015.53585-2-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c

index 62b6faa4276aad03d6716512058cf50bb870ea57..b8d5f6a44d26ab813ae052ec8eb5df6e69ce0156 100644 (file)
@@ -160,8 +160,11 @@ DEFINE_SHOW_ATTRIBUTE(members);
 
 void mlx5_ldev_add_debugfs(struct mlx5_core_dev *dev)
 {
+       struct mlx5_lag *ldev = mlx5_lag_dev(dev);
        struct dentry *dbg;
 
+       if (!ldev)
+               return;
        dbg = debugfs_create_dir("lag", mlx5_debugfs_get_dev_root(dev));
        dev->priv.dbg.lag_debugfs = dbg;