[PATCH 6/8] state: factor out the backend property parsing
Marco Felsch
m.felsch at pengutronix.de
Fri Oct 14 09:35:32 PDT 2022
Move the backend parsing into a own subfunction. This is in preperation
of addding support for a new format which differs from the old one.
While on it introduce the state_of_find_path_by_node() wrapper define
which handles the different compile options: barebox build vs. dt-utils
build which makes the code easier to read. Also remove the unnecessary
ret initialization.
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
common/state/state.c | 55 ++++++++++++++++++++++++++++++--------------
1 file changed, 38 insertions(+), 17 deletions(-)
diff --git a/common/state/state.c b/common/state/state.c
index 6b8b701ba0..cee83ebde4 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -578,6 +578,42 @@ void state_release(struct state *state)
free(state);
}
+#ifdef __BAREBOX__
+
+#define state_of_find_path_by_node(node, path, flags, offset, size) \
+ of_find_path_by_node(node, path, flags)
+
+#else
+
+#define state_of_find_path_by_node(node, path, flags, offset, size) \
+ of_get_devicepath(node, path, offset, size)
+
+#endif /* __BAREBOX__ */
+
+static int
+state_parse_old_backend_format(struct device_node *backend_node,
+ struct state *state, off_t *offset, size_t *size)
+{
+ int ret;
+
+ ret = of_partition_ensure_probed(backend_node);
+ if (ret)
+ return ret;
+
+ ret = state_of_find_path_by_node(backend_node, &state->backend_dev_path,
+ 0, offset, size);
+ if (ret) {
+ if (ret != -EPROBE_DEFER)
+ dev_err(&state->dev, "state failed to parse path to backend: %s\n",
+ strerror(-ret));
+ return ret;
+ }
+
+ state->backend_dts_dev_or_part = of_get_reproducible_name(backend_node);
+
+ return 0;
+}
+
/*
* state_new_from_node - create a new state instance from a device_node
*
@@ -595,7 +631,7 @@ struct state *state_new_from_node(struct device_node *node, bool readonly)
const char *alias;
off_t offset = 0;
size_t size = 0;
- int ret = 0;
+ int ret;
alias = of_alias_get(node);
if (!alias) {
@@ -614,25 +650,10 @@ struct state *state_new_from_node(struct device_node *node, bool readonly)
goto out_release_state;
}
-#ifdef __BAREBOX__
- ret = of_partition_ensure_probed(backend_node);
+ ret = state_parse_old_backend_format(backend_node, state, &offset, &size);
if (ret)
goto out_release_state;
- ret = of_find_path_by_node(backend_node, &state->backend_dev_path, 0);
-#else
- ret = of_get_devicepath(backend_node, &state->backend_dev_path, &offset, &size);
-#endif
-
- if (ret) {
- if (ret != -EPROBE_DEFER)
- dev_err(&state->dev, "state failed to parse path to backend: %s\n",
- strerror(-ret));
- goto out_release_state;
- }
-
- state->backend_dts_dev_or_part = of_get_reproducible_name(backend_node);
-
ret = of_property_read_string(node, "backend-type", &backend_type);
if (ret) {
dev_dbg(&state->dev, "Missing 'backend-type' property\n");
--
2.30.2
More information about the barebox
mailing list