Skip to content

Commit b6614f2

Browse files
committed
Avoid a stack copy of AdminCommandRequestHeader
Saves 4kB of stack use, otherwise a temporary is created for ch. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
1 parent 421cd45 commit b6614f2

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/nvme/mi/dev.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,26 @@ impl RequestHandler for MessageHeader {
101101
};
102102

103103
match nmimt {
104-
MessageType::NvmeMiCommand => match NvmeMiCommandRequestHeader::from_bytes((rest, 0)) {
105-
Ok(((rest, _), ch)) => ch.handle(&ch, mep, subsys, rest, resp, app).await,
106-
Err(err) => {
107-
debug!("Unable to parse NVMeMICommandHeader from message buffer: {err:?}");
108-
// TODO: This is a bad assumption: Can see DekuError::InvalidParam too
109-
Err(ResponseStatus::InvalidCommandSize)
104+
MessageType::NvmeMiCommand => {
105+
match &NvmeMiCommandRequestHeader::from_bytes((rest, 0)) {
106+
Ok(((rest, _), ch)) => ch.handle(ch, mep, subsys, rest, resp, app).await,
107+
Err(err) => {
108+
debug!("Unable to parse NVMeMICommandHeader from message buffer: {err:?}");
109+
// TODO: This is a bad assumption: Can see DekuError::InvalidParam too
110+
Err(ResponseStatus::InvalidCommandSize)
111+
}
110112
}
111-
},
112-
MessageType::NvmeAdminCommand => match AdminCommandRequestHeader::from_bytes((rest, 0))
113-
{
114-
Ok(((rest, _), ch)) => ch.handle(&ch, mep, subsys, rest, resp, app).await,
115-
Err(err) => {
116-
debug!("Unable to parse AdminCommandHeader from message buffer: {err:?}");
117-
// TODO: This is a bad assumption: Can see DekuError::InvalidParam too
118-
Err(ResponseStatus::InvalidCommandSize)
113+
}
114+
MessageType::NvmeAdminCommand => {
115+
match &AdminCommandRequestHeader::from_bytes((rest, 0)) {
116+
Ok(((rest, _), ch)) => ch.handle(ch, mep, subsys, rest, resp, app).await,
117+
Err(err) => {
118+
debug!("Unable to parse AdminCommandHeader from message buffer: {err:?}");
119+
// TODO: This is a bad assumption: Can see DekuError::InvalidParam too
120+
Err(ResponseStatus::InvalidCommandSize)
121+
}
119122
}
120-
},
123+
}
121124
_ => {
122125
debug!("Unimplemented NMINT: {:?}", ctx.nmimt());
123126
Err(ResponseStatus::InternalError)

0 commit comments

Comments
 (0)