Skip to content

Commit

Permalink
net: stmmac_tc: use 64-bit arithmetic instead of 32-bit
Browse files Browse the repository at this point in the history
Add suffix UL to constant 1024 in order to give the compiler complete
information about the proper arithmetic to use. Notice that this
constant is used in a context that expects an expression of type
u64 (64 bits, unsigned) and  following expressions are currently
being evaluated using 32-bit arithmetic:

qopt->idleslope * 1024 * ptr
qopt->hicredit * 1024 * 8
qopt->locredit * 1024 * 8

Addresses-Coverity-ID: 1470246 ("Unintentional integer overflow")
Addresses-Coverity-ID: 1470248 ("Unintentional integer overflow")
Addresses-Coverity-ID: 1470249 ("Unintentional integer overflow")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Acked-by: Jose Abreu <joabreu@synopsys.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Gustavo A. R. Silva authored and David S. Miller committed Jul 3, 2018
1 parent 00f5536 commit c18a9c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ static int tc_setup_cbs(struct stmmac_priv *priv,
speed_div = (priv->speed == SPEED_100) ? 100000 : 1000000;

/* Final adjustments for HW */
value = qopt->idleslope * 1024 * ptr;
value = qopt->idleslope * 1024UL * ptr;
do_div(value, speed_div);
priv->plat->tx_queues_cfg[queue].idle_slope = value & GENMASK(31, 0);

value = -qopt->sendslope * 1024UL * ptr;
do_div(value, speed_div);
priv->plat->tx_queues_cfg[queue].send_slope = value & GENMASK(31, 0);

value = qopt->hicredit * 1024 * 8;
value = qopt->hicredit * 1024UL * 8;
priv->plat->tx_queues_cfg[queue].high_credit = value & GENMASK(31, 0);

value = qopt->locredit * 1024 * 8;
value = qopt->locredit * 1024UL * 8;
priv->plat->tx_queues_cfg[queue].low_credit = value & GENMASK(31, 0);

ret = stmmac_config_cbs(priv, priv->hw,
Expand Down

0 comments on commit c18a9c0

Please sign in to comment.