From 163dd5cb3a02bd6eca0e7e03eec9b92cddbb5ada Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sat, 17 Jan 2026 18:42:47 +0800 Subject: [PATCH] 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 --- framework_lib/src/chromium_ec/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index 94997bab..c823bfe8 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -301,13 +301,16 @@ impl CrosEc { } } - pub fn cmd_version_supported(&self, cmd: u16, version: u8) -> EcResult { - let res = EcRequestGetCmdVersionsV1 { cmd: cmd.into() }.send_command(self); + pub fn cmd_version_supported(&self, cmd: u32, version: u8) -> EcResult { + let res = EcRequestGetCmdVersionsV1 { cmd }.send_command(self); let mask = if let Ok(res) = res { res.version_mask - } else { - let res = EcRequestGetCmdVersionsV0 { cmd: cmd as u8 }.send_command(self)?; + } else if let Ok(cmd) = u8::try_from(cmd) { + // V0 only supports 8-bit command IDs, so only fall back for commands <= 255 + let res = EcRequestGetCmdVersionsV0 { cmd }.send_command(self)?; res.version_mask + } else { + return Ok(false); }; Ok(mask & (1 << version) > 0)