From nobody Tue Apr 7 18:46:38 2026 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (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 39C45337B8C for ; Thu, 26 Feb 2026 23:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149665; cv=none; b=t+E92yMhDsGIRY5percixBHSN3FpPJypGaEh3o110z24YDS/Ph9wMJL13vLxUftInnuVPxLKCI+3zCmlUIwPpLk26DANzEDZLXctSGLclebzwtL+y6nWt5cwZ14q5hWMcgGuPzYH45BomOcXvHn84taCd0G/7outT96W/5EtLKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772149665; c=relaxed/simple; bh=RHn2hmvCm9HqGAs0R0Q7MI+s5iIBHQPJjHJ3TmmUVZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ufSTCwrB+GWo83lk+oYQPjG1jnvM5/qoCczF4HBV9CdbA/+fGw0TJkxAcSHlMaM+3o1RtXkRfFmkh+0Cx872cxcP0UWEQVOe5XNUnkp9KdTvybyRkRLnK8/lFOUgNSRdRo0VtzvisRqZStNSr7c0nSOk7yB2PeZFrMgi59M9Ui0= 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=T5xbapxx; arc=none smtp.client-ip=74.125.82.49 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="T5xbapxx" Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1271195d2a7so2598258c88.0 for ; Thu, 26 Feb 2026 15:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772149663; x=1772754463; 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=sNVcpj/MlR6xmLdrStuL7mU5hg7ztc2Pvj8nGgrDXrY=; b=T5xbapxxHxmnGx3MweLRwo6oFS9rU/w4h0p6yhze7NFBa1KKwaQJfOQGu8XmUTdJsQ iKU2J8UvnfKTm97ky0id3EbMHfoCQIyMo+u9k4QzZi+jOgZQ10279SpFIjpWFYJEa/vz HoTD4ixtcRN78AS7HaSVhP7UAY4PJlUhCkc1m9Ry+aHHDCD4GxRLcOp166SK565PYYyE wR+ux/xxGSsRZX1+JiwGGCMbXPaTXmTAE2dkTgQkTL3mZAjlGmJ1LaOMfdyz8plNTvnr Bsv63Vcfn6RoIE9UhvPcRXfnwOAGH6tWNkvvBJbK7Xf0k/Hl7qQfCReYougKQZoBWzWm aJrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772149663; x=1772754463; 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=sNVcpj/MlR6xmLdrStuL7mU5hg7ztc2Pvj8nGgrDXrY=; b=EksHmohsFzsRF0wx3mkeIjgA3F5oO9WDtzFWUttC+mFhiEPumP1ghr217k+YAR6Lv7 hZyQSjRUs/dCjfw2Q/aZm1XhqomN2Hp30I7CkCXPnc8Bx/bLw+jIKa7xoudj/w3IoRZW UIWSUnxXPyNPIUCo+7RHU7ggEte/+Xg+VRD+Ah4MiJaZJBugaFyI52cHWdle4Y5A7+yd DcdscGRTDqydxPRh1rrDUMCHRmnA/X3/ZHoYlayWYEvDrHINoP7dPQEvJiEVTmXPzNzK 9dyreCSanF2+ABrR9UNP/C5hXGq+g23jVwf6NJz4yhBPyu0tT6OpVTI5a/iULgp6hsR7 cbFg== X-Forwarded-Encrypted: i=1; AJvYcCVwPHHWE++F9uigc2jE1YA7esFhM0ikuP5ubZD/Tk9ZGGIwcd89qC39v9NA6h0TIQ9/uTlOfLfNAzQd968=@vger.kernel.org X-Gm-Message-State: AOJu0YyG6lnD9ClAj5l6yX5hZgDqe+BTSLgjl4ACzU8Z4RXSX205Q4i4 dizawqcm7q/IFJkjkouao6RFyznsSJvxEgXpXAIrkzLvv03bW42mKy0/ X-Gm-Gg: ATEYQzwbD8vCSb2HoUyHFZkqT+lO6LLeTeyIhIjhwbiZvqe5X2dy2Jy5RYeydP0urUD g7kGOGLP/iC2uVmRJjO81W64frg2MwV6nQmyVU4zgC2uXYJ9TI6YMkBIw1c9HEDGVcr3Y4rXTDI YhpxA5Hbf1bfpfbXLeupelgyPJINq7TaEKah0thXsLh5x4/kAJBqKgwcy4hDrVRNPNmH4ak/EMU rzbRAcdvLsDIyCBUuRAwUKLYzy8kpo4Mhi4nDG7wA6JtI6afMJE2qEJemdSI273+t9q3+x8uR2A WM9LzN0OccmlCVAOq5YnNcdiuWf8AVKpOTBbazNwoy1wqGWjsLtf7kMwy0Yq6AhZXrDSxunO6sN kIN9cwTCLVntIlEE96V5X+5Q6K+L8lsfRgKVkbymhDx4eJhRt3XCVTWLUP19CY5GYtjTjlYyeAM tN+M+PjdXcsWdYPZEwryrkfzQM/uLwjr1+9Ap2KQE3U4YFmJvPmGW0ZOn04wt5VlTSJjeBdB/1B w== X-Received: by 2002:a05:7022:6986:b0:124:a4cf:ce90 with SMTP id a92af1059eb24-1278fc288e8mr352535c88.1.1772149663234; Thu, 26 Feb 2026 15:47:43 -0800 (PST) Received: from localhost (99-122-55-39.lightspeed.sntcca.sbcglobal.net. [99.122.55.39]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a5312dsm3296029c88.16.2026.02.26.15.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 15:47:42 -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 5/8] rust: module_param: add from_setup_arg() to ModuleParam trait Date: Thu, 26 Feb 2026 15:47:31 -0800 Message-ID: <20260226234736.428341-6-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" Extend the ModuleParam trait with from_setup_arg(), which constructs a parameter value from a raw C string pointer received via a __setup callback during early boot. The default implementation converts the pointer to a CStr and delegates to try_from_param_arg(), which handles the parse-from-string path used by integer types. StringParam overrides this method to store the raw pointer directly without parsing, since the pointer originates from static_command_line and remains valid for the kernel's lifetime. Also add ModuleParamAccess::set_value() to allow the __setup callback generated by the module! macro to populate the SetOnce container with first-write-wins semantics. Signed-off-by: Matthew Wood --- rust/kernel/module_param.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs index 54379a2bba51..5e14dbe03865 100644 --- a/rust/kernel/module_param.rs +++ b/rust/kernel/module_param.rs @@ -45,6 +45,21 @@ unsafe impl Sync for ObsKernelParam {} pub trait ModuleParam: Sized + Copy { /// Parse a parameter argument into the parameter value. fn try_from_param_arg(arg: &BStr) -> Result; + + /// Create a parameter value from a raw `__setup` callback argument. + /// + /// Default implementation: parse the null-terminated C string via + /// [`ModuleParam::try_from_param_arg`]. `StringParam` overrides this = to store the pointer + /// directly. + /// + /// # Safety + /// + /// `val` must point to a valid null-terminated string. + unsafe fn from_setup_arg(val: *const c_char) -> Result { + // SAFETY: Caller guarantees `val` points to a valid null-terminat= ed string. + let cstr =3D unsafe { CStr::from_char_ptr(val) }; + Self::try_from_param_arg(cstr.as_ref()) + } } =20 /// Set the module parameter from a string. @@ -226,6 +241,12 @@ fn try_from_param_arg(_arg: &BStr) -> Result { // when using PARAM_OPS_STRING. Err(EINVAL) } + + unsafe fn from_setup_arg(val: *const c_char) -> Result { + // SAFETY: Caller guarantees `val` points to a valid null-terminat= ed string. + // The pointer comes from `static_command_line` which is valid for= the kernel's lifetime. + Ok(unsafe { StringParam::from_ptr(val) }) + } } =20 /// A wrapper for kernel parameters. @@ -266,6 +287,14 @@ pub fn value(&self) -> &T { pub const fn as_void_ptr(&self) -> *mut c_void { core::ptr::from_ref(self).cast_mut().cast() } + + /// Set the parameter value directly. + /// + /// Returns `true` if successfully set, `false` if already populated + /// (first-write-wins semantics via [`SetOnce`]). + pub fn set_value(&self, val: T) -> bool { + self.value.populate(val) + } } =20 #[doc(hidden)] --=20 2.52.0