提交 de5ed99e 编写于 作者: I Ido Schimmel 提交者: David S. Miller

mlxsw: spectrum_router: Align RIF index allocation with existing code

The way we usually allocate an index is by letting the allocation
function return an error instead of an invalid index.

Do the same for RIF index.
Signed-off-by: NIdo Schimmel <idosch@mellanox.com>
Reviewed-by: NPetr Machata <petrm@mellanox.com>
Signed-off-by: NJiri Pirko <jiri@mellanox.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 da0abcf9
...@@ -2979,16 +2979,18 @@ mlxsw_sp_dev_rif_type(const struct mlxsw_sp *mlxsw_sp, ...@@ -2979,16 +2979,18 @@ mlxsw_sp_dev_rif_type(const struct mlxsw_sp *mlxsw_sp,
return mlxsw_sp_fid_type_rif_type(mlxsw_sp, type); return mlxsw_sp_fid_type_rif_type(mlxsw_sp, type);
} }
#define MLXSW_SP_INVALID_INDEX_RIF 0xffff static int mlxsw_sp_rif_index_alloc(struct mlxsw_sp *mlxsw_sp, u16 *p_rif_index)
static int mlxsw_sp_avail_rif_get(struct mlxsw_sp *mlxsw_sp)
{ {
int i; int i;
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); i++) for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); i++) {
if (!mlxsw_sp->router->rifs[i]) if (!mlxsw_sp->router->rifs[i]) {
return i; *p_rif_index = i;
return 0;
}
}
return MLXSW_SP_INVALID_INDEX_RIF; return -ENOBUFS;
} }
static struct mlxsw_sp_rif *mlxsw_sp_rif_alloc(size_t rif_size, u16 rif_index, static struct mlxsw_sp_rif *mlxsw_sp_rif_alloc(size_t rif_size, u16 rif_index,
...@@ -3048,11 +3050,9 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp, ...@@ -3048,11 +3050,9 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp,
if (IS_ERR(vr)) if (IS_ERR(vr))
return ERR_CAST(vr); return ERR_CAST(vr);
rif_index = mlxsw_sp_avail_rif_get(mlxsw_sp); err = mlxsw_sp_rif_index_alloc(mlxsw_sp, &rif_index);
if (rif_index == MLXSW_SP_INVALID_INDEX_RIF) { if (err)
err = -ERANGE; goto err_rif_index_alloc;
goto err_avail_rif_get;
}
rif = mlxsw_sp_rif_alloc(ops->rif_size, rif_index, vr->id, params->dev); rif = mlxsw_sp_rif_alloc(ops->rif_size, rif_index, vr->id, params->dev);
if (!rif) { if (!rif) {
...@@ -3095,7 +3095,7 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp, ...@@ -3095,7 +3095,7 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp,
err_fid_get: err_fid_get:
kfree(rif); kfree(rif);
err_rif_alloc: err_rif_alloc:
err_avail_rif_get: err_rif_index_alloc:
mlxsw_sp_vr_put(vr); mlxsw_sp_vr_put(vr);
return ERR_PTR(err); return ERR_PTR(err);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册