netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net/dim: Fix int overflow
@ 2018-03-29 10:53 Tal Gilboa
  2018-03-29 12:01 ` Andy Gospodarek
  2018-03-30 16:56 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Tal Gilboa @ 2018-03-29 10:53 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Tariq Toukan, Tal Gilboa, Andy Gospodarek, Saeed Mahameed

When calculating difference between samples, the values
are multiplied by 100. Large values may cause int overflow
when multiplied (usually on first iteration).
Fixed by forcing 100 to be of type unsigned long.

Fixes: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
Signed-off-by: Tal Gilboa <talgi@mellanox.com>
---
 include/linux/net_dim.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/net_dim.h b/include/linux/net_dim.h
index bebeaad..29ed8fd 100644
--- a/include/linux/net_dim.h
+++ b/include/linux/net_dim.h
@@ -231,7 +231,7 @@ static inline void net_dim_exit_parking(struct net_dim *dim)
 }
 
 #define IS_SIGNIFICANT_DIFF(val, ref) \
-	(((100 * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
+	(((100UL * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
 
 static inline int net_dim_stats_compare(struct net_dim_stats *curr,
 					struct net_dim_stats *prev)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/dim: Fix int overflow
  2018-03-29 10:53 [PATCH net] net/dim: Fix int overflow Tal Gilboa
@ 2018-03-29 12:01 ` Andy Gospodarek
  2018-03-30 16:56 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Gospodarek @ 2018-03-29 12:01 UTC (permalink / raw)
  To: Tal Gilboa
  Cc: David S. Miller, netdev, Tariq Toukan, Andy Gospodarek, Saeed Mahameed

On Thu, Mar 29, 2018 at 01:53:52PM +0300, Tal Gilboa wrote:
> When calculating difference between samples, the values
> are multiplied by 100. Large values may cause int overflow
> when multiplied (usually on first iteration).
> Fixed by forcing 100 to be of type unsigned long.
> 
> Fixes: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
> Signed-off-by: Tal Gilboa <talgi@mellanox.com>

Reviewed-by: Andy Gospodarek <gospo@broadcom.com>

> ---
>  include/linux/net_dim.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/net_dim.h b/include/linux/net_dim.h
> index bebeaad..29ed8fd 100644
> --- a/include/linux/net_dim.h
> +++ b/include/linux/net_dim.h
> @@ -231,7 +231,7 @@ static inline void net_dim_exit_parking(struct net_dim *dim)
>  }
>  
>  #define IS_SIGNIFICANT_DIFF(val, ref) \
> -	(((100 * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
> +	(((100UL * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
>  
>  static inline int net_dim_stats_compare(struct net_dim_stats *curr,
>  					struct net_dim_stats *prev)
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/dim: Fix int overflow
  2018-03-29 10:53 [PATCH net] net/dim: Fix int overflow Tal Gilboa
  2018-03-29 12:01 ` Andy Gospodarek
@ 2018-03-30 16:56 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-03-30 16:56 UTC (permalink / raw)
  To: talgi; +Cc: netdev, tariqt, andrew.gospodarek, saeedm

From: Tal Gilboa <talgi@mellanox.com>
Date: Thu, 29 Mar 2018 13:53:52 +0300

> When calculating difference between samples, the values
> are multiplied by 100. Large values may cause int overflow
> when multiplied (usually on first iteration).
> Fixed by forcing 100 to be of type unsigned long.
> 
> Fixes: 4c4dbb4a7363 ("net/mlx5e: Move dynamic interrupt coalescing code to include/linux")
> Signed-off-by: Tal Gilboa <talgi@mellanox.com>

Applied, thank you.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-30 16:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-29 10:53 [PATCH net] net/dim: Fix int overflow Tal Gilboa
2018-03-29 12:01 ` Andy Gospodarek
2018-03-30 16:56 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).