[06/10] net/atlantic: fix eeprom fetching for small and uneven lengths

Message ID afc2259673b7fc39a2c92670d5c4eb0f4db8d8fc.1551528549.git.igor.russkikh@aquantia.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/atlantic: bugfixes and code cleanup |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Igor Russkikh March 2, 2019, 12:10 p.m. UTC
From: Pavel Belous <Pavel.Belous@aquantia.com>

Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
Signed-off-by: Pavel Belous <Pavel.Belous@aquantia.com>
---
 .../net/atlantic/hw_atl/hw_atl_utils_fw2x.c   | 27 ++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)
  

Patch

diff --git a/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c b/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c
index d0eb9f5e9..efa999268 100644
--- a/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c
+++ b/drivers/net/atlantic/hw_atl/hw_atl_utils_fw2x.c
@@ -531,13 +531,32 @@  static int aq_fw2x_get_eeprom(struct aq_hw_s *self, int dev_addr, u32 *data, u32
 		return err;
 
 	if (result == 0) {
-		err = hw_atl_utils_fw_downld_dwords(self,
+		u32 num_dwords = len / sizeof(u32);
+		u32 bytes_remains = len % sizeof(u32);
+
+		if (num_dwords) {
+			err = hw_atl_utils_fw_downld_dwords(self,
 				self->rpc_addr + sizeof(u32) * 2,
 				data,
-				RTE_ALIGN(len, sizeof(u32)));
+				num_dwords);
 
-		if (err < 0)
-			return err;
+			if (err < 0)
+				return err;
+		}
+
+		if (bytes_remains) {
+			u32 val = 0;
+
+			err = hw_atl_utils_fw_downld_dwords(self,
+				self->rpc_addr + sizeof(u32) * 2 + num_dwords,
+				&val,
+				sizeof(u32));
+
+			if (err < 0)
+				return err;
+
+			rte_memcpy((u8*)data + len - bytes_remains, &val, bytes_remains);
+		}
 	}
 
 	return 0;