]> www.infradead.org Git - users/jedix/linux-maple.git/commit
rust: miscdevice: add base miscdevice abstraction
authorAlice Ryhl <aliceryhl@google.com>
Tue, 1 Oct 2024 08:22:22 +0000 (08:22 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Oct 2024 10:18:30 +0000 (12:18 +0200)
commitf893691e742688ae21ad597c5bba13bef54706cd
treed6cdc5c1ab1f70bc7629b2b149d220d8b6d63db0
parenta69dc41a4211b0da311ae3a3b79dd4497c9dfb60
rust: miscdevice: add base miscdevice abstraction

Provide a `MiscDevice` trait that lets you specify the file operations
that you wish to provide for your misc device. For now, only three file
operations are provided: open, close, ioctl.

These abstractions only support MISC_DYNAMIC_MINOR. This enforces that
new miscdevices should not hard-code a minor number.

When implementing ioctl, the Result type is used. This means that you
can choose to return either of:
* An integer of type isize.
* An errno using the kernel::error::Error type.
When returning an isize, the integer is returned verbatim. It's mainly
intended for returning positive integers to userspace. However, it is
technically possible to return errors via the isize return value too.

To avoid having a dependency on files, this patch does not provide the
file operations callbacks a pointer to the file. This means that they
cannot check file properties such as O_NONBLOCK (which Binder needs).
Support for that can be added as a follow-up.

To avoid having a dependency on vma, this patch does not provide any way
to implement mmap (which Binder needs). Support for that can be added as
a follow-up.

Rust Binder will use these abstractions to create the /dev/binder file
when binderfs is disabled.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/rust-for-linux/20240328195457.225001-1-wedsonaf@gmail.com/
Link: https://lore.kernel.org/r/20241001-b4-miscdevice-v2-2-330d760041fa@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/bindings/bindings_helper.h
rust/kernel/lib.rs
rust/kernel/miscdevice.rs [new file with mode: 0644]