mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Dirk Behme" <dirk.behme@de.bosch.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Dave Ertman" <david.m.ertman@intel.com>,
	"Ira Weiny" <ira.weiny@intel.com>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Igor Korotin" <igor.korotin.linux@gmail.com>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-pci@vger.kernel.org>
Subject: Re: [PATCH 2/4] rust: samples: remove redundant `.as_ref()` for `dev_*` print
Date: Fri, 23 Jan 2026 17:44:22 +0000	[thread overview]
Message-ID: <DFW5LUIQVZK0.2W01YO54KTKR7@garyguo.net> (raw)
In-Reply-To: <82535e68-dde7-46b9-836f-cc6f2f8e7a78@de.bosch.com>

On Wed Jan 21, 2026 at 6:52 AM GMT, Dirk Behme wrote:
> Hi Gary
>
> On 20/01/2026 19:11, Gary Guo wrote:
>> From: Gary Guo <gary@garyguo.net>
>> 
>> This is now handled by the macro itself.
>> 
>> Signed-off-by: Gary Guo <gary@garyguo.net>
>> ---
>>   samples/rust/rust_dma.rs              |  2 +-
>>   samples/rust/rust_driver_auxiliary.rs |  2 +-
>>   samples/rust/rust_driver_faux.rs      |  2 +-
>>   samples/rust/rust_driver_i2c.rs       |  4 ++--
>>   samples/rust/rust_driver_pci.rs       |  6 +++---
>>   samples/rust/rust_driver_platform.rs  |  2 +-
>>   samples/rust/rust_i2c_client.rs       | 10 ++--------
>>   7 files changed, 11 insertions(+), 17 deletions(-)
>> 
>> diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
>> index f53bce2a73e3..a9ac7937ebaf 100644
>> --- a/samples/rust/rust_dma.rs
>> +++ b/samples/rust/rust_dma.rs
>> @@ -57,7 +57,7 @@ impl pci::Driver for DmaSampleDriver {
>>   
>>       fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
>>           pin_init::pin_init_scope(move || {
>> -            dev_info!(pdev.as_ref(), "Probe DMA test driver.\n");
>> +            dev_info!(pdev, "Probe DMA test driver.\n");
>>   
>>               let mask = DmaMask::new::<64>();
>>   
>> diff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs
>> index f148124fe81f..c20961f16835 100644
>> --- a/samples/rust/rust_driver_auxiliary.rs
>> +++ b/samples/rust/rust_driver_auxiliary.rs
>> @@ -39,7 +39,7 @@ impl auxiliary::Driver for AuxiliaryDriver {
>>   
>>       fn probe(adev: &auxiliary::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {
>>           dev_info!(
>> -            adev.as_ref(),
>> +            adev,
>>               "Probing auxiliary driver for auxiliary device with id={}\n",
>>               adev.id()
>>           );
>> diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_faux.rs
>> index 5330b77ea986..99876c8e3743 100644
>> --- a/samples/rust/rust_driver_faux.rs
>> +++ b/samples/rust/rust_driver_faux.rs
>> @@ -26,7 +26,7 @@ fn init(_module: &'static ThisModule) -> Result<Self> {
>>   
>>           let reg = faux::Registration::new(c"rust-faux-sample-device", None)?;
>>   
>> -        dev_info!(reg.as_ref(), "Hello from faux device!\n");
>> +        dev_info!(reg, "Hello from faux device!\n");
>>   
>>           Ok(Self { _reg: reg })
>>       }
>> diff --git a/samples/rust/rust_driver_i2c.rs b/samples/rust/rust_driver_i2c.rs
>> index 6be79f9e9fb5..e71b77196163 100644
>> --- a/samples/rust/rust_driver_i2c.rs
>> +++ b/samples/rust/rust_driver_i2c.rs
>> @@ -56,11 +56,11 @@ fn probe(
>>       }
>>   
>>       fn shutdown(idev: &i2c::I2cClient<Core>, _this: Pin<&Self>) {
>> -        dev_info!(idev.as_ref(), "Shutdown Rust I2C driver sample.\n");
>> +        dev_info!(idev, "Shutdown Rust I2C driver sample.\n");
>>       }
>>   
>>       fn unbind(idev: &i2c::I2cClient<Core>, _this: Pin<&Self>) {
>> -        dev_info!(idev.as_ref(), "Unbind Rust I2C driver sample.\n");
>> +        dev_info!(idev, "Unbind Rust I2C driver sample.\n");
>>       }
>>   }
>>   
>> diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
>> index ef04c6401e6a..d50828b642e5 100644
>> --- a/samples/rust/rust_driver_pci.rs
>> +++ b/samples/rust/rust_driver_pci.rs
>> @@ -75,7 +75,7 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> impl PinInit<Self, Er
>>           pin_init::pin_init_scope(move || {
>>               let vendor = pdev.vendor_id();
>>               dev_dbg!(
>> -                pdev.as_ref(),
>> +                pdev,
>>                   "Probe Rust PCI driver sample (PCI ID: {}, 0x{:x}).\n",
>>                   vendor,
>>                   pdev.device_id()
>> @@ -91,7 +91,7 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> impl PinInit<Self, Er
>>                       let bar = bar.access(pdev.as_ref())?;
>>   
>>                       dev_info!(
>> -                        pdev.as_ref(),
>> +                        pdev,
>>                           "pci-testdev data-match count: {}\n",
>>                           Self::testdev(info, bar)?
>>                       );
>> @@ -112,7 +112,7 @@ fn unbind(pdev: &pci::Device<Core>, this: Pin<&Self>) {
>>   #[pinned_drop]
>>   impl PinnedDrop for SampleDriver {
>>       fn drop(self: Pin<&mut Self>) {
>> -        dev_dbg!(self.pdev.as_ref(), "Remove Rust PCI driver sample.\n");
>> +        dev_dbg!(self.pdev, "Remove Rust PCI driver sample.\n");
>>       }
>>   }
>>   
>> diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
>> index 9537dc38c563..f2229d176fb9 100644
>> --- a/samples/rust/rust_driver_platform.rs
>> +++ b/samples/rust/rust_driver_platform.rs
>> @@ -180,7 +180,7 @@ fn properties_parse(dev: &device::Device) -> Result {
>>   
>>   impl Drop for SampleDriver {
>>       fn drop(&mut self) {
>> -        dev_dbg!(self.pdev.as_ref(), "Remove Rust Platform driver sample.\n");
>> +        dev_dbg!(self.pdev, "Remove Rust Platform driver sample.\n");
>>       }
>>   }
>>   
>> diff --git a/samples/rust/rust_i2c_client.rs b/samples/rust/rust_i2c_client.rs
>> index 8d2c12e535b0..72da5499f150 100644
>> --- a/samples/rust/rust_i2c_client.rs
>> +++ b/samples/rust/rust_i2c_client.rs
>> @@ -113,10 +113,7 @@ fn probe(
>>           pdev: &platform::Device<device::Core>,
>>           _info: Option<&Self::IdInfo>,
>>       ) -> impl PinInit<Self, Error> {
>> -        dev_info!(
>> -            pdev.as_ref(),
>> -            "Probe Rust I2C Client registration sample.\n"
>> -        );
>> +        dev_info!(pdev, "Probe Rust I2C Client registration sample.\n");
>>   
>>           kernel::try_pin_init!( Self {
>>               parent_dev: pdev.into(),
>> @@ -130,10 +127,7 @@ fn probe(
>>       }
>>   
>>       fn unbind(pdev: &platform::Device<device::Core>, _this: Pin<&Self>) {
>> -        dev_info!(
>> -            pdev.as_ref(),
>> -            "Unbind Rust I2C Client registration sample.\n"
>> -        );
>> +        dev_info!(pdev, "Unbind Rust I2C Client registration sample.\n");
>>       }
>>   }
>
>
> At least in samples/rust we have several places where we added helper 
> variables for `dev`. For example in rust_driver_platform.rs [1] we have
>
> let dev = pdev.as_ref();
> dev_dbg!(dev, "Probe Rust Platform driver sample.\n");
>
> Do we want to keep this?
>
> I think there are places where this `dev` helper variable is used for 
> printing, only. And there are places, like in the `probe()` of 
> rust_driver_platform.rs, where the `dev` helper is additionally used 
> elsewhere:
>
> ... Self::properties_parse(dev)?;
>
> Hmm, I'm somehow under the impression what to use when in the end 
> becomes slightly confusing in sum?

Hi Dirk,

If you already need to be obtain `&Device`, then I would say either is fine.
The `AsRef` impl of devices are zero-cost operations anyway.

The motivation behind the patch is that in a lot of cases we only need `&Device`
specifically to print, which is something that I want to avoid.

Best,
Gary


  reply	other threads:[~2026-01-23 17:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 18:11 [PATCH 1/4] rust: device: support `dev_printk` on all devices Gary Guo
2026-01-20 18:11 ` [PATCH 2/4] rust: samples: remove redundant `.as_ref()` for `dev_*` print Gary Guo
2026-01-21  6:52   ` Dirk Behme
2026-01-23 17:44     ` Gary Guo [this message]
2026-01-27 18:51   ` Igor Korotin
2026-01-20 18:11 ` [PATCH 3/4] gpu: nova-core: " Gary Guo
2026-01-20 18:11 ` [PATCH 4/4] gpu: tyr: " Gary Guo
2026-01-21 12:25   ` Daniel Almeida
2026-01-26  9:17   ` Alice Ryhl
2026-01-26 13:43     ` Danilo Krummrich
2026-01-26 15:06       ` Alice Ryhl
2026-01-26 17:02         ` Danilo Krummrich
2026-01-20 18:56 ` [PATCH 1/4] rust: device: support `dev_printk` on all devices Danilo Krummrich
2026-01-21 13:46   ` Gary Guo
2026-01-21 14:25     ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DFW5LUIQVZK0.2W01YO54KTKR7@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=abdiel.janulgue@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=david.m.ertman@intel.com \
    --cc=dirk.behme@de.bosch.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=igor.korotin.linux@gmail.com \
    --cc=ira.weiny@intel.com \
    --cc=kwilczynski@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome