Skip to content

mctp-usb: Simply return the header in MctpUsbHandler::header()#46

Merged
mkj merged 1 commit into
CodeConstruct:mainfrom
SafetyInObscurity:return-type
May 21, 2026
Merged

mctp-usb: Simply return the header in MctpUsbHandler::header()#46
mkj merged 1 commit into
CodeConstruct:mainfrom
SafetyInObscurity:return-type

Conversation

@SafetyInObscurity
Copy link
Copy Markdown
Contributor

Current implementation takes destination variable as a mutable argument and modifies it. It would be better for the function to simply return the header, rather than an empty Ok(()) on success.

@jk-ozlabs
Copy link
Copy Markdown
Member

Looks good! The CI failure looks like a general thing from the nightly toolchain, which we may want to address separately.

The change itself looks good, I would suggest a couple of things on the commit message though:

Simply return the header in MctpUsbHandler::header()

I'd suggest a prefix on this, as you have done in the PR. Since we're modifying multiple crates, perhaps usb:?

I'd also suggest some more context in the commit message; for example, why would it be better, and what effects would this have on the public API? (are there users of MctpUsbHandler::header that we need to worry about?)

@mkj
Copy link
Copy Markdown
Member

mkj commented May 4, 2026

Looks good! The CI failure looks like a general thing from the nightly toolchain, which we may want to address separately.

I have a pending change here to remove nightly toolchain from the PR CI job, and run it separately on a timer. I'll push that soon as a separate PR.

@SafetyInObscurity SafetyInObscurity force-pushed the return-type branch 2 times, most recently from d82c284 to 4110369 Compare May 5, 2026 07:32
Comment thread mctp-estack/src/usb.rs Outdated
Comment on lines +131 to +140
match Self::header(len) {
Ok(header) => hdr.copy_from_slice(&header),
Err(_) => {
trace!("USB transfer error");
return SendOutput::Error {
err: Error::TxFailure,
cookie: None,
};
}
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error path can't be hit (wasn't possible before either, hence InternalError). The only failure from header() is when len > sizeof(u8), but MCTP_USB_MTU_MAX prevents that.

Could just have

let header = Self::header(len).unwrap();
hdr.copy_from_slice(&header);

Comment thread mctp-estack/src/usb.rs Outdated
@@ -150,22 +156,13 @@ impl MctpUsbHandler {
/// `mctplen` is the length of the remaining MCTP packet
/// after the header.
/// `hdr` must be a 4 byte slice.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more hdr argument, can remove this line

Current implementation takes destination variable as a mutable argument and modifies it.
It would be better for the function to simply return the header, rather than an empty `Ok(())` on success.
This breaks the current API for header(), but adjustment should be simple.

Signed-off-by: James Lee <james@codeconstruct.com.au>
@mkj mkj merged commit d90d6ee into CodeConstruct:main May 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants