Skip to content

pldm-fw: ua: send actual component count in RequestUpdate#59

Open
brcarr-nv wants to merge 1 commit into
CodeConstruct:mainfrom
brcarr-nv:patch1
Open

pldm-fw: ua: send actual component count in RequestUpdate#59
brcarr-nv wants to merge 1 commit into
CodeConstruct:mainfrom
brcarr-nv:patch1

Conversation

@brcarr-nv

Copy link
Copy Markdown

request_update() hardcoded the RequestUpdate NumberOfComponents field to 1. DSP0267 Table 27 defines this field as "the number of components that will be passed to the FD during the update", and the FD may use it to compare against the number of PassComponentTable/UpdateComponent commands it receives. When a package applies more than one component, the UA passes all of them (pass_component_table and update_components_progress iterate over update.components) while still announcing only 1, which a conformant FD can reject as a mismatch.

Derive the count from update.components, the same list driven through the rest of the update flow, so the announced value matches what is actually sent. The value is fallibly converted to u16 to guard the (practically impossible) >65535 component case rather than truncating.

request_update() hardcoded the RequestUpdate NumberOfComponents field
to 1. DSP0267 Table 27 defines this field as "the number of components
that will be passed to the FD during the update", and the FD may use it
to compare against the number of PassComponentTable/UpdateComponent
commands it receives. When a package applies more than one component,
the UA passes all of them (pass_component_table and
update_components_progress iterate over update.components) while still
announcing only 1, which a conformant FD can reject as a mismatch.

Derive the count from update.components, the same list driven through
the rest of the update flow, so the announced value matches what is
actually sent. The value is fallibly converted to u16 to guard the
(practically impossible) >65535 component case rather than truncating.

Add a unit test (request_update_reports_actual_component_count) that
drives request_update over a mock MCTP ReqChannel and asserts the
RequestUpdate NumberOfComponents field reflects the actual component
count, along with the cfg(test) package-builder and temp-file helpers it
depends on.

Signed-off-by: Brian Carr <brcarr@nvidia.com>

@mkj mkj left a comment

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.

Thanks for the fix. Some comments on simplifying tests

Comment thread pldm-fw/src/pkg.rs
Comment on lines +349 to +350
#[cfg(test)]
pub(crate) fn build_v11_package(vid: u16, components: &[&[u8]]) -> Vec<u8> {

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.

This can go in a

#[cfg(test)]
pub(crate) mod tests {

Comment thread pldm-fw/src/ua.rs

#[derive(Clone, Default)]
struct MockComm {
st: Rc<RefCell<CommState>>,

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 need for Rc<RefCell>, send_vectored() and recv() take &mut self.
So responses/send can be members of MockComm, don't need CommState

Comment thread pldm-fw/src/pkg.rs
/// The file is unlinked immediately; the returned handle keeps it alive, so
/// the on-disk entry is cleaned up automatically once the handle is dropped.
#[cfg(test)]
pub(crate) fn temp_file_with(bytes: &[u8]) -> std::fs::File {

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.

For tests I'd be fine with a dev-dependency of tempfile::tempfile(), but this looks right too.

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.

2 participants