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 test_bool_parameter: bool { 19 default: false, 20 description: "This boolean parameter defaults to false", 21 }, 22 }, 23 } 24 25 struct RustMinimal { 26 numbers: KVec<i32>, 27 } 28 29 impl kernel::Module for RustMinimal { 30 fn init(_module: &'static ThisModule) -> Result<Self> { 31 pr_info!("Rust minimal sample (init)\n"); 32 pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); 33 pr_info!( 34 "test_parameter: {}\n", 35 module_parameters::test_parameter.value() 36 ); 37 pr_info!( 38 "test_bool_parameter: {}\n", 39 module_parameters::test_bool_parameter.value() 40 ); 41 42 let mut numbers = KVec::new(); 43 numbers.push(72, GFP_KERNEL)?; 44 numbers.push(108, GFP_KERNEL)?; 45 numbers.push(200, GFP_KERNEL)?; 46 47 Ok(RustMinimal { numbers }) 48 } 49 } 50 51 impl Drop for RustMinimal { 52 fn drop(&mut self) { 53 pr_info!("My numbers are {:?}\n", self.numbers); 54 pr_info!("Rust minimal sample (exit)\n"); 55 } 56 } 57