Skip to content

Commit 2894604

Browse files
pmachatadavem330
authored andcommitted
mlxsw: __mlxsw_sp_port_headroom_set(): Fix a use of local variable
The function-local variable "delay" enters the loop interpreted as delay in bits. However, inside the loop it gets overwritten by the result of mlxsw_sp_pg_buf_delay_get(), and thus leaves the loop as quantity in cells. Thus on second and further loop iterations, the headroom for a given priority is configured with a wrong size. Fix by introducing a loop-local variable, delay_cells. Rename thres to thres_cells for consistency. Fixes: f417f04 ("mlxsw: spectrum: Refactor port buffer configuration") Signed-off-by: Petr Machata <petrm@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e1077f commit 2894604

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,9 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
862862
for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
863863
bool configure = false;
864864
bool pfc = false;
865+
u16 thres_cells;
866+
u16 delay_cells;
865867
bool lossy;
866-
u16 thres;
867868

868869
for (j = 0; j < IEEE_8021QAZ_MAX_TCS; j++) {
869870
if (prio_tc[j] == i) {
@@ -877,10 +878,11 @@ int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
877878
continue;
878879

879880
lossy = !(pfc || pause_en);
880-
thres = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
881-
delay = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay, pfc,
882-
pause_en);
883-
mlxsw_sp_pg_buf_pack(pbmc_pl, i, thres + delay, thres, lossy);
881+
thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
882+
delay_cells = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay,
883+
pfc, pause_en);
884+
mlxsw_sp_pg_buf_pack(pbmc_pl, i, thres_cells + delay_cells,
885+
thres_cells, lossy);
884886
}
885887

886888
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);

0 commit comments

Comments
 (0)