Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: device: add device name method

Add a name() method to the `Device` type, which returns a CStr that
contains the device name.

Signed-off-by: Timur Tabi <ttabi@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Tested-by: John Hubbard <jhubbard@nvidia.com>
Tested-by: Eliot Courtney <ecourtney@nvidia.com>
Link: https://patch.msgid.link/20260319212658.2541610-2-ttabi@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Timur Tabi and committed by
Danilo Krummrich
d35ae50c 651c27d6

+16
+5
rust/helpers/device.c
··· 25 25 { 26 26 dev_set_drvdata(dev, data); 27 27 } 28 + 29 + __rust_helper const char *rust_helper_dev_name(const struct device *dev) 30 + { 31 + return dev_name(dev); 32 + }
+11
rust/kernel/device.rs
··· 489 489 // defined as a `#[repr(transparent)]` wrapper around `fwnode_handle`. 490 490 Some(unsafe { &*fwnode_handle.cast() }) 491 491 } 492 + 493 + /// Returns the name of the device. 494 + /// 495 + /// This is the kobject name of the device, or its initial name if the kobject is not yet 496 + /// available. 497 + #[inline] 498 + pub fn name(&self) -> &CStr { 499 + // SAFETY: By its type invariant `self.as_raw()` is a valid pointer to a `struct device`. 500 + // The returned string is valid for the lifetime of the device. 501 + unsafe { CStr::from_char_ptr(bindings::dev_name(self.as_raw())) } 502 + } 492 503 } 493 504 494 505 // SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic