Skip to content

Commit 3903249

Browse files
pmachatadavem330
authored andcommitted
mlxsw: spectrum_router: Do not query MAX_RIFS on each iteration
MLXSW_CORE_RES_GET involves a call to spectrum_core, a separate module. Instead of making the call on every iteration, cache it up front, and use the value. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Amit Cohen <amcohen@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5afef67 commit 3903249

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7699,9 +7699,10 @@ static struct mlxsw_sp_rif *
76997699
mlxsw_sp_rif_find_by_dev(const struct mlxsw_sp *mlxsw_sp,
77007700
const struct net_device *dev)
77017701
{
7702+
int max_rifs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
77027703
int i;
77037704

7704-
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); i++)
7705+
for (i = 0; i < max_rifs; i++)
77057706
if (mlxsw_sp->router->rifs[i] &&
77067707
mlxsw_sp->router->rifs[i]->dev == dev)
77077708
return mlxsw_sp->router->rifs[i];
@@ -10041,11 +10042,12 @@ static int mlxsw_sp_rifs_init(struct mlxsw_sp *mlxsw_sp)
1004110042

1004210043
static void mlxsw_sp_rifs_fini(struct mlxsw_sp *mlxsw_sp)
1004310044
{
10045+
int max_rifs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
1004410046
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
1004510047
int i;
1004610048

1004710049
WARN_ON_ONCE(atomic_read(&mlxsw_sp->router->rifs_count));
10048-
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); i++)
10050+
for (i = 0; i < max_rifs; i++)
1004910051
WARN_ON_ONCE(mlxsw_sp->router->rifs[i]);
1005010052

1005110053
devl_resource_occ_get_unregister(devlink, MLXSW_SP_RESOURCE_RIFS);

0 commit comments

Comments
 (0)