Re: [PATCH Resend V2] dt: add helper function to read u8 & u16 variables & arrays
From: Viresh Kumar <hidden>
Date: 2012-11-06 14:39:04
On 6 November 2012 19:48, Rob Herring [off-list ref] wrote:
quoted
diff --git a/drivers/of/base.c b/drivers/of/base.c
quoted
+#define of_property_read_array(_np, _pname, _out, _sz)\quoted
+ struct property *_prop = of_find_property(_np, _pname, NULL); \ + const __be32 *_val; \ + \ + if (!_prop) \ + return -EINVAL; \ + if (!_prop->value) \ + return -ENODATA; \ + if ((_sz * sizeof(*_out)) > _prop->length) \ + return -EOVERFLOW; \ + \ + _val = _prop->value; \ + while (_sz--) \ + *_out++ = (typeof(*_out))be32_to_cpup(_val++); \This will not work. You are incrementing _out by 1, 2, or 4 bytes, but _val is always incremented by 4 bytes. According to the dtc commit adding this feature, the values are packed: With this patch the following property assignment: property = /bits/ 16 <0x1234 0x5678 0x0 0xffff>; is equivalent to: property = <0x12345678 0x0000ffff>;
Something which i haven't expected :( I will fix and test it well for all types before sending it now.
quoted
+/** + * of_property_read_u8_array - Find and read an array of u8 from aproperty.quoted
+ * + * @np: device node from which the property value is to beread.quoted
+ * @propname: name of the property to be searched. + * @out_value: pointer to return value, modified only if returnvalue is 0.quoted
+ *Missing sz
Yes for both misses.