Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table()
@ 2026-07-02 12:30 Alice Ryhl
  2026-07-02 12:35 ` sashiko-bot
  2026-07-02 13:48 ` Gary Guo
  0 siblings, 2 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-07-02 12:30 UTC (permalink / raw)
  To: Danilo Krummrich, Greg Kroah-Hartman, Rafael J. Wysocki
  Cc: Dave Ertman, Ira Weiny, Leon Romanovsky, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Igor Korotin, Bjorn Helgaas,
	Krzysztof Wilczyński, Sumit Semwal, Christian König,
	driver-core, rust-for-linux, linux-kernel, linux-pci, linux-media,
	dri-devel, linaro-mm-sig, Alice Ryhl

The current name of `as_ptr` is very generic, and if you attempt to
invoke `foo.as_ptr()` on a type for which this method is missing, then
an error along these lines will be printed:

	error[E0599]: no method named `as_ptr` found for reference `&DmaBuf` in the current scope
	   --> linux/rust/kernel/dma_buf/buf.rs:54:38
	    |
	 54 |         ptr::eq(self.as_ptr(), other.as_ptr())
	    |                                      ^^^^^^ method not found in `&DmaBuf`
	    |
	    = help: items from traits can only be used if the trait is implemented and in scope
	note: `device_id::IdTable` defines an item `as_ptr`, perhaps you need to implement it
	   --> linux/rust/kernel/device_id.rs:165:1
	    |
	165 | pub trait IdTable<T: RawDeviceId, U> {
	    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Suggesting the IdTable trait when an as_ptr() method is missing is not
useful. Renaming it to `as_raw_id_table` makes the method name unique to
this trait and avoids these bad suggestions.

Assisted-by: Antigravity:Gemini
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
 rust/kernel/auxiliary.rs | 2 +-
 rust/kernel/device_id.rs | 4 ++--
 rust/kernel/driver.rs    | 8 +++++---
 rust/kernel/i2c.rs       | 8 ++++----
 rust/kernel/pci.rs       | 2 +-
 rust/kernel/platform.rs  | 4 ++--
 rust/kernel/usb.rs       | 2 +-
 7 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
index c42928d5a239..fd6940577e0d 100644
--- a/rust/kernel/auxiliary.rs
+++ b/rust/kernel/auxiliary.rs
@@ -64,7 +64,7 @@ unsafe fn register(
             (*adrv.get()).name = name.as_char_ptr();
             (*adrv.get()).probe = Some(Self::probe_callback);
             (*adrv.get()).remove = Some(Self::remove_callback);
-            (*adrv.get()).id_table = T::ID_TABLE.as_ptr();
+            (*adrv.get()).id_table = T::ID_TABLE.as_raw_id_table();
         }
 
         // SAFETY: `adrv` is guaranteed to be a valid `DriverType`.
diff --git a/rust/kernel/device_id.rs b/rust/kernel/device_id.rs
index 8e9721446014..821da02540b1 100644
--- a/rust/kernel/device_id.rs
+++ b/rust/kernel/device_id.rs
@@ -164,7 +164,7 @@ impl<T: RawDeviceId + RawDeviceIdIndex, U, const N: usize> IdArray<T, U, N> {
 /// `IdArray` doesn't matter.
 pub trait IdTable<T: RawDeviceId, U> {
     /// Obtain the pointer to the ID table.
-    fn as_ptr(&self) -> *const T::RawType;
+    fn as_raw_id_table(&self) -> *const T::RawType;
 
     /// Obtain the pointer to the bus specific device ID from an index.
     fn id(&self, index: usize) -> &T::RawType;
@@ -174,7 +174,7 @@ pub trait IdTable<T: RawDeviceId, U> {
 }
 
 impl<T: RawDeviceId, U, const N: usize> IdTable<T, U> for IdArray<T, U, N> {
-    fn as_ptr(&self) -> *const T::RawType {
+    fn as_raw_id_table(&self) -> *const T::RawType {
         // This cannot be `self.ids.as_ptr()`, as the return pointer must have correct provenance
         // to access the sentinel.
         core::ptr::from_ref(self).cast()
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index bf5ba0d27553..69068adcbdae 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -341,7 +341,8 @@ fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
             // SAFETY:
             // - `table` has static lifetime, hence it's valid for read,
             // - `dev` is guaranteed to be valid while it's alive, and so is `dev.as_raw()`.
-            let raw_id = unsafe { bindings::acpi_match_device(table.as_ptr(), dev.as_raw()) };
+            let raw_id =
+                unsafe { bindings::acpi_match_device(table.as_raw_id_table(), dev.as_raw()) };
 
             if raw_id.is_null() {
                 None
@@ -374,7 +375,8 @@ fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
             // SAFETY:
             // - `table` has static lifetime, hence it's valid for read,
             // - `dev` is guaranteed to be valid while it's alive, and so is `dev.as_raw()`.
-            let raw_id = unsafe { bindings::of_match_device(table.as_ptr(), dev.as_raw()) };
+            let raw_id =
+                unsafe { bindings::of_match_device(table.as_raw_id_table(), dev.as_raw()) };
 
             if !raw_id.is_null() {
                 // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `struct of_device_id`
@@ -404,7 +406,7 @@ fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
             // - `adev` is a valid pointer to `acpi_device` or is null. It is guaranteed to be
             //   valid as long as `dev` is alive.
             // - `table` has static lifetime, hence it's valid for read.
-            if unsafe { acpi_of_match_device(adev, table.as_ptr(), &raw mut raw_id) } {
+            if unsafe { acpi_of_match_device(adev, table.as_raw_id_table(), &raw mut raw_id) } {
                 // SAFETY:
                 // - the function returns true, therefore `raw_id` has been set to a pointer to a
                 //   valid `of_device_id`.
diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
index 624b971ca8b0..920794d4089d 100644
--- a/rust/kernel/i2c.rs
+++ b/rust/kernel/i2c.rs
@@ -116,17 +116,17 @@ unsafe fn register(
         );
 
         let i2c_table = match T::I2C_ID_TABLE {
-            Some(table) => table.as_ptr(),
+            Some(table) => table.as_raw_id_table(),
             None => core::ptr::null(),
         };
 
         let of_table = match T::OF_ID_TABLE {
-            Some(table) => table.as_ptr(),
+            Some(table) => table.as_raw_id_table(),
             None => core::ptr::null(),
         };
 
         let acpi_table = match T::ACPI_ID_TABLE {
-            Some(table) => table.as_ptr(),
+            Some(table) => table.as_raw_id_table(),
             None => core::ptr::null(),
         };
 
@@ -208,7 +208,7 @@ fn i2c_id_info(dev: &I2cClient) -> Option<&'static <Self as driver::Adapter>::Id
         // SAFETY:
         // - `table` has static lifetime, hence it's valid for reads
         // - `dev` is guaranteed to be valid while it's alive, and so is `dev.as_raw()`.
-        let raw_id = unsafe { bindings::i2c_match_id(table.as_ptr(), dev.as_raw()) };
+        let raw_id = unsafe { bindings::i2c_match_id(table.as_raw_id_table(), dev.as_raw()) };
 
         if raw_id.is_null() {
             return None;
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 5071cae6543f..311b4716800b 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -81,7 +81,7 @@ unsafe fn register(
             (*pdrv.get()).name = name.as_char_ptr();
             (*pdrv.get()).probe = Some(Self::probe_callback);
             (*pdrv.get()).remove = Some(Self::remove_callback);
-            (*pdrv.get()).id_table = T::ID_TABLE.as_ptr();
+            (*pdrv.get()).id_table = T::ID_TABLE.as_raw_id_table();
         }
 
         // SAFETY: `pdrv` is guaranteed to be a valid `DriverType`.
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 9b362e0495d3..f6a48f7750da 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -63,12 +63,12 @@ unsafe fn register(
         module: &'static ThisModule,
     ) -> Result {
         let of_table = match T::OF_ID_TABLE {
-            Some(table) => table.as_ptr(),
+            Some(table) => table.as_raw_id_table(),
             None => core::ptr::null(),
         };
 
         let acpi_table = match T::ACPI_ID_TABLE {
-            Some(table) => table.as_ptr(),
+            Some(table) => table.as_raw_id_table(),
             None => core::ptr::null(),
         };
 
diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs
index 7aff0c82d0af..14e0602c3f03 100644
--- a/rust/kernel/usb.rs
+++ b/rust/kernel/usb.rs
@@ -58,7 +58,7 @@ unsafe fn register(
             (*udrv.get()).name = name.as_char_ptr();
             (*udrv.get()).probe = Some(Self::probe_callback);
             (*udrv.get()).disconnect = Some(Self::disconnect_callback);
-            (*udrv.get()).id_table = T::ID_TABLE.as_ptr();
+            (*udrv.get()).id_table = T::ID_TABLE.as_raw_id_table();
         }
 
         // SAFETY: `udrv` is guaranteed to be a valid `DriverType`.

---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260702-idtable-rename-asptr-3ea4d9e38287

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


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

* Re: [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table()
  2026-07-02 12:30 [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table() Alice Ryhl
@ 2026-07-02 12:35 ` sashiko-bot
  2026-07-02 13:48 ` Gary Guo
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-07-02 12:35 UTC (permalink / raw)
  To: Alice Ryhl; +Cc: ojeda, linux-pci, dri-devel

> The current name of `as_ptr` is very generic, and if you attempt to
> invoke `foo.as_ptr()` on a type for which this method is missing, then
> an error along these lines will be printed:
> 
> 	error[E0599]: no method named `as_ptr` found for reference `&DmaBuf` in the current scope
> 	   --> linux/rust/kernel/dma_buf/buf.rs:54:38
> 	    |
> 	 54 |         ptr::eq(self.as_ptr(), other.as_ptr())
> 	    |                                      ^^^^^^ method not found in `&DmaBuf`
> 	    |
> 	    = help: items from traits can only be used if the trait is implemented and in scope
> 	note: `device_id::IdTable` defines an item `as_ptr`, perhaps you need to implement it
> 	   --> linux/rust/kernel/device_id.rs:165:1
> 	    |
> 	165 | pub trait IdTable<T: RawDeviceId, U> {
> 	    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Suggesting the IdTable trait when an as_ptr() method is missing is not
> useful. Renaming it to `as_raw_id_table` makes the method name unique to
> this trait and avoids these bad suggestions.
> 
> Assisted-by: Antigravity:Gemini
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702-idtable-rename-asptr-v1-1-e0927273c71a@google.com?part=1


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

* Re: [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table()
  2026-07-02 12:30 [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table() Alice Ryhl
  2026-07-02 12:35 ` sashiko-bot
@ 2026-07-02 13:48 ` Gary Guo
  2026-07-02 13:59   ` Alice Ryhl
  1 sibling, 1 reply; 4+ messages in thread
From: Gary Guo @ 2026-07-02 13:48 UTC (permalink / raw)
  To: Alice Ryhl, Danilo Krummrich, Greg Kroah-Hartman,
	Rafael J. Wysocki
  Cc: Dave Ertman, Ira Weiny, Leon Romanovsky, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Igor Korotin, Bjorn Helgaas,
	Krzysztof Wilczyński, Sumit Semwal, Christian König,
	driver-core, rust-for-linux, linux-kernel, linux-pci, linux-media,
	dri-devel, linaro-mm-sig

On Thu Jul 2, 2026 at 1:30 PM BST, Alice Ryhl wrote:
> The current name of `as_ptr` is very generic, and if you attempt to
> invoke `foo.as_ptr()` on a type for which this method is missing, then
> an error along these lines will be printed:
>
> 	error[E0599]: no method named `as_ptr` found for reference `&DmaBuf` in the current scope
> 	   --> linux/rust/kernel/dma_buf/buf.rs:54:38
> 	    |
> 	 54 |         ptr::eq(self.as_ptr(), other.as_ptr())
> 	    |                                      ^^^^^^ method not found in `&DmaBuf`
> 	    |
> 	    = help: items from traits can only be used if the trait is implemented and in scope
> 	note: `device_id::IdTable` defines an item `as_ptr`, perhaps you need to implement it
> 	   --> linux/rust/kernel/device_id.rs:165:1
> 	    |
> 	165 | pub trait IdTable<T: RawDeviceId, U> {
> 	    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Suggesting the IdTable trait when an as_ptr() method is missing is not
> useful. Renaming it to `as_raw_id_table` makes the method name unique to
> this trait and avoids these bad suggestions.

I think the name is fine. Functions of this sort is named `as_ptr()` and I don't
see why it should differ just because it's on traits.

I'd rather say this is a Rust deficiency. Perhaps there needs to be a
improvement of `#[diagnostic::do_not_recommend]` so it can be sticked to methods
or traits as well.

Best,
Gary

>
> Assisted-by: Antigravity:Gemini
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>  rust/kernel/auxiliary.rs | 2 +-
>  rust/kernel/device_id.rs | 4 ++--
>  rust/kernel/driver.rs    | 8 +++++---
>  rust/kernel/i2c.rs       | 8 ++++----
>  rust/kernel/pci.rs       | 2 +-
>  rust/kernel/platform.rs  | 4 ++--
>  rust/kernel/usb.rs       | 2 +-
>  7 files changed, 16 insertions(+), 14 deletions(-)

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

* Re: [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table()
  2026-07-02 13:48 ` Gary Guo
@ 2026-07-02 13:59   ` Alice Ryhl
  0 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2026-07-02 13:59 UTC (permalink / raw)
  To: Gary Guo
  Cc: Danilo Krummrich, Greg Kroah-Hartman, Rafael J. Wysocki,
	Dave Ertman, Ira Weiny, Leon Romanovsky, Miguel Ojeda, Boqun Feng,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Trevor Gross, Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Igor Korotin, Bjorn Helgaas,
	Krzysztof Wilczyński, Sumit Semwal, Christian König,
	driver-core, rust-for-linux, linux-kernel, linux-pci, linux-media,
	dri-devel, linaro-mm-sig

On Thu, Jul 2, 2026 at 3:48 PM Gary Guo <gary@garyguo.net> wrote:
>
> On Thu Jul 2, 2026 at 1:30 PM BST, Alice Ryhl wrote:
> > The current name of `as_ptr` is very generic, and if you attempt to
> > invoke `foo.as_ptr()` on a type for which this method is missing, then
> > an error along these lines will be printed:
> >
> >       error[E0599]: no method named `as_ptr` found for reference `&DmaBuf` in the current scope
> >          --> linux/rust/kernel/dma_buf/buf.rs:54:38
> >           |
> >        54 |         ptr::eq(self.as_ptr(), other.as_ptr())
> >           |                                      ^^^^^^ method not found in `&DmaBuf`
> >           |
> >           = help: items from traits can only be used if the trait is implemented and in scope
> >       note: `device_id::IdTable` defines an item `as_ptr`, perhaps you need to implement it
> >          --> linux/rust/kernel/device_id.rs:165:1
> >           |
> >       165 | pub trait IdTable<T: RawDeviceId, U> {
> >           | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > Suggesting the IdTable trait when an as_ptr() method is missing is not
> > useful. Renaming it to `as_raw_id_table` makes the method name unique to
> > this trait and avoids these bad suggestions.
>
> I think the name is fine. Functions of this sort is named `as_ptr()` and I don't
> see why it should differ just because it's on traits.
>
> I'd rather say this is a Rust deficiency. Perhaps there needs to be a
> improvement of `#[diagnostic::do_not_recommend]` so it can be sticked to methods
> or traits as well.

I had a similar thought:
https://internals.rust-lang.org/t/do-not-recommend-for-traits-themselves/24431

Alice

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

end of thread, other threads:[~2026-07-02 14:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-02 12:30 [PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table() Alice Ryhl
2026-07-02 12:35 ` sashiko-bot
2026-07-02 13:48 ` Gary Guo
2026-07-02 13:59   ` Alice Ryhl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox