Re: [PATCH v3 4/4] pylibfdt: Allow reading integer values from properties

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi David,

On 4 June 2018 at 17:59, David Gibson <david@xxxxxxxxxxxxxxxxxxxxx> wrote:
> On Thu, May 17, 2018 at 11:09:16PM -0600, Simon Glass wrote:
>> Extend the Properties class with some functions to read a single integer
>> property. Add a new getprop_obj() function to return a Property object
>> instead of the raw data.
>>
>> This suggested approach can be extended to handle other types, as well as
>> arrays.
>>
>> Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx>
>> ---
>>
>> Changes in v3:
>> - Rename the functions with an 'as_' prefix instead of 'to_'
>>
>> Changes in v2: None
>>
>>  pylibfdt/libfdt.i       | 35 +++++++++++++++++++++++++++++++++++
>>  tests/pylibfdt_tests.py | 12 ++++++++++++
>>  tests/run_tests.sh      |  1 +
>>  tests/test_props.dts    | 11 +++++++++++
>>  4 files changed, 59 insertions(+)
>>  create mode 100644 tests/test_props.dts
>>
>> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
>> index 7e915cf..328d440 100644
>> --- a/pylibfdt/libfdt.i
>> +++ b/pylibfdt/libfdt.i
>> @@ -376,6 +376,26 @@ class Fdt:
>>              return pdata
>>          return str(pdata[0])
>>
>> +    def getprop_obj(self, nodeoffset, prop_name, quiet=()):
>> +        """Get a property from a node as a Property object
>
> Now that you've made Property a subclass of bytearray elsewhere, can't
> you unify the getprop() and getprop_obj() interfaces?

I can, but it does introduce a minor issue. As per other functions
named after libfdt getprop() is a stub for fdt_getprop() which
provides access to the error number in event of failure, whereas
getprop_obj() returns None on error.

For now I'll try returning either:

- a Property object (subclass of bytearray), on success
- an integer err number, on error

Of course the function will raise unless the errors are specifically
quietened, so this behaviour may not be common.

But it is a bit weird so let me know if you have a better idea.

It does make the previous patch moot I think, but I'll send it anyway
since if this patch doesn't fit we still want the previous one.

Regards,
Simon
--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux