From d7c146053dd195b90c79b9b8131431f44541d015 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 18 Mar 2015 00:21:32 +0200 Subject: of/irq: Fix of_irq_parse_one() returned error codes The error code paths that require cleanup use a goto to jump to the cleanup code and return an error code. However, the error code variable res, which is initialized to -EINVAL when declared, is then overwritten with the return value of of_parse_phandle_with_args(), and reused as the return code from of_irq_parse_one(). This leads to an undetermined error being returned instead of the expected -EINVAL value. Fix it. Signed-off-by: Laurent Pinchart Cc: stable@vger.kernel.org # 3.13+ Signed-off-by: Rob Herring --- drivers/of/irq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 0d7765807f49..1a7980692f25 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -290,7 +290,7 @@ int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_ar struct device_node *p; const __be32 *intspec, *tmp, *addr; u32 intsize, intlen; - int i, res = -EINVAL; + int i, res; pr_debug("of_irq_parse_one: dev=%s, index=%d\n", of_node_full_name(device), index); @@ -323,15 +323,19 @@ int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_ar /* Get size of interrupt specifier */ tmp = of_get_property(p, "#interrupt-cells", NULL); - if (tmp == NULL) + if (tmp == NULL) { + res = -EINVAL; goto out; + } intsize = be32_to_cpu(*tmp); pr_debug(" intsize=%d intlen=%d\n", intsize, intlen); /* Check index */ - if ((index + 1) * intsize > intlen) + if ((index + 1) * intsize > intlen) { + res = -EINVAL; goto out; + } /* Copy intspec into irq structure */ intspec += index * intsize; -- cgit v1.2.3 From 5ca1b0dd016701f67994414a2af50dec6efcf103 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 17 Mar 2015 12:30:32 -0700 Subject: of: unittest: Add option string test case with longer path There were regressions seen with commit 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()"), where we couldn't handle extra '/' before the ':'. Let's test for this now. Confirmed that this test fails without the previous patch and passes when patched. All other tests pass. Signed-off-by: Brian Norris Acked-by: Leif Lindholm Signed-off-by: Rob Herring --- drivers/of/unittest.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index aba8946cac46..52c45c7df07f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -97,6 +97,11 @@ static void __init of_selftest_find_node_by_name(void) "option path test, subcase #1 failed\n"); of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data/testcase-device1:test/option", &options); + selftest(np && !strcmp("test/option", options), + "option path test, subcase #2 failed\n"); + of_node_put(np); + np = of_find_node_opts_by_path("/testcase-data:testoption", NULL); selftest(np, "NULL option path test failed\n"); of_node_put(np); -- cgit v1.2.3 From 721a09e95c786346b4188863a1cfa3909c76f690 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 17 Mar 2015 12:30:31 -0700 Subject: of: handle both '/' and ':' in path strings Commit 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()") caused a regression in OF handling of stdout-path. While it fixes some cases which have '/' after the ':', it breaks cases where there is more than one '/' *before* the ':'. For example, it breaks this boot string stdout-path = "/rdb/serial@f040ab00:115200"; So rather than doing sequentialized checks (first for '/', then for ':'; or vice versa), to get the correct behavior we need to check for the first occurrence of either one of them. It so happens that the handy strcspn() helper can do just that. Fixes: 106937e8ccdc ("of: fix handling of '/' in options for of_find_node_by_path()") Signed-off-by: Brian Norris Cc: stable@vger.kernel.org # 3.19 Acked-by: Leif Lindholm Signed-off-by: Rob Herring --- drivers/of/base.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/base.c b/drivers/of/base.c index adb8764861c0..966d6fdcf427 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -715,13 +715,8 @@ static struct device_node *__of_find_node_by_path(struct device_node *parent, { struct device_node *child; int len; - const char *end; - end = strchr(path, ':'); - if (!end) - end = strchrnul(path, '/'); - - len = end - path; + len = strcspn(path, "/:"); if (!len) return NULL; -- cgit v1.2.3 From f64255b5072d9c46cef8655d51cf7e10285abed7 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Tue, 17 Mar 2015 16:46:33 -0400 Subject: Revert "of: Fix premature bootconsole disable with 'stdout-path'" This reverts commit 2fa645cb2703d9b3786d850db815414dfeefa51d. The assumption that at least 1 preferred console will be registered when the stdout-path property is set is invalid, which can result in _no_ consoles. Signed-off-by: Peter Hurley Signed-off-by: Rob Herring --- drivers/of/base.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/base.c b/drivers/of/base.c index 966d6fdcf427..8f165b112e03 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1888,10 +1888,8 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) name = of_get_property(of_chosen, "linux,stdout-path", NULL); if (IS_ENABLED(CONFIG_PPC) && !name) name = of_get_property(of_aliases, "stdout", NULL); - if (name) { + if (name) of_stdout = of_find_node_opts_by_path(name, &of_stdout_options); - add_preferred_console("stdout-path", 0, NULL); - } } if (!of_aliases) -- cgit v1.2.3