Skip to content

Commit a71f5b5

Browse files
authored
Fix try_from! macro not checking MSb of type (#140)
* Fix try_from! macro not checking MSb of type * Use hex values for raw TRB data in test
1 parent 4ae7fb3 commit a71f5b5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/ring/trb/event.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,24 @@ pub enum CompletionCode {
351351
/// Asserted if an error is detected on a USB2 protocol endpoint for a split transaction.
352352
SplitTransactionError = 36,
353353
}
354+
355+
#[cfg(test)]
356+
mod test {
357+
use super::*;
358+
359+
#[test]
360+
fn try_from_macro() {
361+
let raw = [
362+
0x00c8_8800, // address low
363+
0x0000_0000, // address high
364+
0x01_000000, // completion code 1, transfer length 0
365+
0x0000_8401, // endpoint id 0, slot id 0, type 33, event data 0, cycle bit 1
366+
];
367+
assert_eq!(
368+
Allowed::try_from(raw),
369+
Ok(Allowed::CommandCompletion(
370+
CommandCompletion::try_from(raw).unwrap()
371+
)),
372+
);
373+
}
374+
}

src/ring/trb/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ macro_rules! reserved{
2929
}
3030
macro_rules! try_from {
3131
($raw:ident => $($name:ident $(($t:ident))?),* $(,)?) => {{
32-
if let Some(ty) = Type::from_u32($raw[3].get_bits(10..15)) {
32+
if let Some(ty) = Type::from_u32($raw[3].get_bits(10..=15)) {
3333
paste::paste! {
3434
match ty {
3535
$(

0 commit comments

Comments
 (0)