diff mbox series

[net] net/dim: Fix int overflow

Message ID 1522320832-18416-1-git-send-email-talgi@mellanox.com
State Accepted, archived
Delegated to: David Miller
Headers show
Series [net] net/dim: Fix int overflow | expand

Commit Message

Tal Gilboa March 29, 2018, 10:53 a.m. UTC
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(-)

Comments

Andy Gospodarek March 29, 2018, 12:01 p.m. UTC | #1
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
>
David Miller March 30, 2018, 4:56 p.m. UTC | #2
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.
diff mbox series

Patch

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)