Skip to content

Commit 6fa32d5

Browse files
committed
GetCmdVersion: Don't fall back to v0 if >0xFF
v0 only supports 8 bit command IDs. I ran into an issue where truncation and then misreporting happened. I asked claude to fix it and it wanted to just try the command to see if it fails. After I said that's not a good idea, we need to figure out what's wrong, it found this issue. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 1d2ad71 commit 6fa32d5

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

  • framework_lib/src/chromium_ec

framework_lib/src/chromium_ec/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,16 @@ impl CrosEc {
301301
}
302302
}
303303

304-
pub fn cmd_version_supported(&self, cmd: u16, version: u8) -> EcResult<bool> {
305-
let res = EcRequestGetCmdVersionsV1 { cmd: cmd.into() }.send_command(self);
304+
pub fn cmd_version_supported(&self, cmd: u32, version: u8) -> EcResult<bool> {
305+
let res = EcRequestGetCmdVersionsV1 { cmd }.send_command(self);
306306
let mask = if let Ok(res) = res {
307307
res.version_mask
308-
} else {
309-
let res = EcRequestGetCmdVersionsV0 { cmd: cmd as u8 }.send_command(self)?;
308+
} else if let Ok(cmd) = u8::try_from(cmd) {
309+
// V0 only supports 8-bit command IDs, so only fall back for commands <= 255
310+
let res = EcRequestGetCmdVersionsV0 { cmd }.send_command(self)?;
310311
res.version_mask
312+
} else {
313+
return Ok(false);
311314
};
312315

313316
Ok(mask & (1 << version) > 0)

0 commit comments

Comments
 (0)