device property: Get rid of __PROPERTY_ENTRY_ARRAY_EL*SIZE*()
Subsystems (3)
Andy Shevchenko
reviewerPATCH 1/2 device property: Get rid of __PROPERTY_ENTRY_ARRAY_EL*SIZE*()
First of all, _ELEMENT_SIZE() repeats existing sizeof_field() macro. Second, usage of _ARRAY_ELSIZE_LEN() adds unnecessary indirection to the data layout. It's more understandable when the data structure is placed explicitly. That said, get rid of those macros by replacing them with the existing helper and explicit data structure layout.
--- include/linux/property.h | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
include/linux/property.h +14 -20
@@ -12,6 +12,7 @@#include <linux/bits.h> #include <linux/fwnode.h> +#include <linux/stddef.h> #include <linux/types.h> struct device ;
@@ -310,24 +311,14 @@ struct property_entry {* crafted to avoid gcc-4.4.4's problems with initialization of anon unions * and structs. */ - -#define __PROPERTY_ENTRY_ELEMENT_SIZE (_elem_) \ - sizeof(((struct property_entry *)NULL)->value._elem_[0]) - -#define __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN (_name_, _elsize_, _Type_, \ - _val_, _len_) \ -(struct property_entry) { \ - .name = _name_, \ - .length = (_len_) * (_elsize_), \ - .type = DEV_PROP_##_Type_, \ - { .pointer = _val_ }, \ +#define __PROPERTY_ENTRY_ARRAY_LEN (_name_, _elem_, _Type_, _val_, _len_) \ +(struct property_entry) { \ + .name = _name_, \ + .length = (_len_) * sizeof_field(struct property_entry, value._elem_[0]), \ + .type = DEV_PROP_##_Type_, \ + { .pointer = _val_ }, \ } -#define __PROPERTY_ENTRY_ARRAY_LEN (_name_, _elem_, _Type_, _val_, _len_)\ - __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \ - __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ - _Type_, _val_, _len_) -#define PROPERTY_ENTRY_U8_ARRAY_LEN (_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_)#define PROPERTY_ENTRY_U16_ARRAY_LEN (_name_, _val_, _len_) \
@@ -339,9 +330,12 @@ struct property_entry {#define PROPERTY_ENTRY_STRING_ARRAY_LEN (_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_)#define PROPERTY_ENTRY_REF_ARRAY_LEN (_name_, _val_, _len_) \ - __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \ - sizeof(struct software_node_ref_args), \ - REF, _val_, _len_) +(struct property_entry) { \ + .name = _name_, \ + .length = (_len_) * sizeof(struct software_node_ref_args), \ + .type = DEV_PROP_##_Type_, \ + .pointer = _val_, \ +}#define PROPERTY_ENTRY_U8_ARRAY (_name_, _val_) \ PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
@@ -359,7 +353,7 @@ struct property_entry {#define __PROPERTY_ENTRY_ELEMENT (_name_, _elem_, _Type_, _val_) \ (struct property_entry) { \ .name = _name_, \ - .length = __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \ + .length = sizeof_field(struct property_entry, value._elem_[0]), \ .is_inline = true, \ .type = DEV_PROP_##_Type_, \ { .value = { ._elem_[0] = _val_ } }, \
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerPATCH 2/2 device property: Move PROPERTY_ENTRY_BOOL() a bit down
Let's order ARRAY and non-ARRAY macros in the same way. The PROPERTY_ENTRY_BOOL() is special, move it a bit down in the code so it won't break ordering of the rest.
--- include/linux/property.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
include/linux/property.h +7 -6
@@ -329,6 +329,7 @@ struct property_entry { __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_)#define PROPERTY_ENTRY_STRING_ARRAY_LEN (_name_, _val_, _len_) \ __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_) +#define PROPERTY_ENTRY_REF_ARRAY_LEN (_name_, _val_, _len_) \ (struct property_entry) { \ .name = _name_, \
@@ -370,12 +371,6 @@ struct property_entry {#define PROPERTY_ENTRY_STRING (_name_, _val_) \ __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_) -#define PROPERTY_ENTRY_BOOL (_name_) \ -(struct property_entry) { \ - .name = _name_, \ - .is_inline = true, \ -} -#define PROPERTY_ENTRY_REF (_name_, _ref_, ...) \ (struct property_entry) { \ .name = _name_, \
@@ -384,6 +379,12 @@ struct property_entry { { .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), }, \ } +#define PROPERTY_ENTRY_BOOL (_name_) \ +(struct property_entry) { \ + .name = _name_, \ + .is_inline = true, \ +} +struct property_entry *property_entries_dup (const struct property_entry *properties);void property_entries_free (const struct property_entry *properties);
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerQuoted 5 lines · Andy Shevchenko
First of all,
_ELEMENT_SIZE()repeats existingsizeof_field()macro. Second, usage of_ARRAY_ELSIZE_LEN()adds unnecessary indirection to the data layout. It's more understandable when the data structure is placed explicitly. That said, get rid of those macros by replacing them with the existing helper and explicit data structure layout.
...
include/linux/property.h struct property_entry {
Quoted 6 lines
include/linux/property.h +5
-0+(struct property_entry ) { \ + .name = _name_, \ + .length = (_len_) *sizeof (struct software_node_ref_args ), \ + .type = DEV_PROP_##_Type_, \ + .pointer = _val_, \
While waiting for the comments, I have noticed missed {} here. I haven't checked if gcc 5.1 still requires that, but in any case that should be matter of a separate patch (to drop {} for anonymous union members initialization).
That said, v2 will occur if no serious objection is provided.
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko