Showcase the rust module parameter support by adding a module parameter to
the `rust_minimal` sample.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
samples/rust/rust_minimal.rs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs
index 1fc7a1be6b6d..c04cc07b3249 100644
--- a/samples/rust/rust_minimal.rs
+++ b/samples/rust/rust_minimal.rs
@@ -10,6 +10,12 @@
authors: ["Rust for Linux Contributors"],
description: "Rust minimal sample",
license: "GPL",
+ params: {
+ test_parameter: i64 {
+ default: 1,
+ description: "This parameter has a default of 1",
+ },
+ },
}
struct RustMinimal {
@@ -20,6 +26,10 @@ impl kernel::Module for RustMinimal {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Rust minimal sample (init)\n");
pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
+ pr_info!(
+ "test_parameter: {}\n",
+ *module_parameters::test_parameter.get()
+ );
let mut numbers = KVec::new();
numbers.push(72, GFP_KERNEL)?;
--
2.47.2
(Sorry for being late on this one, just a minor nit below.) On 6/12/25 3:40 PM, Andreas Hindborg wrote: > struct RustMinimal { > @@ -20,6 +26,10 @@ impl kernel::Module for RustMinimal { > fn init(_module: &'static ThisModule) -> Result<Self> { > pr_info!("Rust minimal sample (init)\n"); > pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); > + pr_info!( > + "test_parameter: {}\n", > + *module_parameters::test_parameter.get() Can we please call it something else than get(), maybe obtain(), access() or just ref()? > + ); > > let mut numbers = KVec::new(); > numbers.push(72, GFP_KERNEL)?; >
"Danilo Krummrich" <dakr@kernel.org> writes: > (Sorry for being late on this one, just a minor nit below.) > > On 6/12/25 3:40 PM, Andreas Hindborg wrote: >> struct RustMinimal { >> @@ -20,6 +26,10 @@ impl kernel::Module for RustMinimal { >> fn init(_module: &'static ThisModule) -> Result<Self> { >> pr_info!("Rust minimal sample (init)\n"); >> pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); >> + pr_info!( >> + "test_parameter: {}\n", >> + *module_parameters::test_parameter.get() > > Can we please call it something else than get(), maybe obtain(), access() or > just ref()? Probably `ref` is the most precise of the options you propose. I would go with that one. Or, should it be `as_ref`? Best regards, Andreas Hindborg
On 6/30/25 2:12 PM, Andreas Hindborg wrote: > "Danilo Krummrich" <dakr@kernel.org> writes: > >> (Sorry for being late on this one, just a minor nit below.) >> >> On 6/12/25 3:40 PM, Andreas Hindborg wrote: >>> struct RustMinimal { >>> @@ -20,6 +26,10 @@ impl kernel::Module for RustMinimal { >>> fn init(_module: &'static ThisModule) -> Result<Self> { >>> pr_info!("Rust minimal sample (init)\n"); >>> pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); >>> + pr_info!( >>> + "test_parameter: {}\n", >>> + *module_parameters::test_parameter.get() >> >> Can we please call it something else than get(), maybe obtain(), access() or >> just ref()? > > Probably `ref` is the most precise of the options you propose. I would > go with that one. Or, should it be `as_ref`? Guess that works as well. One question additional question: Can't we just impl Deref for ModuleParamAccess<T>?
On 6/30/25 2:18 PM, Danilo Krummrich wrote: > On 6/30/25 2:12 PM, Andreas Hindborg wrote: >> "Danilo Krummrich" <dakr@kernel.org> writes: >> >>> (Sorry for being late on this one, just a minor nit below.) >>> >>> On 6/12/25 3:40 PM, Andreas Hindborg wrote: >>>> struct RustMinimal { >>>> @@ -20,6 +26,10 @@ impl kernel::Module for RustMinimal { >>>> fn init(_module: &'static ThisModule) -> Result<Self> { >>>> pr_info!("Rust minimal sample (init)\n"); >>>> pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); >>>> + pr_info!( >>>> + "test_parameter: {}\n", >>>> + *module_parameters::test_parameter.get() >>> >>> Can we please call it something else than get(), maybe obtain(), access() or >>> just ref()? >> >> Probably `ref` is the most precise of the options you propose. I would >> go with that one. Or, should it be `as_ref`? > > Guess that works as well. > > One question additional question: Can't we just impl Deref for > ModuleParamAccess<T>? Just notice that it would work for now, but not in the future, because this will apparently require some lock guard? Then maybe access() describes it best?
On Mon Jun 30, 2025 at 2:23 PM CEST, Danilo Krummrich wrote: > On 6/30/25 2:18 PM, Danilo Krummrich wrote: >> On 6/30/25 2:12 PM, Andreas Hindborg wrote: >>> "Danilo Krummrich" <dakr@kernel.org> writes: >>> >>>> (Sorry for being late on this one, just a minor nit below.) >>>> >>>> On 6/12/25 3:40 PM, Andreas Hindborg wrote: >>>>> struct RustMinimal { >>>>> @@ -20,6 +26,10 @@ impl kernel::Module for RustMinimal { >>>>> fn init(_module: &'static ThisModule) -> Result<Self> { >>>>> pr_info!("Rust minimal sample (init)\n"); >>>>> pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); >>>>> + pr_info!( >>>>> + "test_parameter: {}\n", >>>>> + *module_parameters::test_parameter.get() >>>> >>>> Can we please call it something else than get(), maybe obtain(), access() or >>>> just ref()? >>> >>> Probably `ref` is the most precise of the options you propose. I would >>> go with that one. Or, should it be `as_ref`? >> >> Guess that works as well. >> >> One question additional question: Can't we just impl Deref for >> ModuleParamAccess<T>? > > Just notice that it would work for now, but not in the future, because this will > apparently require some lock guard? Then maybe access() describes it best? What about `value()`? --- Cheers, Benno
On Thu Jun 12, 2025 at 3:40 PM CEST, Andreas Hindborg wrote: > Showcase the rust module parameter support by adding a module parameter to > the `rust_minimal` sample. > > Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Benno Lossin <lossin@kernel.org> --- Cheers, Benno > --- > samples/rust/rust_minimal.rs | 10 ++++++++++ > 1 file changed, 10 insertions(+)
© 2016 - 2025 Red Hat, Inc.