Commit c391eb83 authored by Dan Carpenter's avatar Dan Carpenter Committed by David S. Miller

mlxsw: Fix some IS_ERR() vs NULL bugs

The mlxsw_sp_acl_rulei_create() function is supposed to return an error
pointer from mlxsw_afa_block_create().  The problem is that these
functions both return NULL instead of error pointers.  Half the callers
expect NULL and half expect error pointers so it could lead to a NULL
dereference on failure.

This patch changes both of them to return error pointers and changes all
the callers which checked for NULL to check for IS_ERR() instead.

Fixes: 4cda7d8d ("mlxsw: core: Introduce flexible actions support")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 829e7573
...@@ -380,7 +380,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa) ...@@ -380,7 +380,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa)
block = kzalloc(sizeof(*block), GFP_KERNEL); block = kzalloc(sizeof(*block), GFP_KERNEL);
if (!block) if (!block)
return NULL; return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&block->resource_list); INIT_LIST_HEAD(&block->resource_list);
block->afa = mlxsw_afa; block->afa = mlxsw_afa;
...@@ -408,7 +408,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa) ...@@ -408,7 +408,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa)
mlxsw_afa_set_destroy(block->first_set); mlxsw_afa_set_destroy(block->first_set);
err_first_set_create: err_first_set_create:
kfree(block); kfree(block);
return NULL; return ERR_PTR(-ENOMEM);
} }
EXPORT_SYMBOL(mlxsw_afa_block_create); EXPORT_SYMBOL(mlxsw_afa_block_create);
......
...@@ -88,8 +88,8 @@ static int mlxsw_sp2_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, void *priv, ...@@ -88,8 +88,8 @@ static int mlxsw_sp2_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, void *priv,
* to be written using PEFA register to all indexes for all regions. * to be written using PEFA register to all indexes for all regions.
*/ */
afa_block = mlxsw_afa_block_create(mlxsw_sp->afa); afa_block = mlxsw_afa_block_create(mlxsw_sp->afa);
if (!afa_block) { if (IS_ERR(afa_block)) {
err = -ENOMEM; err = PTR_ERR(afa_block);
goto err_afa_block; goto err_afa_block;
} }
err = mlxsw_afa_block_continue(afa_block); err = mlxsw_afa_block_continue(afa_block);
......
...@@ -464,7 +464,7 @@ mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl, ...@@ -464,7 +464,7 @@ mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
rulei = kzalloc(sizeof(*rulei), GFP_KERNEL); rulei = kzalloc(sizeof(*rulei), GFP_KERNEL);
if (!rulei) if (!rulei)
return NULL; return ERR_PTR(-ENOMEM);
if (afa_block) { if (afa_block) {
rulei->act_block = afa_block; rulei->act_block = afa_block;
......
...@@ -199,8 +199,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp, ...@@ -199,8 +199,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp,
int err; int err;
afa_block = mlxsw_afa_block_create(mlxsw_sp->afa); afa_block = mlxsw_afa_block_create(mlxsw_sp->afa);
if (!afa_block) if (IS_ERR(afa_block))
return ERR_PTR(-ENOMEM); return afa_block;
err = mlxsw_afa_block_append_allocated_counter(afa_block, err = mlxsw_afa_block_append_allocated_counter(afa_block,
counter_index); counter_index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment