Thread (4 messages) 4 messages, 3 authors, 2023-03-01

Re: [PATCH net v2] ice: copy last block omitted in ice_get_module_eeprom()

From: Jesse Brandeburg <hidden>
Date: 2023-03-01 19:27:12
Also in: intel-wired-lan, lkml

On 3/1/2023 9:14 AM, Petr Oros wrote:
quoted hunk ↗ jump to hunk
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
index b360bd8f15998b..1dc3f9fc74bdfb 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
@@ -4293,6 +4293,7 @@ ice_get_module_eeprom(struct net_device *netdev,
 	bool is_sfp = false;
 	unsigned int i, j;
 	u16 offset = 0;
+	u32 copy_len;
copy_len should only be declared in the "if" below so that it's only
declared in the context it is used.
quoted hunk ↗ jump to hunk
 	u8 page = 0;
 	int status;
 
@@ -4354,8 +4355,9 @@ ice_get_module_eeprom(struct net_device *netdev,
 			}
 
 			/* Make sure we have enough room for the new block */
-			if ((i + SFF_READ_BLOCK_SIZE) < ee->len)
-				memcpy(data + i, value, SFF_READ_BLOCK_SIZE);
+			copy_len = min_t(u32, SFF_READ_BLOCK_SIZE,
+					 ee->len - i);
also this line can be unwrapped now.
+			memcpy(data + i, value, copy_len);
 		}
 	}
 	return 0;
I've tested this and it fixes the problem. Interestingly, the ethtool
application when compiled without netlink support parsed the output
correctly so caused a bit of confusion around this issue.

Thank you Petr!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help