On Tue Dec 1, 2026 at 11:12 PM JST, Danilo Krummrich wrote:
> On Tue Dec 1, 2026 at 9:15 AM CET, Alexandre Courbot wrote:
>> + pub(crate) fn validate(&self) -> Result {
>> + if self.mctp_magic != Self::MCTP_MAGIC
>> + || !self.mctp_header.has_expected_version()
>> + || !self.nvdm_header.has_nvidia_vendor()
>> + {
>> + return Err(EIO);
>> + }
>> +
>> + let element_len = self.element_len();
>> + if element_len < size_of::<Self>() + self.message_len()
>> + || element_len > GSP_MSG_QUEUE_ELEMENT_SIZE_MAX
>> + {
>> + return Err(EIO);
>> + }
>> +
>> + Ok(())
>> + }
>> +}
>
> [...]
>
>> - /// Validates this header against the expected NVIDIA NVDM format and
>> type.
>> - pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
>> + /// Returns `true` if this NVDM header belongs to a PCI vendor-defined
>> message from NVIDIA.
>> + ///
>> + /// The GPU firmware only ever sends such messages, so a mismatch is a
>> sign of corruption.
>> + pub(crate) fn has_nvidia_vendor(self) -> bool {
>> u8::from(self.msg_type()) == MSG_TYPE_VENDOR_PCI
>> && u16::from(self.vendor_id()) == Vendor::NVIDIA.as_raw()
>> + }
>> +
>> + /// Validates this header against the expected NVIDIA NVDM format and
>> type.
>> + pub(crate) fn validate(self, expected_type: NvdmType) -> bool {
>> + self.has_nvidia_vendor()
>> && matches!(self.nvdm_type(), Ok(nvdm_type) if nvdm_type ==
>> expected_type)
>> }
>> }
>
> NIT: I find has_nvidia_vendor() slighly confusing, as it reads as if it can
> legitimately return false. I think it should either be validate() and
> validate_type(), or define validate() as done by this patch and rename
> has_nvidia_vendor() to has_expected_vendor(), matching has_expected_version().
`has_expected_vendor` sounds good, I like the symmetry.