From nobody Tue Apr 7 18:46:39 2026 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCADF332EC9 for ; Thu, 26 Feb 2026 23:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149663; cv=none; b=DZOO6YlBWtx9RyWEbfdAvur1tXk7bhc07IJnYsuQ3CqsRXMNJTMrAG0a0l4xvBDwCHbVRIK77h95Aiu3xFCQBY1rubVD5HOMPQHv1gR5U5wRgDgIpqhcIFumlrINxbVjVY8FR3eLK9nxF/NeXAEoAZ8XHMelfAOUeeWeuIbn+lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149663; c=relaxed/simple; bh=PEStsCfUg1vck30VzbuzLY18WcACc8ezhy6sImv5QbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCM9e0pxFqLEyyfIr15NgzdVuVfu3V2bSDQpBH/Uhm895IhYBTpRC07p0JqfC0HGav6wOM+2EPHivmvFTiaG6fPFWrxL/GkWg/oy5YeHo6LJTBVuoZbiYY60cyZIWyMZlWxl+IRgiK4OcQoMNJSrNf2qnFnM/QVEC+P8SuWJecM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S6f06dGg; arc=none smtp.client-ip=74.125.82.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S6f06dGg" Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-2bdc4f2b680so1151189eec.1 for ; Thu, 26 Feb 2026 15:47:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149661; x=1772754461; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CL8jxHXJRXWZMH+LIIg5DtNI0nPNnxmf0FX4+vNJA2Q=; b=S6f06dGg0w8gcTAjDnQZFXinm4gT7G2IlqeGf9SbOBXlbC4O4laX551x+IMKXow3SR gk+avOwqge1Fhd641eqfxaYQqArsW2l8eeYa58wVU59hHmlxoQ8AK2+KO1WbyzLgduhs ESeLWXaYcQYro+Bq1Ooux5X1w8D6660PJgOU11W8Om0tipiGrKro1NjTDX02hi9hfvKd jxpc7pHYAHPYZatWITDmAikuGW0q4+x1rBfk16uuJzcqgtPy5JL1LwlhFIFwz4RoBbuf v9m6zq3ClKuZJvwuVxO5rddRUTjZS+7gewgKnl+3Mui044CI3irSdlbPOKTRW6dauVuW fA2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149661; x=1772754461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CL8jxHXJRXWZMH+LIIg5DtNI0nPNnxmf0FX4+vNJA2Q=; b=GdL+oguOJVe0U4NYDTZjSaORTUNbhNB2R15QmEjVwGctskC+Zb9cUZ74JC5vkjktbs cUvqTqhORdr/afjmbdW0gSTMGK/rMi4gofMHx+xPy75VMjs+cXv2p1FV+WTf2YcKkjHv CFGx/s//MY+LIy3G2UKuhyS5YAiNVFUXVrQOL9LfwdI581i+1LdH4g6F7TlzaDSp0sQ8 KrpVqSI+MqGRIJsYVLL/OhTgAIXqM2QMN8e5M2QLZ0GgBCMAiW9GEXs586M0nZyeuh/N jN47tWL/2niXVmqkzG0oOj//BwCsfxAR7QCKEWRbk1bqKDXmBPSWYt47Bg8kbDXycpJm 3fgw== X-Forwarded-Encrypted: i=1; AJvYcCXdMK6BJ0tTdj3pXgtZYWljcI+nUpiKRGR0FNMQZcG/Jgzfvh3qD2hk2YQYmUmh4WnlvZZK5g2+G5bHMPM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/MOP04qbywX84lkBYAg6Qs3C3xrBHnmccrlado/6MPWQ/bcpf tvMGfO3uf/D5LvrnYDksopZMfmw5elhdk4CuaVHdRAWoD5bgJMm6TQEB X-Gm-Gg: ATEYQzyKwQpLKpF88Bpm+U91phy1JDZZ2CK+sgbQFwqDBs8mKHh8kOnKm3ZAGv9P/QT JqWI8w4eOtee3RQagP92BswIjpm4B4i8nZBf1Xs94dUJ5694TJQZgQlSNEa2PXfR42g6tBrtSKQ 3Y4htAxIL9wgH0BaldZNvUYoChpBvHuynvX7g1y+FSe4BgpksrweqhumBmpQFPHnTQArzRXVf1w AEeL2zNF2f63/znbHkk2e3fRhEthmO+4bMGTFAA75qBQq4bKUj9DO8g/DNmFFsJWlI47kte5jUQ mqxjVXflZN09RIwSZg1uLx5o0sSWtD7fIbqd635XBYRfs+3SGapWC1eqOvE+erNYUjL/HaX1Jxx B1+7Vz1yL7b5Z0l3w3wLLAV4wB3DQ8GVXPxNJId6Y7QUX/NwgPaPtGpiO55aFQ8tGXHt5CcLy2s NwgDu7Jy8OIQQ9SYOcmlyQwoXURofpqqQSzc0wz66fUyQNz/uNrBPfJQ0wg7H1NRzvwPpIOCF5X A== X-Received: by 2002:a05:7300:538e:b0:2b0:5b6b:6529 with SMTP id 5a478bee46e88-2bde1ff2aedmr322221eec.39.1772149660935; Thu, 26 Feb 2026 15:47:40 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1f49d96sm2726909eec.27.2026.02.26.15.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:40 -0800 (PST) From: Matthew Wood To: Miguel Ojeda , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen Cc: Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] samples: rust_minimal: demonstrate string module parameter Date: Thu, 26 Feb 2026 15:47:29 -0800 Message-ID: <20260226234736.428341-4-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com> References: <20260226234736.428341-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a `test_str` string parameter alongside the existing integer parameter (renamed from `test_parameter` to `test_int` for clarity) in the rust_minimal sample module. The init function now prints both parameters to the kernel log, showing how string parameters are declared, defaulted, and read back via StringParam::as_cstr(). Also add module-level documentation showing usage via insmod and kernel command-line with dotted notation. Signed-off-by: Matthew Wood --- samples/rust/rust_minimal.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 8eb9583571d7..59955e95e31a 100644 --- a/samples/rust/rust_minimal.rs +++ b/samples/rust/rust_minimal.rs @@ -1,6 +1,23 @@ // SPDX-License-Identifier: GPL-2.0 =20 //! Rust minimal sample. +//! +//! This is a sample module written in Rust. It is intended to be a minimal +//! example of how to write a module in Rust. It does not do anything usef= ul, +//! except print a message when it is loaded and unloaded. +//! +//! It provides examples of how to receive module parameters, which can be= provided +//! by the user when the module is loaded: +//! +//! ``` +//! insmod /lib/modules/$(uname -r)/kernel/samples/rust/rust_minimal.ko te= st_int=3D2 test_str=3Dworld +//! ``` +//! +//! or via kernel cmdline with module dotted notation (when built-in and n= ot built as a module): +//! +//! ``` +//! ... rust_minimal.test_int=3D2 rust_minimal.test_str=3Dworld ... +//! ``` =20 use kernel::prelude::*; =20 @@ -11,10 +28,14 @@ description: "Rust minimal sample", license: "GPL", params: { - test_parameter: i64 { + test_int: i64 { default: 1, description: "This parameter has a default of 1", }, + test_str: string { + default: "hello", + description: "This parameter has a default of hello", + } }, } =20 @@ -26,9 +47,13 @@ impl kernel::Module for RustMinimal { fn init(_module: &'static ThisModule) -> Result { pr_info!("Rust minimal sample (init)\n"); pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); + pr_info!("test_int: {}\n", *module_parameters::test_int.value()); pr_info!( - "test_parameter: {}\n", - *module_parameters::test_parameter.value() + "test_str: {}\n", + module_parameters::test_str + .value() + .as_cstr() + .expect("test_str has a default value") ); =20 let mut numbers =3D KVec::new(); --=20 2.52.0