Re: [PATCH 3/5] rust: miscdevice: Provide additional abstractions for iov_iter and kiocb structures

From: Andreas Hindborg
Date: Wed Mar 19 2025 - 16:17:05 EST


"Alice Ryhl" <aliceryhl@xxxxxxxxxx> writes:

> These will be used for the read_iter() and write_iter() callbacks, which
> are now the preferred back-ends for when a user operates on a char device
> with read() and write() respectively.
>
> Co-developed-by: Lee Jones <lee@xxxxxxxxxx>
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

[...]

> +impl<'a, T: ForeignOwnable> Kiocb<'a, T> {
> + /// Get the private data in this kiocb.
> + pub fn private_data(&self) -> <T as ForeignOwnable>::Borrowed<'a> {
> + // SAFETY: The `kiocb` lets us access the private data.
> + let private = unsafe { (*(*self.inner.as_ptr()).ki_filp).private_data };
> + // SAFETY: The kiocb has shared access to the private data.
> + unsafe { <T as ForeignOwnable>::borrow(private) }
> + }

Another quick observation: `kiocb` has a `void *private` field that is
used in the same way that `struct file` `private_data` field is used.
The naming of this function is misleading, since it does not return the
`kiocb` private data.

Either rename this function or exchange it for an access method for the
associated file.


Best regards,
Andreas Hindborg