diff options
| author | Wenzhao Liao <wenzhaoliao@ruc.edu.cn> | 2026-04-11 09:02:54 -0400 |
|---|---|---|
| committer | Petr Pavlu <petr.pavlu@suse.com> | 2026-08-06 13:29:03 +0200 |
| commit | da991304c9afc0f1567033ac743ce27dcc947652 (patch) | |
| tree | 993456862d8005a78a52f526be7006f76ccc8b8a /samples | |
| parent | 327d44754c54060baf9679ac073a21839912be16 (diff) | |
| download | linux-da991304c9afc0f1567033ac743ce27dcc947652.tar.gz linux-da991304c9afc0f1567033ac743ce27dcc947652.zip | |
rust: module_param: support bool parameters
Add support for parsing boolean module parameters in the Rust
module! macro.
Currently, only integer types are supported by the `module_param!`
macros. This patch implements the `ModuleParam` trait for `bool`
by delegating the string parsing to the existing C implementation
via `kstrtobool_bytes()`. It also wires up `PARAM_OPS_BOOL` so that
the Rust parameter system correctly links to the C `param_ops_bool`
structure.
For demonstration and verification, a boolean parameter is added
to `samples/rust/rust_minimal.rs`.
Support for boolean parameters will initially be used by the Rust
null block driver [1].
Link: https://lore.kernel.org/all/20260609-rnull-v6-19-rc5-send-v2-4-82c7404542e2@kernel.org/ [1]
Assisted-by: Codex:GPT-5
Signed-off-by: Wenzhao Liao <wenzhaoliao@ruc.edu.cn>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Link: https://lore.kernel.org/linux-modules/20260411130254.3510128-1-wenzhaoliao@ruc.edu.cn/
[ppavlu: add motivation to the commit message and rebase the patch]
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/rust/rust_minimal.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 60d03df6cd80..8c910d314dfa 100644 --- a/samples/rust/rust_minimal.rs +++ b/samples/rust/rust_minimal.rs @@ -15,6 +15,10 @@ module! { default: 1, description: "This parameter has a default of 1", }, + test_bool_parameter: bool { + default: false, + description: "This boolean parameter defaults to false", + }, }, } @@ -30,6 +34,10 @@ impl kernel::Module for RustMinimal { "test_parameter: {}\n", module_parameters::test_parameter.value() ); + pr_info!( + "test_bool_parameter: {}\n", + module_parameters::test_bool_parameter.value() + ); let mut numbers = KVec::new(); numbers.push(72, GFP_KERNEL)?; |
