rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] rust: device: allow `Device<DeviceContext>::parent()`
@ 2025-04-29 21:06 Miguel Ojeda
  2025-04-29 21:20 ` Miguel Ojeda
  2025-04-29 21:52 ` Danilo Krummrich
  0 siblings, 2 replies; 3+ messages in thread
From: Miguel Ojeda @ 2025-04-29 21:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Miguel Ojeda, Alex Gaynor
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, rust-for-linux,
	linux-kernel, patches

When `CONFIG_AUXILIARY_BUS` is disabled, `parent()` is still dead code:

    error: method `parent` is never used
      --> rust/kernel/device.rs:71:19
       |
    64 | impl<Ctx: DeviceContext> Device<Ctx> {
       | ------------------------------------ method in this implementation
    ...
    71 |     pub(crate) fn parent(&self) -> Option<&Self> {
       |                   ^^^^^^
       |
       = note: `-D dead-code` implied by `-D warnings`
       = help: to override `-D warnings` add `#[allow(dead_code)]`

Thus reintroduce the `expect`, but now as a conditional one. Do so as
`dead_code` since that is narrower.

An `allow` would also be possible, but Danilo wants to catch new users
in the future [1].

Link: https://lore.kernel.org/rust-for-linux/aBE8qQrpXOfru_K3@pollux/ [1]
Fixes: ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 rust/kernel/device.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index 40c1f549b0ba..f08583fa39c9 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -68,6 +68,7 @@ pub(crate) fn as_raw(&self) -> *mut bindings::device {
     }
 
     /// Returns a reference to the parent device, if any.
+    #[cfg_attr(not(CONFIG_AUXILIARY_BUS), expect(dead_code))]
     pub(crate) fn parent(&self) -> Option<&Self> {
         // SAFETY:
         // - By the type invariant `self.as_raw()` is always valid.

base-commit: ce735e73dd59b169b877cedd0753297c81c2a091
-- 
2.49.0


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

* Re: [PATCH v2] rust: device: allow `Device<DeviceContext>::parent()`
  2025-04-29 21:06 [PATCH v2] rust: device: allow `Device<DeviceContext>::parent()` Miguel Ojeda
@ 2025-04-29 21:20 ` Miguel Ojeda
  2025-04-29 21:52 ` Danilo Krummrich
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2025-04-29 21:20 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	rust-for-linux, linux-kernel, patches

On Tue, Apr 29, 2025 at 11:06 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> When `CONFIG_AUXILIARY_BUS` is disabled, `parent()` is still dead code:
>
>     error: method `parent` is never used
>       --> rust/kernel/device.rs:71:19
>        |
>     64 | impl<Ctx: DeviceContext> Device<Ctx> {
>        | ------------------------------------ method in this implementation
>     ...
>     71 |     pub(crate) fn parent(&self) -> Option<&Self> {
>        |                   ^^^^^^
>        |
>        = note: `-D dead-code` implied by `-D warnings`
>        = help: to override `-D warnings` add `#[allow(dead_code)]`
>
> Thus reintroduce the `expect`, but now as a conditional one. Do so as
> `dead_code` since that is narrower.
>
> An `allow` would also be possible, but Danilo wants to catch new users
> in the future [1].
>
> Link: https://lore.kernel.org/rust-for-linux/aBE8qQrpXOfru_K3@pollux/ [1]
> Fixes: ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Great, I updated this message and somehow broke the title completely
-- please assume it was:

    rust: device: conditionally expect `dead_code` for
`Device<DeviceContext>::parent()`

And, again, please feel free to just `fixup` this patch if preferred.

Cheers,
Miguel

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

* Re: [PATCH v2] rust: device: allow `Device<DeviceContext>::parent()`
  2025-04-29 21:06 [PATCH v2] rust: device: allow `Device<DeviceContext>::parent()` Miguel Ojeda
  2025-04-29 21:20 ` Miguel Ojeda
@ 2025-04-29 21:52 ` Danilo Krummrich
  1 sibling, 0 replies; 3+ messages in thread
From: Danilo Krummrich @ 2025-04-29 21:52 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, rust-for-linux, linux-kernel, patches

On Tue, Apr 29, 2025 at 11:06:29PM +0200, Miguel Ojeda wrote:
> When `CONFIG_AUXILIARY_BUS` is disabled, `parent()` is still dead code:
> 
>     error: method `parent` is never used
>       --> rust/kernel/device.rs:71:19
>        |
>     64 | impl<Ctx: DeviceContext> Device<Ctx> {
>        | ------------------------------------ method in this implementation
>     ...
>     71 |     pub(crate) fn parent(&self) -> Option<&Self> {
>        |                   ^^^^^^
>        |
>        = note: `-D dead-code` implied by `-D warnings`
>        = help: to override `-D warnings` add `#[allow(dead_code)]`
> 
> Thus reintroduce the `expect`, but now as a conditional one. Do so as
> `dead_code` since that is narrower.
> 
> An `allow` would also be possible, but Danilo wants to catch new users
> in the future [1].
> 
> Link: https://lore.kernel.org/rust-for-linux/aBE8qQrpXOfru_K3@pollux/ [1]
> Fixes: ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Applied to nova-next, thanks!

[ Adjust commit subject to "rust: device: conditionally expect
  `dead_code` for `parent()`". - Danilo ]

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

end of thread, other threads:[~2025-04-29 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 21:06 [PATCH v2] rust: device: allow `Device<DeviceContext>::parent()` Miguel Ojeda
2025-04-29 21:20 ` Miguel Ojeda
2025-04-29 21:52 ` Danilo Krummrich

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).