Skip to content

Commit c391eb8

Browse files
Dan Carpenterdavem330
authored andcommitted
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: 4cda7d8 ("mlxsw: core: Introduce flexible actions support") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 829e757 commit c391eb8

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa)
380380

381381
block = kzalloc(sizeof(*block), GFP_KERNEL);
382382
if (!block)
383-
return NULL;
383+
return ERR_PTR(-ENOMEM);
384384
INIT_LIST_HEAD(&block->resource_list);
385385
block->afa = mlxsw_afa;
386386

@@ -408,7 +408,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa)
408408
mlxsw_afa_set_destroy(block->first_set);
409409
err_first_set_create:
410410
kfree(block);
411-
return NULL;
411+
return ERR_PTR(-ENOMEM);
412412
}
413413
EXPORT_SYMBOL(mlxsw_afa_block_create);
414414

drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static int mlxsw_sp2_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, void *priv,
8888
* to be written using PEFA register to all indexes for all regions.
8989
*/
9090
afa_block = mlxsw_afa_block_create(mlxsw_sp->afa);
91-
if (!afa_block) {
92-
err = -ENOMEM;
91+
if (IS_ERR(afa_block)) {
92+
err = PTR_ERR(afa_block);
9393
goto err_afa_block;
9494
}
9595
err = mlxsw_afa_block_continue(afa_block);

drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
464464

465465
rulei = kzalloc(sizeof(*rulei), GFP_KERNEL);
466466
if (!rulei)
467-
return NULL;
467+
return ERR_PTR(-ENOMEM);
468468

469469
if (afa_block) {
470470
rulei->act_block = afa_block;

drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp,
199199
int err;
200200

201201
afa_block = mlxsw_afa_block_create(mlxsw_sp->afa);
202-
if (!afa_block)
203-
return ERR_PTR(-ENOMEM);
202+
if (IS_ERR(afa_block))
203+
return afa_block;
204204

205205
err = mlxsw_afa_block_append_allocated_counter(afa_block,
206206
counter_index);

0 commit comments

Comments
 (0)