virtio-devices: vsock: drop unsafe test len helper

The helper only needs to update the packet len field. Use write_slice()
instead of rebuilding a mutable slice from a raw host pointer.

Assisted-by: Codex:GPT-5
Signed-off-by: Dylan Reid <dgreid@fb.com>
This commit is contained in:
Dylan Reid
2026-05-27 11:27:04 -07:00
committed by Rob Bradford
parent dfcc02f547
commit e08f70b6d3

View File

@@ -555,12 +555,11 @@ mod unit_tests {
fn set_pkt_len(len: u32, guest_desc: &GuestQDesc, mem: &GuestMemoryMmap) {
let hdr_gpa = guest_desc.addr.get();
let hdr_ptr =
get_host_address_range(mem, GuestAddress(hdr_gpa), VSOCK_PKT_HDR_SIZE).unwrap();
// SAFETY: The length is valid.
let len_ptr = unsafe { hdr_ptr.add(HDROFF_LEN) };
// SAFETY: The length is valid.
LittleEndian::write_u32(unsafe { std::slice::from_raw_parts_mut(len_ptr, 4) }, len);
mem.write_slice(
&len.to_le_bytes(),
GuestAddress(hdr_gpa + HDROFF_LEN as u64),
)
.expect("test packet header len field should be in guest memory");
}
#[test]