Re: [PATCH v2 5/5] samples: rust: platform: Add property read examples

Dirk Behme
2025-04-24T05:48:01Z

On 23/04/2025 14:39, Dirk Behme wrote:
> Hi Remo,
>
> On 14/04/2025 17:26, Remo Senekowitsch wrote:
>> Add some example usage of the device property read methods for
>> DT/ACPI/swnode properties.
>>
>> Co-developed-by: Rob Herring (Arm) <robh@kernel.org>
>> Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
>> Signed-off-by: Remo Senekowitsch <remo@buenzli.dev>
>> ---
>> drivers/of/unittest-data/tests-platform.dtsi | 3 +
>> samples/rust/rust_driver_platform.rs | 69 +++++++++++++++++++-
>> 2 files changed, 69 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/of/unittest-data/tests-platform.dtsi b/drivers/of/unittest-data/tests-platform.dtsi
>> index 4171f43cf..50a51f38a 100644
>> --- a/drivers/of/unittest-data/tests-platform.dtsi
>> +++ b/drivers/of/unittest-data/tests-platform.dtsi
>> @@ -37,6 +37,9 @@ dev@100 {
>> test-device@2 {
>> compatible = "test,rust-device";
>> reg = <0x2>;
>> +
>> + test,u32-prop = <0xdeadbeef>;
>> + test,i16-array = /bits/ 16 <1 2 (-3) (-4)>;
>
>
> Is "test,u32-required-prop" missing here? See below ...

Ah, no, sorry, "test,u32-required-prop" isn't there intentionally to
demonstrate the error handling on missing required properties. In this
case I would propose to just remove the '?' to make the sample code not
exit on this intended error:

diff --git a/samples/rust/rust_driver_platform.rs
b/samples/rust/rust_driver_platform.rs
index 01902956e1ca7..b6cbd721a8882 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -75,7 +75,7 @@ fn properties_parse(dev: &kernel::device::Device) ->
Result<()> {
// Missing property without a default will print an error
let _ = dev
.property_read::<u32>(c_str!("test,u32-required-prop"))
- .required()?;
+ .required();

let prop: u32 =
dev.property_read(c_str!("test,u32-prop")).required()?;
dev_info!(dev, "'test,u32-prop' is {:#x}\n", prop);

Best regards

Dirk