forked from mirrors/linux
		
	This introduces a module for working with faux devices in rust, along with adding sample code to show how the API is used. Unlike other types of devices, we don't provide any hooks for device probe/removal - since these are optional for the faux API and are unnecessary in rust. Signed-off-by: Lyude Paul <lyude@redhat.com> Cc: MaĆra Canal <mairacanal@riseup.net> Cc: Danilo Krummrich <dakr@kernel.org> Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/2025021026-exert-accent-b4c6@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
		
			
				
	
	
		
			29 lines
		
	
	
	
		
			666 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
	
		
			666 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0-only
 | 
						|
 | 
						|
//! Rust faux device sample.
 | 
						|
 | 
						|
use kernel::{c_str, faux, prelude::*, Module};
 | 
						|
 | 
						|
module! {
 | 
						|
    type: SampleModule,
 | 
						|
    name: "rust_faux_driver",
 | 
						|
    author: "Lyude Paul",
 | 
						|
    description: "Rust faux device sample",
 | 
						|
    license: "GPL",
 | 
						|
}
 | 
						|
 | 
						|
struct SampleModule {
 | 
						|
    _reg: faux::Registration,
 | 
						|
}
 | 
						|
 | 
						|
impl Module for SampleModule {
 | 
						|
    fn init(_module: &'static ThisModule) -> Result<Self> {
 | 
						|
        pr_info!("Initialising Rust Faux Device Sample\n");
 | 
						|
 | 
						|
        let reg = faux::Registration::new(c_str!("rust-faux-sample-device"))?;
 | 
						|
 | 
						|
        dev_info!(reg.as_ref(), "Hello from faux device!\n");
 | 
						|
 | 
						|
        Ok(Self { _reg: reg })
 | 
						|
    }
 | 
						|
}
 |