From 8099956f6a99fbedc9a81ef5e3f480b9bc4e9424 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 20 Oct 2016 09:25:48 +0200 Subject: [PATCH 1/7] state: pass error code instead of inventing new one Both of_find_path() and of_find_path_by_node() return a meaningful error code, so forward it instead of inventing a new one. Do this especially for the -EPROBE_DEFER case which currently does not work. Signed-off-by: Sascha Hauer --- common/state/state.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/state/state.c b/common/state/state.c index 075618e5b..2be3c8c5c 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -466,9 +466,10 @@ struct state *state_new_from_node(struct device_node *node, char *path, of_path = partition_node->full_name; ret = of_find_path_by_node(partition_node, &path, 0); } - if (!path) { - pr_err("state failed to parse path to backend\n"); - ret = -EINVAL; + if (ret) { + if (ret != -EPROBE_DEFER) + pr_err("state failed to parse path to backend: %s\n", + strerror(-ret)); goto out_release_state; } } From 70af08d8634c00e9593a4407b86a303246791cfb Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 20 Oct 2016 09:27:41 +0200 Subject: [PATCH 2/7] state: driver: handle EPROBE_DEFER When state_new_from_node() returns -ENODEV that means that there is no device available for the node, so return -EPROBE_DEFER in this case and hope a device is there later. Signed-off-by: Sascha Hauer --- drivers/misc/state.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/misc/state.c b/drivers/misc/state.c index b9eb1b7bb..b43aee60f 100644 --- a/drivers/misc/state.c +++ b/drivers/misc/state.c @@ -28,8 +28,12 @@ static int state_probe(struct device_d *dev) bool readonly = false; state = state_new_from_node(np, NULL, 0, 0, readonly); - if (IS_ERR(state)) - return PTR_ERR(state); + if (IS_ERR(state)) { + int ret = PTR_ERR(state); + if (ret == -ENODEV) + ret = -EPROBE_DEFER; + return ret; + } return 0; } From 82eb3dff10ae0c0436e0fcd5ff0c9cd2a2caab3c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 20 Oct 2016 09:28:58 +0200 Subject: [PATCH 3/7] of_path: handle no driver for device in __of_find_path it can happen that there is a device, but there is no driver for this device because it hasn't been probed yet. Return -ENODEV in this case to let the caller know that it has to try later again. Signed-off-by: Sascha Hauer --- drivers/of/of_path.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c index 8e1931f93..12a7c0257 100644 --- a/drivers/of/of_path.c +++ b/drivers/of/of_path.c @@ -61,6 +61,9 @@ static int __of_find_path(struct device_node *node, const char *part, char **out return -ENODEV; } + if (!dev->driver) + return -ENODEV; + device_detect(dev); if (part) From 28d5eb1bbc8681de635d145fa1d0edccb1571e0d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 20 Oct 2016 09:34:42 +0200 Subject: [PATCH 4/7] state: Use dev_* for information rather than pr_* Signed-off-by: Sascha Hauer --- common/state/state.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/state/state.c b/common/state/state.c index 2be3c8c5c..4020d5e1e 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -468,7 +468,7 @@ struct state *state_new_from_node(struct device_node *node, char *path, } if (ret) { if (ret != -EPROBE_DEFER) - pr_err("state failed to parse path to backend: %s\n", + dev_err(&state->dev, "state failed to parse path to backend: %s\n", strerror(-ret)); goto out_release_state; } @@ -488,7 +488,7 @@ struct state *state_new_from_node(struct device_node *node, char *path, &storage_type); if (ret) { storage_type = NULL; - pr_info("No backend-storage-type found, using default.\n"); + dev_info(&state->dev, "No backend-storage-type found, using default.\n"); } ret = state_backend_init(&state->backend, &state->dev, node, @@ -512,10 +512,10 @@ struct state *state_new_from_node(struct device_node *node, char *path, ret = state_load(state); if (ret) { - pr_warn("Failed to load persistent state, continuing with defaults, %d\n", ret); + dev_warn(&state->dev, "Failed to load persistent state, continuing with defaults, %d\n", ret); } - pr_info("New state registered '%s'\n", alias); + dev_info(&state->dev, "New state registered '%s'\n", alias); return state; From 88b67f8ee47cee555342111481c252a39a390e44 Mon Sep 17 00:00:00 2001 From: Stefan Lengfeld Date: Wed, 2 Nov 2016 08:54:27 +0100 Subject: [PATCH 5/7] state: use packed attribute for on storage structs These structs are used for on-storage data layouts. They should be not affected by different integer precisions and alignment optimizations of 32bit or 64bit machines. Using the architecture independent integer data types, like uint32_t, achieves the former, using the packed attribute the later. Signed-off-by: Stefan Lengfeld Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 2 +- common/state/backend_bucket_direct.c | 2 +- common/state/backend_format_raw.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index 72e165e43..d8504e035 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -47,7 +47,7 @@ struct state_backend_storage_bucket_circular { struct device_d *dev; }; -struct state_backend_storage_bucket_circular_meta { +struct __attribute__((__packed__)) state_backend_storage_bucket_circular_meta { uint32_t magic; uint32_t written_length; }; diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c index 08892f001..5225433ec 100644 --- a/common/state/backend_bucket_direct.c +++ b/common/state/backend_bucket_direct.c @@ -32,7 +32,7 @@ struct state_backend_storage_bucket_direct { struct device_d *dev; }; -struct state_backend_storage_bucket_direct_meta { +struct __attribute__((__packed__)) state_backend_storage_bucket_direct_meta { uint32_t magic; uint32_t written_length; }; diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c index 420942413..e028ea616 100644 --- a/common/state/backend_format_raw.c +++ b/common/state/backend_format_raw.c @@ -37,7 +37,7 @@ struct state_backend_format_raw { struct device_d *dev; }; -struct backend_raw_header { +struct __attribute__((__packed__)) backend_raw_header { uint32_t magic; uint16_t reserved; uint16_t data_len; From 2e93886c38dd5126f59481ff8fbc84c1cdc453ce Mon Sep 17 00:00:00 2001 From: Stefan Lengfeld Date: Wed, 2 Nov 2016 08:54:28 +0100 Subject: [PATCH 6/7] state: fix indentation Signed-off-by: Stefan Lengfeld Signed-off-by: Sascha Hauer --- common/state/state_variables.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/state/state_variables.c b/common/state/state_variables.c index efc24562c..1e37856c1 100644 --- a/common/state/state_variables.c +++ b/common/state/state_variables.c @@ -441,9 +441,9 @@ static struct variable_type types[] = { { .type = STATE_TYPE_U8, .type_name = "uint8", - .export = state_uint32_export, - .import = state_uint32_import, - .create = state_uint8_create, + .export = state_uint32_export, + .import = state_uint32_import, + .create = state_uint8_create, }, { .type = STATE_TYPE_U32, .type_name = "uint32", From 63cc1eb8ebbee4b16c659029d263ae791c6eac9c Mon Sep 17 00:00:00 2001 From: Stefan Lengfeld Date: Wed, 2 Nov 2016 08:54:30 +0100 Subject: [PATCH 7/7] docs: state: make string variable type clearer Only fixed length strings are supported. Make the wording clearer. Signed-off-by: Stefan Lengfeld Signed-off-by: Sascha Hauer --- Documentation/devicetree/bindings/barebox/barebox,state.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst b/Documentation/devicetree/bindings/barebox/barebox,state.rst index e39245f6c..438cc434a 100644 --- a/Documentation/devicetree/bindings/barebox/barebox,state.rst +++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst @@ -51,8 +51,8 @@ variable. The node name may end with ``@
``, but the suffix is stripped from the variable name. State variables have a type. Currenty supported types are: ``uint8``, -``uint32``, ``enum32``, ``mac`` address or ``string``. Variable length -strings are not planned. +``uint32``, ``enum32``, ``mac`` address or ``string`` (fixed length string). +Variable length strings are not planned. Required properties: