net/mlx5: Fix access to sf_dev_table on allocation failure
authorShay Drory <shayd@nvidia.com>
Thu, 30 Dec 2021 06:54:08 +0000 (08:54 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 10:03:57 +0000 (11:03 +0100)
[ Upstream commit a1c7c49c2091926962f8c1c866d386febffec5d8 ]

Even when SF devices are supported, the SF device table allocation
can still fail.
In such case mlx5_sf_dev_supported still reports true, but SF device
table is invalid. This can result in NULL table access.

Hence, fix it by adding NULL table check.

Fixes: 1958fc2f0712 ("net/mlx5: SF, Add auxiliary device driver")
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.c

index 871c2fbe18d39f541fd076abb2e403844c685c25..64bbc18332d56907151de647d0c9f8dce45144a7 100644 (file)
@@ -28,10 +28,7 @@ bool mlx5_sf_dev_allocated(const struct mlx5_core_dev *dev)
 {
        struct mlx5_sf_dev_table *table = dev->priv.sf_dev_table;
 
-       if (!mlx5_sf_dev_supported(dev))
-               return false;
-
-       return !xa_empty(&table->devices);
+       return table && !xa_empty(&table->devices);
 }
 
 static ssize_t sfnum_show(struct device *dev, struct device_attribute *attr, char *buf)