[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DFUBAXCDIF1H.2R3004ZHIZPOE@garyguo.net>
Date: Wed, 21 Jan 2026 13:46:53 +0000
From: "Gary Guo" <gary@...yguo.net>
To: "Danilo Krummrich" <dakr@...nel.org>, "Gary Guo" <gary@...nel.org>
Cc: "Gary Guo" <gary@...yguo.net>, "Greg Kroah-Hartman"
<gregkh@...uxfoundation.org>, "Rafael J. Wysocki" <rafael@...nel.org>,
"Miguel Ojeda" <ojeda@...nel.org>, "Boqun Feng" <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Alice
Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>, "Bjorn
Helgaas" <bhelgaas@...gle.com>, Krzysztof Wilczyński
<kwilczynski@...nel.org>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-pci@...r.kernel.org>
Subject: Re: [PATCH 1/4] rust: device: support `dev_printk` on all devices
On Tue Jan 20, 2026 at 6:56 PM GMT, Danilo Krummrich wrote:
> On Tue Jan 20, 2026 at 7:11 PM CET, Gary Guo wrote:
>> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
>> index c7b5db9dcca1..94e0548e7687 100644
>> --- a/rust/kernel/device.rs
>> +++ b/rust/kernel/device.rs
>> @@ -601,6 +601,13 @@ impl DeviceContext for Core {}
>> impl DeviceContext for CoreInternal {}
>> impl DeviceContext for Normal {}
>>
>> +impl<Ctx: DeviceContext> AsRef<Device<Ctx>> for Device<Ctx> {
>> + #[inline]
>> + fn as_ref(&self) -> &Device<Ctx> {
>> + self
>> + }
>> +}
>> +
>> /// Convert device references to bus device references.
>> ///
>> /// Bus devices can implement this trait to allow abstractions to provide the bus device in
>> @@ -720,7 +727,7 @@ macro_rules! impl_device_context_into_aref {
>> macro_rules! dev_printk {
>> ($method:ident, $dev:expr, $($f:tt)*) => {
>> {
>> - ($dev).$method($crate::prelude::fmt!($($f)*));
>> + $crate::device::Device::$method($dev.as_ref(), $crate::prelude::fmt!($($f)*))
>
> At a first glance I wasn't sure if we really want to rely on AsRef when hide it
> in the macro. But on the other hand, if someone would implement AsRef on a class
> or bus device to return some other (unrelated) &Device it would be wrong
> anyways. So I think using AsRef is fine.
>
> I think a lot of people will be very happy about this patch. :)
^ this is basically me getting annoyed by everything being `pdev.as_ref()` when
reviewing code and want to fix the pain :)
>
> I will pick up patches 1 and 2 this cycle, patch 3 and 4 can go through the
> corresponding subsystem tree next cycle.
>
>> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
>> index bea76ca9c3da..3946ca919332 100644
>> --- a/rust/kernel/pci.rs
>> +++ b/rust/kernel/pci.rs
>> @@ -351,7 +351,7 @@ impl Device {
>> /// // Get an instance of `Vendor`.
>> /// let vendor = pdev.vendor_id();
>> /// dev_info!(
>> - /// pdev.as_ref(),
>> + /// pdev,
>> /// "Device: Vendor={}, Device=0x{:x}\n",
>> /// vendor,
>> /// pdev.device_id()
>> diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs
>> index c09125946d9e..e2d9e8804347 100644
>> --- a/rust/kernel/pci/id.rs
>> +++ b/rust/kernel/pci/id.rs
>> @@ -22,7 +22,7 @@
>> /// fn probe_device(pdev: &pci::Device<Core>) -> Result {
>> /// let pci_class = pdev.pci_class();
>> /// dev_info!(
>> -/// pdev.as_ref(),
>> +/// pdev,
>> /// "Detected PCI class: {}\n",
>> /// pci_class
>> /// );
>
> Can you please send a separate patch for those?
I converted them as they're the users that benefit from this behaviour in the
kernel crate (i.e. "convert the users"). Do you want them separate so you can
take it via a different tree?
Best,
Gary
Powered by blists - more mailing lists