Re: [PATCH] rust: kernel: device: Add of_platform_populate/depopulate

Danilo Krummrich
2025-04-28T18:39:34Z

On Mon, Apr 28, 2025 at 07:52:29PM +0530, Ayush Singh wrote:
> Open Questions
> ***************
>
> 1. Function names
>
> The rust implementations are based on devm_* versions of these
> functions, i.e of_platform_depopulate() is called when the device is
> unbound. Since in case of Rust, these are methods on the Device struct,
> I am not sure if the `devm_` prefix is required.

Please add the 'devm' prefix.

> 2. Maybe should be functions instead of methods?

Making those methods is the correct thing.

> + /// Populate platform_devices from device tree data
> + pub fn of_platform_populate(&self) -> crate::error::Result<()> {
> + crate::error::to_result(unsafe { bindings::devm_of_platform_populate(self.as_raw()) })

As Greg mentioned, please add the missing safety comments. Additionally, I
suggest to import to_result().

Please also make sure to go through [1].

> + }
> +
> + /// Remove devices populated from device tree
> + pub fn of_platform_depopulate(&self) {
> + unsafe { bindings::devm_of_platform_depopulate(self.as_raw()) }
> + }
> }

Please move both of those methods into

impl Device<Bound> {

which ensures that those methods can only be called for a bound device, which is
required by devres.

The impl block does not exist for Device yet, so you have to create it with your
patch.

- Danilo

[1] https://rust-for-linux.com/contributing#submit-checklist-addendum