Skip to content

Commit d060e85

Browse files
kiram9JohnAZoidberg
authored andcommitted
i2c read - truncate return buf to request size
i2c verification was failing due to on windows there are additional bytes in the response from send_command. So truncate the extra bytes to the request size Signed-off-by: Kieran Levin <ktl@frame.work>
1 parent 77a9090 commit d060e85

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

framework_lib/src/chromium_ec/i2c_passthrough.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ pub fn i2c_read_16bit_addr(
177177

178178
let data = ec.send_command(EcCommands::I2cPassthrough as u16, 0, &buffer)?;
179179
let res: _EcI2cPassthruResponse = unsafe { std::ptr::read(data.as_ptr() as *const _) };
180-
let res_data = &data[size_of::<_EcI2cPassthruResponse>()..];
180+
let header_len: usize = size_of::<_EcI2cPassthruResponse>();
181+
/* Note on windows, you can get extra bytes back, so truncate this to the requested size */
182+
let res_data = &data[header_len..(len as usize + header_len)];
181183
debug_assert!(res.messages as usize == messages.len() || res.messages == 0);
182184
trace!(
183185
" i2c_read_16bit_addr response (len: {}, data: {:#04X?})",

0 commit comments

Comments
 (0)