From b4e47f4994f555b24bdcd15cd6b1cb3cbe6b39c7 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Tue, 16 Nov 2021 16:44:57 +0530 Subject: [PATCH] [i2c] Send data for I2C_SMBUS_BYTE command The data needs to be sent for I2C_SMBUS_BYTE command and we need to make sure we don't access the same for I2C_SMBUS_QUICK command after the command is processed. Signed-off-by: Viresh Kumar --- coverage_config_x86_64.json | 2 +- src/i2c/src/i2c.rs | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index de4f3b7..6682093 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1,5 +1,5 @@ { - "coverage_score": 43.2, + "coverage_score": 42.9, "exclude_path": "", "crate_features": "" } diff --git a/src/i2c/src/i2c.rs b/src/i2c/src/i2c.rs index 472f69e..11c5345 100644 --- a/src/i2c/src/i2c.rs +++ b/src/i2c/src/i2c.rs @@ -203,7 +203,7 @@ impl SmbusMsg { read_write, command: reqs[0].buf[0], size: I2C_SMBUS_BYTE, - data: None, + data: Some(data), }), // Write requests @@ -456,14 +456,12 @@ impl I2cAdapter { self.device.smbus(&mut msg)?; if msg.read_write == I2C_SMBUS_READ { - // data is guaranteed to be valid here. - let data = msg.data.unwrap(); - match msg.size { - I2C_SMBUS_BYTE => reqs[0].buf[0] = data.read_byte(), - I2C_SMBUS_BYTE_DATA => reqs[1].buf[0] = data.read_byte(), + I2C_SMBUS_QUICK => {} + I2C_SMBUS_BYTE => reqs[0].buf[0] = msg.data.unwrap().read_byte(), + I2C_SMBUS_BYTE_DATA => reqs[1].buf[0] = msg.data.unwrap().read_byte(), I2C_SMBUS_WORD_DATA => { - let word = data.read_word(); + let word = msg.data.unwrap().read_word(); reqs[1].buf[0] = (word & 0xff) as u8; reqs[1].buf[1] = (word >> 8) as u8;