1 // SPDX-License-Identifier: GPL-2.0 2 3 //! Rust minimal sample. 4 5 use kernel::prelude::*; 6 7 module! { 8 type: RustMinimal, 9 name: "rust_minimal", 10 authors: ["Rust for Linux Contributors"], 11 description: "Rust minimal sample", 12 license: "GPL", 13 params: { 14 test_parameter: i64 { 15 default: 1, 16 description: "This parameter has a default of 1", 17 }, 18 }, 19 } 20 21 struct RustMinimal { 22 numbers: KVec<i32>, 23 } 24 25 impl kernel::Module for RustMinimal { init(_module: &'static ThisModule) -> Result<Self>26 fn init(_module: &'static ThisModule) -> Result<Self> { 27 pr_info!("Rust minimal sample (init)\n"); 28 pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); 29 pr_info!( 30 "test_parameter: {}\n", 31 *module_parameters::test_parameter.value() 32 ); 33 34 let mut numbers = KVec::new(); 35 numbers.push(72, GFP_KERNEL)?; 36 numbers.push(108, GFP_KERNEL)?; 37 numbers.push(200, GFP_KERNEL)?; 38 39 Ok(RustMinimal { numbers }) 40 } 41 } 42 43 impl Drop for RustMinimal { drop(&mut self)44 fn drop(&mut self) { 45 pr_info!("My numbers are {:?}\n", self.numbers); 46 pr_info!("Rust minimal sample (exit)\n"); 47 } 48 } 49