software node: implement reference properties
PATCH v2 1/3 software node: implement reference properties
It is possible to store references to software nodes in the same fashion as other static properties, so that users do not need to define separate structures:
static const struct software_node gpio_bank_b_node = {
.name = "B",
};static const struct property_entry simone_key_enter_props[] = {
PROPERTY_ENTRY_U32("linux,code", KEY_ENTER),
PROPERTY_ENTRY_STRING("label", "enter"),
PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW),
{ }
};---
v1->v2:
- reworked code so that even single-entry reference properties are stored as arrays (i.e. the software_node_ref_args instances are not part of property_entry structure) to avoid size increase. From user's POV nothing is changed, one can still use PROPERTY_ENTRY_REF macro to define reference "inline".
- dropped unused DEV_PROP_MAX
drivers/base/swnode.c | 43 ++++++++++++++++++++++++++------ include/linux/property.h | 54 +++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 23 deletions(-)
drivers/base/swnode.c +35 -8
@@ -387,6 +387,9 @@ static int property_entry_copy_data(struct property_entry *dst, new =kstrdup (src->value.str,GFP_KERNEL );if (!new && src->value.str)return -ENOMEM ; + }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ; }else { new = pointer; }
@@ -568,21 +571,45 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, {struct swnode *swnode =to_swnode (fwnode);const struct software_node_reference *ref; +const struct software_node_ref_args *ref_args;const struct property_entry *prop;struct fwnode_handle *refnode;int i; -if (!swnode || !swnode->node->references) +if (!swnode)return -ENOENT ; -for (ref = swnode->node->references; ref->name; ref++) -if (!strcmp (ref->name, propname)) -break ; + prop =property_entry_get (swnode->node->properties, propname); +if (prop) { +if (prop->type !=DEV_PROP_REF ) +return -EINVAL ; -if (!ref->name || index > (ref->nrefs -1 )) -return -ENOENT ; +/* +* We expect all references to be stored as arrays via +* a pointer, even single ones. +*/ +if (!prop->is_array) +return -EINVAL ; + +if (index *sizeof (*ref_args) >= prop->length) +return -ENOENT ; + + ref_args = &prop->pointer.ref[index]; + }else { +if (!swnode->node->references) +return -ENOENT ; + +for (ref = swnode->node->references; ref->name; ref++) +if (!strcmp (ref->name, propname)) +break ; + +if (!ref->name || index > (ref->nrefs -1 )) +return -ENOENT ; + + ref_args = &ref->refs[index]; + } - refnode =software_node_fwnode (ref->refs[index].node); + refnode =software_node_fwnode (ref_args->node);if (!refnode)return -ENOENT ;
@@ -601,7 +628,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs;for (i =0 ; i < nargs; i++) - args->args[i] = ref->refs[index].args[i]; + args->args[i] = ref_args->args[i];return 0 ; }
include/linux/property.h +39 -15
90 lines not on this page · raw message
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 2/3 platform/x86: intel_cht_int33fe: use inline reference properties
Now that static device properties allow defining reference properties together with all other types of properties, instead of managing them separately, let's adjust the driver.
---
v1-v2:
- rebased on top of linux-next-20190904
drivers/platform/x86/intel_cht_int33fe.c | 81 ++++++++++++------------ 1 file changed, 41 insertions(+), 40 deletions(-)
drivers/platform/x86/intel_cht_int33fe.c +41 -40
@@ -46,30 +46,6 @@ struct cht_int33fe_data {struct fwnode_handle *dp; }; -static const struct software_node nodes[]; - -static const struct software_node_ref_args pi3usb30532_ref = { - &nodes[INT33FE_NODE_PI3USB30532 ] -}; - -static const struct software_node_ref_args dp_ref = { - &nodes[INT33FE_NODE_DISPLAYPORT ] -}; - -static struct software_node_ref_args mux_ref; - -static const struct software_node_reference usb_connector_refs[] = { - {"orientation-switch" ,1 , &pi3usb30532_ref}, - {"mode-switch" ,1 , &pi3usb30532_ref}, - {"displayport" ,1 , &dp_ref}, - { } -}; - -static const struct software_node_reference fusb302_refs[] = { - {"usb-role-switch" ,1 , &mux_ref}, - { } -}; -/* * Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates * the max17047 both through the INT33FE ACPI device (it is right there
@@ -105,8 +81,18 @@ static const struct property_entry max17047_props[] = { { } }; +/* +* We are not using inline property here because those are constant, +* and we need to adjust this one at runtime to point to real +* software node. +*/ +static struct software_node_ref_args fusb302_mux_refs[] = { + { .node =NULL }, +}; +static const struct property_entry fusb302_props[] = {PROPERTY_ENTRY_STRING ("linux,extcon-name" ,"cht_wcove_pwrsrc" ), +PROPERTY_ENTRY_REF_ARRAY ("usb-role-switch" , fusb302_mux_refs), { } };
@@ -122,6 +108,8 @@ static const u32 snk_pdo[] = { PDO_VAR(5000, 12000, 3000), }; +static const struct software_node nodes[]; +static const struct property_entry usb_connector_props[] = {PROPERTY_ENTRY_STRING ("data-role" ,"dual" ),PROPERTY_ENTRY_STRING ("power-role" ,"dual" ),
@@ -129,15 +117,21 @@ static const struct property_entry usb_connector_props[] = {PROPERTY_ENTRY_U32_ARRAY ("source-pdos" , src_pdo),PROPERTY_ENTRY_U32_ARRAY ("sink-pdos" , snk_pdo),PROPERTY_ENTRY_U32 ("op-sink-microwatt" ,2500000 ), +PROPERTY_ENTRY_REF ("orientation-switch" , + &nodes[INT33FE_NODE_PI3USB30532 ]), +PROPERTY_ENTRY_REF ("mode-switch" , + &nodes[INT33FE_NODE_PI3USB30532 ]), +PROPERTY_ENTRY_REF ("displayport" , + &nodes[INT33FE_NODE_DISPLAYPORT]), { } };static const struct software_node nodes[] = { - {"fusb302" ,NULL , fusb302_props, fusb302_refs }, + {"fusb302" ,NULL , fusb302_props }, {"max17047" ,NULL , max17047_props }, {"pi3usb30532" }, {"displayport" }, - {"connector" , &nodes[0 ], usb_connector_props, usb_connector_refs }, + {"connector" , &nodes[0 ], usb_connector_props }, { } };
@@ -173,9 +167,10 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data) {software_node_unregister_nodes (nodes); -if (mux_ref.node) { -fwnode_handle_put (software_node_fwnode (mux_ref.node)); - mux_ref.node =NULL ; +if (fusb302_mux_refs[0 ].node) { +fwnode_handle_put ( +software_node_fwnode (fusb302_mux_refs[0 ].node)); + fusb302_mux_refs[0 ].node =NULL ; }if (data->dp) {
@@ -187,25 +182,31 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data)static int cht_int33fe_add_nodes (struct cht_int33fe_data *data) { +const struct software_node *mux_ref_node;int ret; - ret =software_node_register_nodes (nodes); -if (ret) -return ret; - -/* The devices that are not created in this driver need extra steps. */ -/* * There is no ACPI device node for the USB role mux, so we need to wait * until the mux driver has created software node for the mux device. * It means we depend on the mux driver. This function will return * -EPROBE_DEFER until the mux device is registered. */ - mux_ref.node =software_node_find_by_name (NULL ,"intel-xhci-usb-sw" ); -if (!mux_ref.node) { - ret = -EPROBE_DEFER ; - goto err_remove_nodes; - } + mux_ref_node =software_node_find_by_name (NULL ,"intel-xhci-usb-sw" ); +if (!mux_ref_node) +return -EPROBE_DEFER ; + +/* +* Update node used in "usb-role-switch" property. Note that we +* rely on software_node_register_nodes() to use the original +* instance of properties instead of copying them. +*/ + fusb302_mux_refs[0 ].node = mux_ref_node; + + ret =software_node_register_nodes (nodes); +if (ret) +return ret; + +/* The devices that are not created in this driver need extra steps. */ /* * The DP connector does have ACPI device node. In this case we can just
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Re: [PATCH v2 2/3] platform/x86: intel_cht_int33fe: use inline reference properties
Quoted 4 lines · Dmitry Torokhov
Now that static device properties allow defining reference properties together with all other types of properties, instead of managing them separately, let's adjust the driver.
Quoted 157 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
v1-v2:
- rebased on top of linux-next-20190904
drivers/platform/x86/intel_cht_int33fe.c | 81 ++++++++++++------------ 1 file changed, 41 insertions(+), 40 deletions(-)drivers/platform/x86/intel_cht_int33fe.c +41
-40@@ -46,30 +46,6 @@ struct cht_int33fe_data {struct fwnode_handle *dp; }; -static const struct software_node nodes[]; - -static const struct software_node_ref_args pi3usb30532_ref = { - &nodes[INT33FE_NODE_PI3USB30532 ] -}; - -static const struct software_node_ref_args dp_ref = { - &nodes[INT33FE_NODE_DISPLAYPORT ] -}; - -static struct software_node_ref_args mux_ref; - -static const struct software_node_reference usb_connector_refs[] = { - {"orientation-switch" ,1 , &pi3usb30532_ref}, - {"mode-switch" ,1 , &pi3usb30532_ref}, - {"displayport" ,1 , &dp_ref}, - { } -}; - -static const struct software_node_reference fusb302_refs[] = { - {"usb-role-switch" ,1 , &mux_ref}, - { } -}; -/* * Grrr I severly dislike buggy BIOS-es. At least one BIOS enumerates * the max17047 both through the INT33FE ACPI device (it is right there @@ -105,8 +81,18 @@ static const struct property_entry max17047_props[] = { { } }; +/* +* We are not using inline property here because those are constant, +* and we need to adjust this one at runtime to point to real +* software node. +*/ +static struct software_node_ref_args fusb302_mux_refs[] = { + { .node =NULL }, +}; +static const struct property_entry fusb302_props[] = {PROPERTY_ENTRY_STRING ("linux,extcon-name" ,"cht_wcove_pwrsrc" ), +PROPERTY_ENTRY_REF_ARRAY ("usb-role-switch" , fusb302_mux_refs), { } };@@ -122,6 +108,8 @@ static const u32 snk_pdo[] = { PDO_VAR(5000, 12000, 3000), }; +static const struct software_node nodes[]; +static const struct property_entry usb_connector_props[] = {PROPERTY_ENTRY_STRING ("data-role" ,"dual" ),PROPERTY_ENTRY_STRING ("power-role" ,"dual" ),@@ -129,15 +117,21 @@ static const struct property_entry usb_connector_props[] = {PROPERTY_ENTRY_U32_ARRAY ("source-pdos" , src_pdo),PROPERTY_ENTRY_U32_ARRAY ("sink-pdos" , snk_pdo),PROPERTY_ENTRY_U32 ("op-sink-microwatt" ,2500000 ), +PROPERTY_ENTRY_REF ("orientation-switch" , + &nodes[INT33FE_NODE_PI3USB30532 ]), +PROPERTY_ENTRY_REF ("mode-switch" , + &nodes[INT33FE_NODE_PI3USB30532 ]), +PROPERTY_ENTRY_REF ("displayport" , + &nodes[INT33FE_NODE_DISPLAYPORT]), { } };static const struct software_node nodes[] = { - {"fusb302" ,NULL , fusb302_props, fusb302_refs }, + {"fusb302" ,NULL , fusb302_props }, {"max17047" ,NULL , max17047_props }, {"pi3usb30532" }, {"displayport" }, - {"connector" , &nodes[0 ], usb_connector_props, usb_connector_refs }, + {"connector" , &nodes[0 ], usb_connector_props }, { } };@@ -173,9 +167,10 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data) {software_node_unregister_nodes (nodes); -if (mux_ref.node) { -fwnode_handle_put (software_node_fwnode (mux_ref.node)); - mux_ref.node =NULL ; +if (fusb302_mux_refs[0 ].node) { +fwnode_handle_put ( +software_node_fwnode (fusb302_mux_refs[0 ].node)); + fusb302_mux_refs[0 ].node =NULL ; }if (data->dp) {@@ -187,25 +182,31 @@ static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data)static int cht_int33fe_add_nodes (struct cht_int33fe_data *data) { +const struct software_node *mux_ref_node;int ret; - ret =software_node_register_nodes (nodes); -if (ret) -return ret; - -/* The devices that are not created in this driver need extra steps. */ -/* * There is no ACPI device node for the USB role mux, so we need to wait * until the mux driver has created software node for the mux device. * It means we depend on the mux driver. This function will return * -EPROBE_DEFER until the mux device is registered. */ - mux_ref.node =software_node_find_by_name (NULL ,"intel-xhci-usb-sw" ); -if (!mux_ref.node) { - ret = -EPROBE_DEFER ; - goto err_remove_nodes; - } + mux_ref_node =software_node_find_by_name (NULL ,"intel-xhci-usb-sw" ); +if (!mux_ref_node) +return -EPROBE_DEFER ; + +/* +* Update node used in "usb-role-switch" property. Note that we +* rely on software_node_register_nodes() to use the original +* instance of properties instead of copying them. +*/ + fusb302_mux_refs[0 ].node = mux_ref_node; + + ret =software_node_register_nodes (nodes); +if (ret) +return ret; + +/* The devices that are not created in this driver need extra steps. */ /* * The DP connector does have ACPI device node. In this case we can just Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/3 software node: remove separate handling of references
In reply to Dmitry TorokhovNow that all users of references have moved to reference properties, we can remove separate handling of references.
---
v1->v2:
- dropped rename of struct software_node_ref_args -> struct software_node_reference
drivers/base/swnode.c | 44 +++++++++++++++------------------------- include/linux/property.h | 14 ------------- 2 files changed, 16 insertions(+), 42 deletions(-)
drivers/base/swnode.c +16 -28
@@ -570,8 +570,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, struct fwnode_reference_args *args) {struct swnode *swnode =to_swnode (fwnode); -const struct software_node_reference *ref; -const struct software_node_ref_args *ref_args; +const struct software_node_ref_args *ref;const struct property_entry *prop;struct fwnode_handle *refnode;int i;
@@ -580,36 +579,25 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,return -ENOENT ; prop =property_entry_get (swnode->node->properties, propname); -if (prop) { -if (prop->type !=DEV_PROP_REF ) -return -EINVAL ; - -/* -* We expect all references to be stored as arrays via -* a pointer, even single ones. -*/ -if (!prop->is_array) -return -EINVAL ; - -if (index *sizeof (*ref_args) >= prop->length) -return -ENOENT ; +if (!prop) +return -ENOENT ; - ref_args = &prop->pointer.ref[index]; - }else { -if (!swnode->node->references) -return -ENOENT ; +if (prop->type !=DEV_PROP_REF ) +return -EINVAL ; -for (ref = swnode->node->references; ref->name; ref++) -if (!strcmp (ref->name, propname)) -break ; +/* +* We expect all references to be stored as arrays via +* a pointer, even single ones. +*/ +if (!prop->is_array) +return -EINVAL ; -if (!ref->name || index > (ref->nrefs -1 )) -return -ENOENT ; +if (index *sizeof (*ref) >= prop->length) +return -ENOENT ; - ref_args = &ref->refs[index]; - } + ref = &prop->pointer.ref[index]; - refnode =software_node_fwnode (ref_args->node); + refnode =software_node_fwnode (ref->node);if (!refnode)return -ENOENT ;
@@ -628,7 +616,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs;for (i =0 ; i < nargs; i++) - args->args[i] = ref_args->args[i]; + args->args[i] = ref->args[i];return 0 ; }
include/linux/property.h +0 -14
@@ -415,30 +415,16 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,/* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ -/** -* struct software_node_reference - Named software node reference property -* @name: Name of the property -* @nrefs: Number of elements in @refs array -* @refs: Array of references with optional arguments -*/ -struct software_node_reference { -const char *name; -unsigned int nrefs; -const struct software_node_ref_args *refs; -}; -/** * struct software_node - Software node description * @name: Name of the software node * @parent: Parent of the software node * @properties: Array of device properties -* @references: Array of software node reference properties */ struct software_node {const char *name;const struct software_node *parent;const struct property_entry *properties; -const struct software_node_reference *references; };bool is_software_node (const struct fwnode_handle *fwnode);
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Re: [PATCH v2 3/3] software node: remove separate handling of references
Quoted 3 lines · Dmitry Torokhov
Now that all users of references have moved to reference properties, we can remove separate handling of references.
FWIW,
Quoted 124 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
v1->v2:- dropped rename of struct
software_node_ref_args-> structsoftware_node_referencedrivers/base/swnode.c | 44 +++++++++++++++------------------------- include/linux/property.h | 14 ------------- 2 files changed, 16 insertions(+), 42 deletions(-)drivers/base/swnode.c +16
-28@@ -570,8 +570,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, struct fwnode_reference_args *args) {struct swnode *swnode =to_swnode (fwnode); -const struct software_node_reference *ref; -const struct software_node_ref_args *ref_args; +const struct software_node_ref_args *ref;const struct property_entry *prop;struct fwnode_handle *refnode;int i;@@ -580,36 +579,25 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,return -ENOENT ; prop =property_entry_get (swnode->node->properties, propname); -if (prop) { -if (prop->type !=DEV_PROP_REF ) -return -EINVAL ; - -/* -* We expect all references to be stored as arrays via -* a pointer, even single ones. -*/ -if (!prop->is_array) -return -EINVAL ; - -if (index *sizeof (*ref_args) >= prop->length) -return -ENOENT ; +if (!prop) +return -ENOENT ; - ref_args = &prop->pointer.ref[index]; - }else { -if (!swnode->node->references) -return -ENOENT ; +if (prop->type !=DEV_PROP_REF ) +return -EINVAL ; -for (ref = swnode->node->references; ref->name; ref++) -if (!strcmp (ref->name, propname)) -break ; +/* +* We expect all references to be stored as arrays via +* a pointer, even single ones. +*/ +if (!prop->is_array) +return -EINVAL ; -if (!ref->name || index > (ref->nrefs -1 )) -return -ENOENT ; +if (index *sizeof (*ref) >= prop->length) +return -ENOENT ; - ref_args = &ref->refs[index]; - } + ref = &prop->pointer.ref[index]; - refnode =software_node_fwnode (ref_args->node); + refnode =software_node_fwnode (ref->node);if (!refnode)return -ENOENT ;@@ -628,7 +616,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, args->nargs = nargs;for (i =0 ; i < nargs; i++) - args->args[i] = ref_args->args[i]; + args->args[i] = ref->args[i];return 0 ; }include/linux/property.h +0
-14@@ -415,30 +415,16 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,/* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */ -/** -* struct software_node_reference - Named software node reference property -* @name: Name of the property -* @nrefs: Number of elements in @refs array -* @refs: Array of references with optional arguments -*/ -struct software_node_reference { -const char *name; -unsigned int nrefs; -const struct software_node_ref_args *refs; -}; -/** * struct software_node - Software node description * @name: Name of the software node * @parent: Parent of the software node * @properties: Array of device properties -* @references: Array of software node reference properties */ struct software_node {const char *name;const struct software_node *parent;const struct property_entry *properties; -const struct software_node_reference *references; };bool is_software_node (const struct fwnode_handle *fwnode);Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerQuoted 8 lines · Dmitry Torokhov
It is possible to store references to software nodes in the same fashion as other static properties, so that users do not need to define separate structures:
static const struct software_node gpio_bank_b_node = { .name = "B", };
Quoted 7 lines
static const struct property_entry simone_key_enter_props[] = {
PROPERTY_ENTRY_U32("linux,code", KEY_ENTER),
PROPERTY_ENTRY_STRING("label", "enter"),
PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW),
{ }
};Thanks for an update, my comments below.
drivers/base/swnode.c static int property_entry_copy_data(struct property_entry *dst, · line 392
Quoted 3 lines
drivers/base/swnode.c +3
-0+ }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ;
Hmm... What about to duplicate pointer under value union and use is_array to distinguish which one to use? Because...
Review struct property_entry {
Quoted 12 lines
(quoted diff) +5
-0@@ -240,6 +254,7 @@ struct property_entry { const u32 *u32_data; const u64 *u64_data; const char * const *str; + const struct software_node_ref_args *ref; } pointer; +#define PROPERTY_ENTRY_REF(_name_, _ref_, ...) \ +(struct property_entry) { \ + .name = _name_, \ + .length = sizeof(struct software_node_ref_args), \
Is it correct?
include/linux/property.h struct property_entry { · line 306
Quoted 3 lines
include/linux/property.h +2
-0+ .type = DEV_PROP_REF, \ + .is_array = true, \
I really don't like this "cheating".
include/linux/property.h struct property_entry {
Quoted 5 lines
include/linux/property.h +4
-0+ .type = DEV_PROP_REF, \ + .pointer.ref = &(const struct software_node_ref_args ) { \ + .node = _ref_, \ + .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \
Seems like you can drop pair of parentheses.
Quoted 3 lines
include/linux/property.h +3
-0+ .args = { __VA_ARGS__ }, \ + }, \ +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 8 lines · Dmitry Torokhov
It is possible to store references to software nodes in the same fashion as other static properties, so that users do not need to define separate structures:
static const struct software_node gpio_bank_b_node = { .name = "B", };Quoted 7 lines
static const struct property_entry simone_key_enter_props[] = { PROPERTY_ENTRY_U32("linux,code", KEY_ENTER), PROPERTY_ENTRY_STRING("label", "enter"), PROPERTY_ENTRY_REF("gpios", &gpio_bank_b_node, 123, GPIO_ACTIVE_LOW), { } };
Quoted 8 lines
Thanks for an update, my comments below.
drivers/base/swnode.c static int property_entry_copy_data(struct property_entry *dst, · line 392
Quoted 3 lines
drivers/base/swnode.c +3
-0+ }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ;Hmm... What about to duplicate pointer under value union and use
is_arrayto distinguish which one to use? Because...
Then we have to special-case copying this entry, similar to the pains we are going with the strings.
Quoted 9 lines
Quoted 8 lines
include/linux/property.h +1
-0@@ -240,6 +254,7 @@ struct property_entry {const u32 *u32_data;const u64 *u64_data;const char *const *str; +const struct software_node_ref_args *ref; } pointer;
Quoted 7 lines
include/linux/property.h struct property_entry {
Quoted 5 lines
include/linux/property.h +4
-0+#define PROPERTY_ENTRY_REF (_name_, _ref_, ...) \ +(struct property_entry) { \ + .name = _name_, \ + .length = sizeof(struct software_node_ref_args), \Is it correct?
Yes, we length is element size * number of elements.
Quoted 6 lines
include/linux/property.h struct property_entry { · line 306
Quoted 4 lines
include/linux/property.h +2
-0+ .type = DEV_PROP_REF, \ + .is_array = true, \I really don't like this "cheating".
This is not cheating. Any single value can be represented as an array of one element. Actually, the only reason we have this "is_array" business is because for scalar values and short strings it is much cheaper to store single value in-line instead of out of line + pointer, especially on 64 bit arches.
If you want we can change is_array into is_inline.
Thanks.
Signature · 1 line
Dmitry
Andy Shevchenko
reviewerQuoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Andy Shevchenko
drivers/base/swnode.c static int property_entry_copy_data(struct property_entry *dst, · line 392
Quoted 3 lines · Dmitry Torokhov
drivers/base/swnode.c +3
-0+ }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ;Hmm... What about to duplicate pointer under value union and use
is_arrayto distinguish which one to use? Because...
Quoted 2 lines
Then we have to special-case copying this entry, similar to the pains we are going with the strings.
I can't see it as a pain. Simple do the same kmemdup() for the case when is_array = false and DEV_TYPE_REF?
By the way, don't we need to update property_entry_{get,set}_pointer()?
Quoted 9 lines
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ .is_array = true, \I really don't like this "cheating".
This is not cheating. Any single value can be represented as an array of one element. Actually, the only reason we have this "
is_array" business is because for scalar values and short strings it is much cheaper to store single value in-line instead of out of line + pointer, especially on 64 bit arches.
Yes, and this is a lot of benefit!
Quoted 1 line
If you want we can change
is_arrayintois_inline.
Nope, is_array is exactly what it tells us about the content. Its functional load is to distinguish which union (value vs. pointer) we are using.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Andy Shevchenko
drivers/base/swnode.c static int property_entry_copy_data(struct property_entry *dst, · line 392
Quoted 3 lines · Dmitry Torokhov
drivers/base/swnode.c +3
-0+ }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ;Hmm... What about to duplicate pointer under value union and use
is_arrayto distinguish which one to use? Because...
Quoted 5 lines
Quoted 2 lines
Then we have to special-case copying this entry, similar to the pains we are going with the strings.
I can't see it as a pain. Simple do the same
kmemdup()for the case whenis_array= false andDEV_TYPE_REF?
And then you need to make sure it is freed on error paths and when we remove property entries. This requires more checks and code. In contrast we already know how to handle out of line objects of arbitrary size.
The only reason we have inline strings is because for shorter strings we save 4/8 bytes.
Quoted 2 lines
By the way, don't we need to update property_entry_{get,set}_pointer()?
I do not see these, where are they?
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ .is_array = true, \I really don't like this "cheating".
Quoted 7 lines
Quoted 5 lines
This is not cheating. Any single value can be represented as an array of one element. Actually, the only reason we have this "
is_array" business is because for scalar values and short strings it is much cheaper to store single value in-line instead of out of line + pointer, especially on 64 bit arches.Yes, and this is a lot of benefit!
Yes, nobody argues against it. Here however we are dealing with a larger structure. There is absolutely no benefit of trying to separate single value vs array here.
Quoted 5 lines
Quoted 2 lines
If you want we can change
is_arrayintois_inline.Nope,
is_arrayis exactly what it tells us about the content. Its functional load is to distinguish which union (value vs. pointer) we are using.
No, it signifies whether the value is stored within property entry or outside. I can fit probably 8 bytes arrays into property entry structure, in which case is_array will definitely not reflect the data type.
It is the type-specific accessors that know how to parse and fetch data from properties.
Thanks.
Signature · 1 line
Dmitry
Andy Shevchenko
reviewerQuoted 15 lines · Dmitry Torokhov
Quoted 14 lines · Andy Shevchenko
Quoted 12 lines · Dmitry Torokhov
Quoted 8 lines · Andy Shevchenko
drivers/base/swnode.c static int property_entry_copy_data(struct property_entry *dst, · line 392
Quoted 3 lines · Dmitry Torokhov
drivers/base/swnode.c +3
-0+ }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ;Hmm... What about to duplicate pointer under value union and use
is_arrayto distinguish which one to use? Because...Then we have to special-case copying this entry, similar to the pains we are going with the strings.
Quoted 6 lines
Quoted 2 lines
I can't see it as a pain. Simple do the same
kmemdup()for the case whenis_array= false andDEV_TYPE_REF?And then you need to make sure it is freed on error paths and when we remove property entries. This requires more checks and code. In contrast we already know how to handle out of line objects of arbitrary size.
We can put it one level up to be a sibling to value / pointer unions. In that case is_array can be anything (we just don't care).
Actually strings aren't inlined.
Quoted 3 lines
Quoted 1 line
By the way, don't we need to update property_entry_{get,set}_pointer()?
I do not see these, where are they?
swnode.c. I meant property_{get,set}_pointer().
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ .is_array = true, \I really don't like this "cheating".
This is not cheating. Any single value can be represented as an array of one element. Actually, the only reason we have this "
is_array" business is because for scalar values and short strings it is much cheaper to store single value in-line instead of out of line + pointer, especially on 64 bit arches.
Quoted 5 lines
Quoted 1 line
Yes, and this is a lot of benefit!
Yes, nobody argues against it. Here however we are dealing with a larger structure. There is absolutely no benefit of trying to separate single value vs array here.
Thus, moving to upper layer makes more sense. Right?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
If you want we can change
is_arrayintois_inline.Nope,
is_arrayis exactly what it tells us about the content. Its functional load is to distinguish which union (value vs. pointer) we are using.No, it signifies whether the value is stored within property entry or outside. I can fit probably 8 bytes arrays into property entry structure, in which case
is_arraywill definitely not reflect the data type.
Nope, since strings are not inlined AFAICS.
Quoted 2 lines
It is the type-specific accessors that know how to parse and fetch data from properties.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 18 lines · Dmitry Torokhov
Quoted 16 lines · Andy Shevchenko
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Andy Shevchenko
drivers/base/swnode.c static int property_entry_copy_data(struct property_entry *dst, · line 392
Quoted 3 lines · Dmitry Torokhov
drivers/base/swnode.c +3
-0+ }else if (src->type ==DEV_PROP_REF ) { +/* All reference properties must be arrays */ +return -EINVAL ;Hmm... What about to duplicate pointer under value union and use
is_arrayto distinguish which one to use? Because...Quoted 2 lines
Then we have to special-case copying this entry, similar to the pains we are going with the strings.
I can't see it as a pain. Simple do the same
kmemdup()for the case whenis_array= false andDEV_TYPE_REF?
Quoted 6 lines
Quoted 3 lines
And then you need to make sure it is freed on error paths and when we remove property entries. This requires more checks and code. In contrast we already know how to handle out of line objects of arbitrary size.
We can put it one level up to be a sibling to value / pointer unions. In that case
is_arraycan be anything (we just don't care).
I think it would be better if you sketched out your proposed data structure(s) so we are talking about the same things. But please note that when you are dealing with property arrays we need to keep the easy way of defining them, which means we should not be splitting individual entries.
Quoted 2 lines
Actually strings aren't inlined.
Right. Maybe I should clean it up as well.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
By the way, don't we need to update property_entry_{get,set}_pointer()?
I do not see these, where are they?
swnode.c. I meant property_{get,set}_pointer().
Yes, I think you are right about property_set_pointer() at least.
Quoted 24 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ .is_array = true, \I really don't like this "cheating".
This is not cheating. Any single value can be represented as an array of one element. Actually, the only reason we have this "
is_array" business is because for scalar values and short strings it is much cheaper to store single value in-line instead of out of line + pointer, especially on 64 bit arches.Quoted 5 lines
Quoted 1 line
Yes, and this is a lot of benefit!
Yes, nobody argues against it. Here however we are dealing with a larger structure. There is absolutely no benefit of trying to separate single value vs array here.
Thus, moving to upper layer makes more sense. Right?
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
If you want we can change
is_arrayintois_inline.Nope,
is_arrayis exactly what it tells us about the content. Its functional load is to distinguish which union (value vs. pointer) we are using.
Quoted 6 lines
Quoted 4 lines
No, it signifies whether the value is stored within property entry or outside. I can fit probably 8 bytes arrays into property entry structure, in which case
is_arraywill definitely not reflect the data type.Nope, since strings are not inlined AFAICS.
But u64 values are.
Thanks.
Signature · 1 line
Dmitry
Andy Shevchenko
reviewerQuoted 24 lines · Dmitry Torokhov
Quoted 23 lines · Andy Shevchenko
Quoted 21 lines · Dmitry Torokhov
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Andy Shevchenko
Review
Quoted 3 lines · Dmitry Torokhov
(quoted diff) +3
-0+ } else if (src->type == DEV_PROP_REF) { + /* All reference properties must be arrays */ + return -EINVAL;Hmm... What about to duplicate pointer under value union and use
is_arrayto distinguish which one to use? Because...Quoted 5 lines
Quoted 2 lines
Then we have to special-case copying this entry, similar to the pains we are going with the strings.
I can't see it as a pain. Simple do the same
kmemdup()for the case whenis_array= false andDEV_TYPE_REF?And then you need to make sure it is freed on error paths and when we remove property entries. This requires more checks and code. In contrast we already know how to handle out of line objects of arbitrary size.
Quoted 8 lines
Quoted 2 lines
We can put it one level up to be a sibling to value / pointer unions. In that case
is_arraycan be anything (we just don't care).I think it would be better if you sketched out your proposed data structure(s) so we are talking about the same things. But please note that when you are dealing with property arrays we need to keep the easy way of defining them, which means we should not be splitting individual entries.
This one:
union {
union {
const u8 *u8_data;
const u16 *u16_data;
const u32 *u32_data;
const u64 *u64_data;
const char * const *str;
} pointer;
union {
u8 u8_data;
u16 u16_data;
u32 u32_data;
u64 u64_data;
const char *str;
} value;
struct ... *ref;
};Signature · 2 lines
With Best Regards, Andy Shevchenko