From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 47EED38657B for ; Wed, 4 Mar 2026 08:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772611986; cv=none; b=P7l5b+pfneQL6enrsH8V4isKzwVvKAnCDp1+hKzRLAK6r1BnpRa7XNEANjNJjTm7qgV+pcqV3ZIM22Qmf18MATwqFDw+fXT/swTqYIWuF/J5sWO7Jcyz6urfi2s9RCVzhRZRxenewAXvj+e/KhfuU98HrSXTaal+GVN10H3pb20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772611986; c=relaxed/simple; bh=crWmgNqlnMBQ03nDgNxxQUvIWj21atNNvKm8ubqqak0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eX92EH3fkEMA4l55NoUXAEKyqQyT9eh5lftGHmWc4uoE26vbPGl/Gzvd5IjBZDzWlAay17NmU2UdQkvsiex9roQzNpWk1yNo4j9FsIFBISSeooBCxeJMDEztPj9jfQ2Vr97pTHqTPm3T1TMDnFRZMYzk4VyAoMsWC7LlhNIIHf4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=RNHuSUO8; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="RNHuSUO8" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-439b9b190easo1901780f8f.2 for ; Wed, 04 Mar 2026 00:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1772611983; x=1773216783; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=lkljEEI7m7cvv1eaHcluPEw1Mfpi3L3tnqN5jye2x18=; b=RNHuSUO8Nix+PnIrKdsux+HzYnBwJJzG/fUSeLzNICww/skyl1gwIGV1OfoxYlJ63Q f5uk1WA3nsukO8gRf7+eU9/xeasxp3bA6GLdDzzkboFCLGqO+uThKdfgXHf0xjkZOZKk vIJQ6/3pYuLReI992EkGhKchXpg8RZjJlj5cUZ+wE6qoWxeAQouVPcHlSowxAJ25Mp1a aCcpd/Cv6uEZuG6SY4zjGOPPsflDR8B04kTi1cBEBrLfzA1TH3DbtpP4lOYP4G2LfNfK ifv8W+LzNoadTtzFxiiXtr7pkIoUim+PqZA2NgyqnJbv/A3VWeetLAGxJV2BaeZ3GQm/ zteQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772611983; x=1773216783; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lkljEEI7m7cvv1eaHcluPEw1Mfpi3L3tnqN5jye2x18=; b=vSlgwykaONtTyqYxsSjWeTAy12jib1kKg6lh7ARr+fSkhAKhCwFov8nbkQNZOc5Vg/ pNXca/w3jBFvC/A0q+p+2+a56SJFGyZGcX5gkmnsDfe/qVmyHukvMCa8YqchFxUHqMIw NGida3dvtmiNMw3r1YFyyCRTjxL6DHXI1kuDiUQaja/Z0mjWqwDiCK8/RFqqyt1Ig981 2O2TLa23hWExYETI6ia6wG/cnaRqPSS32+rpDOk8GwmYT6ACEb77fbYl5dGpgCK0O0/D eRvVKduV9CAk6D8TkF2afw9KGs/bV22ORKs/qEs8XmP+aUFwbShL531OyfauHOBB4ZfC VwXw== X-Forwarded-Encrypted: i=1; AJvYcCVqU7qkwSoCY+Qz9b3kS0Mf/BLh/hO0oUTuJgox+Frouo49A+1YXze7kxKu/AElN+OaavmbYi0y0zxQIps=@vger.kernel.org X-Gm-Message-State: AOJu0YwG9b62sLNdX7alKcTqm9YixoZl1/rh1Gdxj2+BY6otxETaciBw /c8jM8+XiCEZYYcaAGMGYmaXJzWRsVgz38krGayuYpyLMZ5GGNCiA1LPlL25U86VKIo= X-Gm-Gg: ATEYQzwVw3t2eqlYFuG+z9aIaPaPPgkN8SP+2H2CXVM+Zl79SfgNSOfZNtf2qHxIPy8 XBwGFpJHnKiKXI85I6P/J7J7HFyl72A4ecNBWa/tRqxcZeR9Y8NUwhX42JTiZxHhc2qX2FAZuRq bKaxd1Il6uEePomeI8/HEEPTOxQ1WgV6/+4cSsWmRLiZmr8qCi93jZJGwbPaSiUnJ5KqFpfcNMa YlLqJnPUcoX7bkePkBU4LF4tdEI4qwXcbD3QRk8pJ5cfVP95I2z49//47Es3AyNkZBEPij5S8FQ fDoS4sfitNLiQMezV3Q5Q0DW+dXm513/GaAPP8xqxa04nL9v6gOGlLvn7KUNs5XPWL4UrlSN0KH M+IhrH9HxVNjYVjKN6MD3HfZwWPDKdRw6JV+mKR3SD2HUJu96Egnc+hxB9kSGKvwJiVe/XDQwFS phQ8kksApa9tQMj2B6eWo1PWb21ccuBcSWsvwaHnZrgRgcAEo+QOcZJUwN/VkfFi1mRq3LQbkEw PPhf/WtDvcbvGnzybzDdLcpFAez/zR3MD5jWQTX1QqZnqUEgbOrrXhrckNGSYYgmZpm2g== X-Received: by 2002:a5d:5d0b:0:b0:439:a9a5:d3e9 with SMTP id ffacd0b85a97d-439c7fd3cfbmr2326625f8f.30.1772611983540; Wed, 04 Mar 2026 00:13:03 -0800 (PST) Received: from ?IPV6:2a00:1028:838d:271e:8e3b:4aff:fe4c:a100? (dynamic-2a00-1028-838d-271e-8e3b-4aff-fe4c-a100.ipv6.o2.cz. [2a00:1028:838d:271e:8e3b:4aff:fe4c:a100]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439b0549600sm26602877f8f.35.2026.03.04.00.13.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Mar 2026 00:13:03 -0800 (PST) Message-ID: Date: Wed, 4 Mar 2026 09:13:02 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/8] rust: module_param: wire StringParam into the module! macro To: Matthew Wood Cc: Miguel Ojeda , Luis Chamberlain , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Tamir Duberstein , David Gow , =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= , linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260226234736.428341-1-thepacketgeek@gmail.com> <20260226234736.428341-3-thepacketgeek@gmail.com> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20260226234736.428341-3-thepacketgeek@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/27/26 12:47 AM, Matthew Wood wrote: > Add support for `string` as a parameter type in the module! macro. > > On the runtime side, add: > - set_string_param(): an extern "C" callback matching the > kernel_param_ops::set signature that stores the raw C string > pointer directly into the SetOnce container, avoiding > an unnecessary copy-and-parse round-trip. > - PARAM_OPS_STRING: a static kernel_param_ops that uses > set_string_param as its setter. > - ModuleParam impl for StringParam with try_from_param_arg() > returning -EINVAL, since string parameters are populated > exclusively through the kernel's set callback. > > On the macro side: > - Change the Parameter::ptype field from Ident to syn::Type to > support path-qualified types. Why is it necessary to change the type of Parameter::ptype? My understanding is that this token can currently be "i8", "u8", ..., "isize", "usize". Additionally, the value "string" should now be accepted. When should one use a path-qualified type in this context? > - Recognize the `string` shorthand and resolve it to the fully > qualified ::kernel::module_param::StringParam type during code > generation. > - Wrap string default values with StringParam::from_c_str(c_str!(...)) > to produce a compile-time CStr-backed default. > - Route `string` to PARAM_OPS_STRING in param_ops_path(). > > Signed-off-by: Matthew Wood > --- > rust/kernel/module_param.rs | 48 +++++++++++++++++++++++++++++++++++++ > rust/macros/module.rs | 42 +++++++++++++++++++++++++------- > 2 files changed, 81 insertions(+), 9 deletions(-) > > diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs > index 80fe8643c0ab..67ff6f2ea9c2 100644 > --- a/rust/kernel/module_param.rs > +++ b/rust/kernel/module_param.rs > @@ -86,6 +86,36 @@ pub trait ModuleParam: Sized + Copy { > }) > } > > +/// Set a string module parameter from a string. > +/// > +/// Similar to [`set_param`] but for [`StringParam`]. > +/// > +/// # Safety > +/// > +/// Same requirements as [`set_param`]. > +unsafe extern "C" fn set_string_param( > + val: *const c_char, > + param: *const bindings::kernel_param, > +) -> c_int { The safety comment is somewhat inaccurate because set_param() says that the input value needs to be valid only for the duration of the call, whereas set_string_param() and StringParam require it to be valid for the module's lifetime. -- Thanks, Petr