Re: [PATCH v2 1/5] rust: Move property_present to separate file

Danilo Krummrich
2025-04-14T16:00:32Z

On Mon, Apr 14, 2025 at 05:26:26PM +0200, Remo Senekowitsch wrote:
> Not all property-related APIs can be exposed directly on a device.
> For example, iterating over child nodes of a device will yield
> fwnode_handle. Thus, in order to access properties on these child nodes,
> duplicate the APIs on a fwnode as they are in C.

What do you mean with "duplicate the APIs"?

Also, this patch does three separate things.

(1) move property_present() to separate file
(2) implement FwNode abstraction
(3) implement Device::fwnode()

I'd rather keep property_present() in device.rs and also move fwnode() into
device.rs, even though in C it's in property.c. impl Device blocks should be in
device.rs.

Hence, please split this in two patches, one for (2) and one for (3).

> +++ b/rust/kernel/property.rs
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Unified device property interface.
> +//!
> +//! C header: [`include/linux/property.h`](srctree/include/linux/property.h)
> +
> +use core::ptr;
> +
> +use crate::{bindings, device::Device, str::CStr, types::Opaque};
> +
> +impl Device {
> + /// Obtain the fwnode corresponding to the device.
> + fn fwnode(&self) -> &FwNode {
> + // SAFETY: `self` is valid.
> + let fwnode_handle = unsafe { bindings::__dev_fwnode(self.as_raw()) };
> + if fwnode_handle.is_null() {
> + panic!("fwnode_handle cannot be null");

Please don't use panic!() unless you hit an error condition that is impossible
to handle.

If __dev_fwnode() can ever return NULL, make this function return
Option<&FwNode> instead.