From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: gpu: nova-core: vbios: read BitToken using FromBytes Date: Tue, 26 May 2026 07:03:40 +1000 Message-ID: In-Reply-To: <20260525-fix-vbios-v5-4-e5e455251537@nvidia.com> References: <20260525-fix-vbios-v5-0-e5e455251537@nvidia.com> <20260525-fix-vbios-v5-4-e5e455251537@nvidia.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Patch Review Good conversion. The manual byte-by-byte construction of `BitToken` is replaced with `FromBytes`, which is both safer and cleaner. Adding `#[repr(C)]` is required for `FromBytes` to have defined layout. ```rust // SAFETY: all bit patterns are valid for `BitToken`. unsafe impl FromBytes for BitToken {} ``` This safety comment is correct -- `BitToken` is `{u8, u8, u16, u16}`, all of which accept any bit pattern, and `#[repr(C)]` ensures the layout is predictable. The checked arithmetic for `entry_offset` using `checked_mul`/`checked_add` is appropriate since both `token_size` and `token_entries` come from firmware. **Minor note:** The original code checked `entry_offset + header.token_size > data.len()` but the new code uses `.get(entry_offset..).and_then(|data| data.get(..entry_size))` which achieves the same bounds check more idiomatically. However, if `entry_size < size_of::()`, `from_bytes_copy_prefix` will return `None` and the `.ok_or(EINVAL)?` catches it. This is correct. --- Generated by Claude Code Patch Reviewer