Skip to content

Commit 95cb0cb

Browse files
Lyudegregkh
authored andcommitted
rust/faux: Add missing parent argument to Registration::new()
A little late in the review of the faux device interface, we added the ability to specify a parent device when creating new faux devices - but this never got ported over to the rust bindings. So, let's add the missing argument now so we don't have to convert other users later down the line. Signed-off-by: Lyude Paul <lyude@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250227193522.198344-1-lyude@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6853d9d commit 95cb0cb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

rust/kernel/faux.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ pub struct Registration(NonNull<bindings::faux_device>);
2323

2424
impl Registration {
2525
/// Create and register a new faux device with the given name.
26-
pub fn new(name: &CStr) -> Result<Self> {
26+
pub fn new(name: &CStr, parent: Option<&device::Device>) -> Result<Self> {
2727
// SAFETY:
2828
// - `name` is copied by this function into its own storage
2929
// - `faux_ops` is safe to leave NULL according to the C API
30-
let dev = unsafe { bindings::faux_device_create(name.as_char_ptr(), null_mut(), null()) };
30+
// - `parent` can be either NULL or a pointer to a `struct device`, and `faux_device_create`
31+
// will take a reference to `parent` using `device_add` - ensuring that it remains valid
32+
// for the lifetime of the faux device.
33+
let dev = unsafe {
34+
bindings::faux_device_create(
35+
name.as_char_ptr(),
36+
parent.map_or(null_mut(), |p| p.as_raw()),
37+
null(),
38+
)
39+
};
3140

3241
// The above function will return either a valid device, or NULL on failure
3342
// INVARIANT: The device will remain registered until faux_device_destroy() is called, which

samples/rust/rust_driver_faux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Module for SampleModule {
2020
fn init(_module: &'static ThisModule) -> Result<Self> {
2121
pr_info!("Initialising Rust Faux Device Sample\n");
2222

23-
let reg = faux::Registration::new(c_str!("rust-faux-sample-device"))?;
23+
let reg = faux::Registration::new(c_str!("rust-faux-sample-device"), None)?;
2424

2525
dev_info!(reg.as_ref(), "Hello from faux device!\n");
2626

0 commit comments

Comments
 (0)