net/mlx5: check for allocation failure in mlx5_ft_pool_init()
Subsystems (5)
PATCH 1/1 net/mlx5: check for allocation failure in mlx5_ft_pool_init()
Add a check for if the kzalloc() fails.
--- drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c +2 -0
@@ -27,6 +27,8 @@ int mlx5_ft_pool_init(struct mlx5_core_dev *dev)int i; ft_pool =kzalloc (sizeof (*ft_pool),GFP_KERNEL ); +if (!ft_pool) +return -ENOMEM ;for (i =ARRAY_SIZE (FT_POOLS ) -1 ; i >=0 ; i--) ft_pool->ft_left[i] =FT_SIZE /FT_POOLS [i];
Signature · 1 line
2.30.2
Quoted 13 lines · Dan Carpenter
Add a check for if the
kzalloc()fails.Fixes 4a98544d1827 ("net/mlx5: Move chains ft pool to be used by all firmware steering")Signed-off-by Dan Carpenter <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c +0
-0
drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c int mlx5_ft_pool_init(struct mlx5_core_dev *dev) · line 34
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c +2
-0@@ -27,6 +27,8 @@ int mlx5_ft_pool_init(struct mlx5_core_dev *dev)int i; ft_pool =kzalloc (sizeof (*ft_pool),GFP_KERNEL ); +if (!ft_pool) +return -ENOMEM ;for (i =ARRAY_SIZE (FT_POOLS ) -1 ; i >=0 ; i--) ft_pool->ft_left[i] =FT_SIZE /FT_POOLS [i];
Dan thanks for your patch.
When reviewed your patch, I spotted another error in the patch from the Fixes line.
2955 err = mlx5_ft_pool_init(dev);
2956 if (err)
2957 return err;
2958
2959 steering = kzalloc(sizeof(*steering), GFP_KERNEL);
2960 if (!steering)
2961 goto err;
^^^^^^^^ it will return success, while should return ENOMEM.Thanks,
Quoted 28 lines · Leon Romanovsky
Quoted 13 lines · Dan Carpenter
Add a check for if the
kzalloc()fails.Fixes 4a98544d1827 ("net/mlx5: Move chains ft pool to be used by all firmware steering")Signed-off-by Dan Carpenter <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c +0
-0drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c int mlx5_ft_pool_init(struct mlx5_core_dev *dev) · line 34
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c +2
-0@@ -27,6 +27,8 @@ int mlx5_ft_pool_init(struct mlx5_core_dev *dev)int i; ft_pool =kzalloc (sizeof (*ft_pool),GFP_KERNEL ); +if (!ft_pool) +return -ENOMEM ;for (i =ARRAY_SIZE (FT_POOLS ) -1 ; i >=0 ; i--) ft_pool->ft_left[i] =FT_SIZE /FT_POOLS [i];Dan thanks for your patch.
When reviewed your patch, I spotted another error in the patch from the Fixes line.
Quoted 8 lines
2955 err = mlx5_ft_pool_init(dev);
2956 if (err)
2957 return err;
2958
2959 steering = kzalloc(sizeof(*steering), GFP_KERNEL);
2960 if (!steering)
2961 goto err;
^^^^^^^^ it will return success, while should return ENOMEM.Smatch prints a static checker warning for this, but I never finished going through the backlog of old "missing error code" warnings. At one point I was down to 38 warnings left but now I see that the backlog is 62 warnings so people are adding new bugs faster than I'm reviewing them... :P
I will take care of this tomorrow as a separate patch. I will just report or the other 61 warnings and get the backlog cleared out so that I can start checking these better in the future.
regards,
dan carpenter
Saeed Mahameed
AppliedQuoted 16 lines · Dan Carpenter
Add a check for if the
kzalloc()fails.Fixes 4a98544d1827 ("net/mlx5: Move chains ft pool to be used by allfirmware steering")
Signed-off-by Dan Carpenter <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c | 2 ++1 file changed, 2 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/fs_ft_pool.c +0
-0@@ -27,6 +27,8 @@ int mlx5_ft_pool_init(struct mlx5_core_dev *dev) int i;
Quoted 7 lines
ft_pool =kzalloc(sizeof(*ft_pool), GFP_KERNEL); + if (!ft_pool)
+ return-ENOMEM;
for (i =ARRAY_SIZE(FT_POOLS)- 1; i >= 0; i--) ft_pool->ft_left[i] =FT_SIZE/ FT_POOLS[i];
applied to net-next-mlx5,
thanks