rust_minimal.rs 1.1 KB

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