Skip to contentSkip to conversation

rust: device: allow `Device<DeviceContext>::parent()`

PATCH Applied Miguel Ojeda 3 participants 3 messages Apr 29, 2025

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH v2 1/1 rust: device: allow `Device<DeviceContext>::parent()`

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

Fixes ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")
---
 rust/kernel/device.rs | 1 +
 1 file changed, 1 insertion(+)
rust/kernel/device.rs +1 -0
index 40c1f549b0ba..f08583fa39c9 100644
@@ -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

Signature · 1 line
2.49.0
#1 lore raw
Quoted 18 lines · Miguel Ojeda

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.

Quoted 6 lines

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

Fixes ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")

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

maintainer Applied
#2 lore raw
In reply to Miguel Ojeda
Quoted 17 lines · Miguel Ojeda

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.

Quoted 6 lines

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

Fixes ce735e73dd59 ("rust: auxiliary: add auxiliary device / driver abstractions")

Applied to nova-next, thanks!

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