[PATCH] rust: device_id: rename IdTable::as_ptr to as_raw_id_table()
From: Alice Ryhl
Date: Thu Jul 02 2026 - 08:44:16 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxxx>