diff mbox series

[net] mlxsw: __mlxsw_sp_port_headroom_set(): Fix a use of local variable

Message ID 20190217071809.19295-1-idosch@mellanox.com
State Accepted
Delegated to: David Miller
Headers show
Series [net] mlxsw: __mlxsw_sp_port_headroom_set(): Fix a use of local variable | expand

Commit Message

Ido Schimmel Feb. 17, 2019, 7:18 a.m. UTC
From: Petr Machata <petrm@mellanox.com>

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: f417f04da589 ("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>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

David Miller Feb. 17, 2019, 6:14 p.m. UTC | #1
From: Ido Schimmel <idosch@mellanox.com>
Date: Sun, 17 Feb 2019 07:18:41 +0000

> From: Petr Machata <petrm@mellanox.com>
> 
> 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: f417f04da589 ("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>

Applied and queued up for -stable, thanks Ido.
Ido Schimmel Feb. 19, 2019, 9:30 a.m. UTC | #2
On Sun, Feb 17, 2019 at 10:14:40AM -0800, David Miller wrote:
> From: Ido Schimmel <idosch@mellanox.com>
> Date: Sun, 17 Feb 2019 07:18:41 +0000
> 
> > From: Petr Machata <petrm@mellanox.com>
> > 
> > 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: f417f04da589 ("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>
> 
> Applied and queued up for -stable, thanks Ido.

Hi David,

We have a series for net-next that adds support for Spectrum-2 shared
buffers and it depends on this patch. I was wondering if you could merge
net into net-next today or later this week, so that we could submit it.

Normally I would just wait for the merge to happen, but it looks like
this is going to be the last week to submit changes and I prefer not to
miss the window while waiting for the inevitable merge.

Thanks and sorry about the noise.
David Miller Feb. 19, 2019, 6:33 p.m. UTC | #3
From: Ido Schimmel <idosch@mellanox.com>
Date: Tue, 19 Feb 2019 09:30:31 +0000

> We have a series for net-next that adds support for Spectrum-2 shared
> buffers and it depends on this patch. I was wondering if you could merge
> net into net-next today or later this week, so that we could submit it.
> 
> Normally I would just wait for the merge to happen, but it looks like
> this is going to be the last week to submit changes and I prefer not to
> miss the window while waiting for the inevitable merge.
> 
> Thanks and sorry about the noise.

Ido, I will send Linus a pull request today and he should pull it in and
I should therefore be able to get net-next sync'd with it by the end of
tomorrow.
Ido Schimmel Feb. 20, 2019, 8:12 a.m. UTC | #4
On Tue, Feb 19, 2019 at 10:33:38AM -0800, David Miller wrote:
> From: Ido Schimmel <idosch@mellanox.com>
> Date: Tue, 19 Feb 2019 09:30:31 +0000
> 
> > We have a series for net-next that adds support for Spectrum-2 shared
> > buffers and it depends on this patch. I was wondering if you could merge
> > net into net-next today or later this week, so that we could submit it.
> > 
> > Normally I would just wait for the merge to happen, but it looks like
> > this is going to be the last week to submit changes and I prefer not to
> > miss the window while waiting for the inevitable merge.
> > 
> > Thanks and sorry about the noise.
> 
> Ido, I will send Linus a pull request today and he should pull it in and
> I should therefore be able to get net-next sync'd with it by the end of
> tomorrow.

Great, thanks!
David Miller Feb. 20, 2019, 6:41 p.m. UTC | #5
From: Ido Schimmel <idosch@mellanox.com>
Date: Wed, 20 Feb 2019 08:12:18 +0000

> On Tue, Feb 19, 2019 at 10:33:38AM -0800, David Miller wrote:
>> From: Ido Schimmel <idosch@mellanox.com>
>> Date: Tue, 19 Feb 2019 09:30:31 +0000
>> 
>> > We have a series for net-next that adds support for Spectrum-2 shared
>> > buffers and it depends on this patch. I was wondering if you could merge
>> > net into net-next today or later this week, so that we could submit it.
>> > 
>> > Normally I would just wait for the merge to happen, but it looks like
>> > this is going to be the last week to submit changes and I prefer not to
>> > miss the window while waiting for the inevitable merge.
>> > 
>> > Thanks and sorry about the noise.
>> 
>> Ido, I will send Linus a pull request today and he should pull it in and
>> I should therefore be able to get net-next sync'd with it by the end of
>> tomorrow.
> 
> Great, thanks!

This is now done.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 32519c93df17..b65e274b02e9 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -862,8 +862,9 @@  int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
 	for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
 		bool configure = false;
 		bool pfc = false;
+		u16 thres_cells;
+		u16 delay_cells;
 		bool lossy;
-		u16 thres;
 
 		for (j = 0; j < IEEE_8021QAZ_MAX_TCS; j++) {
 			if (prio_tc[j] == i) {
@@ -877,10 +878,11 @@  int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
 			continue;
 
 		lossy = !(pfc || pause_en);
-		thres = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
-		delay = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay, pfc,
-						  pause_en);
-		mlxsw_sp_pg_buf_pack(pbmc_pl, i, thres + delay, thres, lossy);
+		thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
+		delay_cells = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay,
+							pfc, pause_en);
+		mlxsw_sp_pg_buf_pack(pbmc_pl, i, thres_cells + delay_cells,
+				     thres_cells, lossy);
 	}
 
 	return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);