summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich Ölmann <u.oelmann@pengutronix.de>2018-12-18 14:57:53 +0100
committerRoland Hieber <rhi@pengutronix.de>2019-01-07 15:47:56 +0100
commit498e2d84d0867b9ba6dcf5b7613ca9983c673b33 (patch)
tree216b2a3d663df0b71a55c325d4cca67741d0a89d
parent8dcc82777ae4f80be670bf05230e46ba08c2c078 (diff)
downloaddt-utils-498e2d84d0867b9ba6dcf5b7613ca9983c673b33.tar.gz
dt-utils-498e2d84d0867b9ba6dcf5b7613ca9983c673b33.tar.xz
state: remove unused arguments from state_new_from_node()
Other than in barebox the offset and size of a state's backend device do not necessarily equal zero in Linux userspace (EEPROMs & block devices). So we have to consider that and differentiate between both usecases here while porting the following barebox commit and removing the now no longer used noop definition of of_find_path_by_node(): | commit a66a8d79871c3763cd488cd5e785415a5dbc36de | Author: Sascha Hauer <s.hauer@pengutronix.de> | Date: Tue Feb 20 12:21:00 2018 +0100 | | state: remove unused arguments from state_new_from_node() | | state_new_from_node() has arguments describing the backend path. These | are never used in barebox, the backend path is always derived from the | device nodes backend description. Remove these arguments. | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de> [rhi: fixed tabs vs. spaces indentation in state_new_from_node()] Signed-off-by: Roland Hieber <rhi@pengutronix.de>
-rw-r--r--src/barebox-state.c19
-rw-r--r--src/barebox-state/state.c50
-rw-r--r--src/dt/dt.h6
-rw-r--r--src/state.h3
4 files changed, 25 insertions, 53 deletions
diff --git a/src/barebox-state.c b/src/barebox-state.c
index f10b7c6..f8b8df6 100644
--- a/src/barebox-state.c
+++ b/src/barebox-state.c
@@ -310,15 +310,12 @@ static int state_set_var(struct state *state, const char *var, const char *val)
struct state *state_get(const char *name, bool readonly, bool auth)
{
- struct device_node *root, *node, *partition_node;
+ struct device_node *root, *node;
char *path;
struct state *state;
int ret;
const char *backend_type = NULL;
struct state_variable *v;
- char *devpath;
- off_t offset;
- size_t size;
root = of_read_proc_devicetree();
if (IS_ERR(root)) {
@@ -349,19 +346,7 @@ struct state *state_get(const char *name, bool readonly, bool auth)
if (pr_level_get() > 6)
of_print_nodes(node, 0);
- partition_node = of_parse_phandle(node, "backend", 0);
- if (!partition_node) {
- pr_err("cannot find backend node in %s\n", node->full_name);
- exit (1);
- }
-
- ret = of_get_devicepath(partition_node, &devpath, &offset, &size);
- if (ret) {
- pr_err("Cannot find backend path in %s\n", node->full_name);
- return ERR_PTR(ret);
- }
-
- state = state_new_from_node(node, devpath, offset, size, readonly);
+ state = state_new_from_node(node, readonly);
if (IS_ERR(state)) {
pr_err("unable to initialize state: %s\n",
strerror(PTR_ERR(state)));
diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c
index 6e483df..d6ab464 100644
--- a/src/barebox-state/state.c
+++ b/src/barebox-state/state.c
@@ -566,17 +566,10 @@ void state_release(struct state *state)
/*
* state_new_from_node - create a new state instance from a device_node
*
- * @node The device_node describing the new state instance
- * @path Path to the backend device. If NULL the path is constructed
- * using the path in the backend property of the DT.
- * @offset Offset in the device path. May be 0 to start at the beginning.
- * @max_size Maximum size of the area used. This may be 0 to use the full
- * size.
* @readonly This is a read-only state. Note that with this option set,
* there are no repairs done.
*/
-struct state *state_new_from_node(struct device_node *node, char *path,
- off_t offset, size_t max_size, bool readonly)
+struct state *state_new_from_node(struct device_node *node, bool readonly)
{
struct state *state;
int ret = 0;
@@ -584,6 +577,9 @@ struct state *state_new_from_node(struct device_node *node, char *path,
const char *storage_type = NULL;
const char *alias;
uint32_t stridesize;
+ struct device_node *partition_node;
+ off_t offset = 0;
+ size_t size = 0;
alias = of_alias_get(node);
if (!alias) {
@@ -595,26 +591,24 @@ struct state *state_new_from_node(struct device_node *node, char *path,
if (IS_ERR(state))
return state;
- if (!path) {
- struct device_node *partition_node;
-
- partition_node = of_parse_phandle(node, "backend", 0);
- if (!partition_node) {
- dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n");
- ret = -EINVAL;
- goto out_release_state;
- }
-
- ret = of_find_path_by_node(partition_node, &path, 0);
- 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;
- }
+ partition_node = of_parse_phandle(node, "backend", 0);
+ if (!partition_node) {
+ dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n");
+ ret = -EINVAL;
+ goto out_release_state;
}
- state->backend_path = xstrdup(path);
+#ifdef __BAREBOX__
+ ret = of_find_path_by_node(partition_node, &state->backend_path, 0);
+#else
+ ret = of_get_devicepath(partition_node, &state->backend_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;
+ }
ret = of_property_read_string(node, "backend-type", &backend_type);
if (ret) {
@@ -634,8 +628,8 @@ struct state *state_new_from_node(struct device_node *node, char *path,
if (ret)
goto out_release_state;
- ret = state_storage_init(state, path, offset,
- max_size, stridesize, storage_type);
+ ret = state_storage_init(state, state->backend_path, offset,
+ size, stridesize, storage_type);
if (ret)
goto out_release_state;
diff --git a/src/dt/dt.h b/src/dt/dt.h
index 6d71a71..10fe162 100644
--- a/src/dt/dt.h
+++ b/src/dt/dt.h
@@ -370,12 +370,6 @@ static inline struct device_node *of_find_root_node(struct device_node *node)
struct device_node *of_read_proc_devicetree(void);
-static inline int of_find_path_by_node(struct device_node *node, char **outpath,
- unsigned flags)
-{
- return -ENOSYS;
-}
-
static inline struct device_node *of_find_node_by_devpath(struct device_node *root,
const char *path)
{
diff --git a/src/state.h b/src/state.h
index 888b491..132c0c3 100644
--- a/src/state.h
+++ b/src/state.h
@@ -10,8 +10,7 @@ int state_backend_dtb_file(struct state *state, const char *of_path,
int state_backend_raw_file(struct state *state, const char *of_path,
const char *path, off_t offset, size_t size);
-struct state *state_new_from_node(struct device_node *node, char *path,
- off_t offset, size_t max_size, bool readonly);
+struct state *state_new_from_node(struct device_node *node, bool readonly);
void state_release(struct state *state);
struct state *state_by_name(const char *name);