Blob Blame History Raw
From: Eran Ben Elisha <eranbe@mellanox.com>
Date: Fri, 23 Aug 2019 15:34:47 +0300
Subject: net/mlx5: Fix return code in case of hyperv wrong size read
Patch-mainline: v5.4-rc1
Git-commit: 87cade2997c9210cfeb625957e44b865a89d0c13
References: jsc#SLE-8464

Return code value could be non deterministic in case of wrong size read.
With this patch, if such error occurs, set rc to be -EIO.

In addition, mlx5_hv_config_common() supports reading of
HV_CONFIG_BLOCK_SIZE_MAX bytes only, fix to early return error with
bad input.

Fixes: 913d14e86657 ("net/mlx5: Add wrappers for HyperV PCIe operations")
Reported-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Eran Ben Elisha <eranbe@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c
@@ -12,7 +12,7 @@ static int mlx5_hv_config_common(struct
 	int bytes_returned;
 	int block_id;
 
-	if (offset % HV_CONFIG_BLOCK_SIZE_MAX || len % HV_CONFIG_BLOCK_SIZE_MAX)
+	if (offset % HV_CONFIG_BLOCK_SIZE_MAX || len != HV_CONFIG_BLOCK_SIZE_MAX)
 		return -EINVAL;
 
 	block_id = offset / HV_CONFIG_BLOCK_SIZE_MAX;
@@ -25,8 +25,8 @@ static int mlx5_hv_config_common(struct
 				  HV_CONFIG_BLOCK_SIZE_MAX, block_id);
 
 	/* Make sure len bytes were read successfully  */
-	if (read)
-		rc |= !(len == bytes_returned);
+	if (read && !rc && len != bytes_returned)
+		rc = -EIO;
 
 	if (rc) {
 		mlx5_core_err(dev, "Failed to %s hv config, err = %d, len = %d, offset = %d\n",