rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: opp: Make the doctest example depend on CONFIG_OF
@ 2025-05-26  5:35 Viresh Kumar
  2025-05-26 11:08 ` Rafael J. Wysocki
  2025-05-26 21:02 ` Miguel Ojeda
  0 siblings, 2 replies; 3+ messages in thread
From: Viresh Kumar @ 2025-05-26  5:35 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar, Nishanth Menon, Stephen Boyd,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, kernel test robot,
	rust-for-linux, linux-kernel

The doctest example uses a function only available for CONFIG_OF and so
the build with doc tests fails when it isn't enabled.

  error[E0599]: no function or associated item named `from_of_cpumask`
  found for struct `rust_doctest_kernel_alloc_kbox_rs_4::kernel::opp::Table`
  in the current scope

Fix this by making the doctest depend on CONFIG_OF.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202505260856.ZQWHW2xT-lkp@intel.com/
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Rafael,

Please apply this directly, if no one objects to it. Thanks.

 rust/kernel/opp.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
index 212555dacd45..c2bdc11f3999 100644
--- a/rust/kernel/opp.rs
+++ b/rust/kernel/opp.rs
@@ -582,6 +582,7 @@ extern "C" fn config_regulators(
 /// use kernel::opp::Table;
 /// use kernel::types::ARef;
 ///
+/// #[cfg(CONFIG_OF)]
 /// fn get_table(dev: &ARef<Device>, mask: &mut Cpumask, freq: Hertz) -> Result<Table> {
 ///     let mut opp_table = Table::from_of_cpumask(dev, mask)?;
 ///
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: opp: Make the doctest example depend on CONFIG_OF
  2025-05-26  5:35 [PATCH] rust: opp: Make the doctest example depend on CONFIG_OF Viresh Kumar
@ 2025-05-26 11:08 ` Rafael J. Wysocki
  2025-05-26 21:02 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2025-05-26 11:08 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Viresh Kumar, Nishanth Menon, Stephen Boyd,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, linux-pm, Vincent Guittot,
	kernel test robot, rust-for-linux, linux-kernel

On Mon, May 26, 2025 at 7:35 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> The doctest example uses a function only available for CONFIG_OF and so
> the build with doc tests fails when it isn't enabled.
>
>   error[E0599]: no function or associated item named `from_of_cpumask`
>   found for struct `rust_doctest_kernel_alloc_kbox_rs_4::kernel::opp::Table`
>   in the current scope
>
> Fix this by making the doctest depend on CONFIG_OF.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202505260856.ZQWHW2xT-lkp@intel.com/
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Rafael,
>
> Please apply this directly, if no one objects to it. Thanks.

Done, thanks!

>
>  rust/kernel/opp.rs | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
> index 212555dacd45..c2bdc11f3999 100644
> --- a/rust/kernel/opp.rs
> +++ b/rust/kernel/opp.rs
> @@ -582,6 +582,7 @@ extern "C" fn config_regulators(
>  /// use kernel::opp::Table;
>  /// use kernel::types::ARef;
>  ///
> +/// #[cfg(CONFIG_OF)]
>  /// fn get_table(dev: &ARef<Device>, mask: &mut Cpumask, freq: Hertz) -> Result<Table> {
>  ///     let mut opp_table = Table::from_of_cpumask(dev, mask)?;
>  ///
> --
> 2.31.1.272.g89b43f80a514
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: opp: Make the doctest example depend on CONFIG_OF
  2025-05-26  5:35 [PATCH] rust: opp: Make the doctest example depend on CONFIG_OF Viresh Kumar
  2025-05-26 11:08 ` Rafael J. Wysocki
@ 2025-05-26 21:02 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2025-05-26 21:02 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, Viresh Kumar, Nishanth Menon, Stephen Boyd,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, linux-pm, Vincent Guittot,
	kernel test robot, rust-for-linux, linux-kernel

On Mon, May 26, 2025 at 7:35 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> +/// #[cfg(CONFIG_OF)]
>  /// fn get_table(dev: &ARef<Device>, mask: &mut Cpumask, freq: Hertz) -> Result<Table> {

Quick note related to this patch for the future/discussion: I think it
is a good idea to keep `cfg`s as local as possible, like it is done
here, although for documentation I wonder if it may be best to put it
at the top and hide it, e.g.

    /// ```
    /// # #![cfg(CONFIG_OPP)]
    /// use kernel::clk::Hertz;

(We took that approach in another example recently)

It is nice that the `CONFIG_`s appear at the top, so that one knows at
a glance when the example applies, as if it was configuration for the
example.

On the other hand, it may be useful for the reader to see immediately
that they will need the `cfg`s. But it may be distracting from the
actual examples, and there could be a need to add it too many times
(e.g. in every related example).

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-26 21:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-26  5:35 [PATCH] rust: opp: Make the doctest example depend on CONFIG_OF Viresh Kumar
2025-05-26 11:08 ` Rafael J. Wysocki
2025-05-26 21:02 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).