On Wed, Jan 28, 2026 at 08:28:33PM -0600, Timur Tabi wrote:
> [PATCH v6 3/7] gpu: nova-core: implement BinaryWriter for 
> CoherentAllocation<u8>

The commit title says 'gpu: nova-core:' but this is primarily a change
to rust/kernel/dma.rs, so it should say 'rust: dma:' or similar.

> +// SAFETY: Sharing `&CoherentAllocation` across threads is safe if `T` is 
> `Sync`, because all
> +// methods that access the buffer contents (`field_read`, `field_write`, 
> `as_slice`,
> +// `as_slice_mut`) are `unsafe`, and callers are responsible for ensuring no 
> data races occur.
> +// The safe methods only return metadata or raw pointers whose use requires 
> `unsafe`.
> +unsafe impl<T: AsBytes + FromBytes + Sync> Sync for CoherentAllocation<T> {}

This change is unrelated to implementing BinaryWriter for
CoherentAllocation.

> +impl debugfs::BinaryWriter for CoherentAllocation<u8> {
> +    fn write_to_slice(
> +        &self,
> +        writer: &mut UserSliceWriter,
> +        offset: &mut file::Offset,
> +    ) -> Result<usize> {
> +        if offset.is_negative() {
> +            return Err(EINVAL);
> +        }
> +
> +        let offset_val: usize = (*offset).try_into().map_err(|_| EINVAL)?;

If the user seeks to a large offset, this leads to EINVAL. But the
correct behavior for a file is to simply return Ok(0) in such case.

Alice

Reply via email to