From 67817b3b7a885b86b02b222675e0e29b1a2f25bf Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 Feb 2020 21:46:04 +0100 Subject: dm: core: remove redundant assignment Variable count is initialized at the start of every round of the while loop and it is not used after the while loop. So there is no need to initialize it beforehand. Identified by cppcheck. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/core/of_access.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/core/of_access.c') diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index acd745c1211..29e705e0b66 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -577,7 +577,7 @@ static int __of_parse_phandle_with_args(const struct device_node *np, { const __be32 *list, *list_end; int rc = 0, cur_index = 0; - uint32_t count = 0; + uint32_t count; struct device_node *node = NULL; phandle phandle; int size; -- cgit v1.2.3 From 4bb7075c830c6f4e4512fe0277ff1f08c5a9e084 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 29 Mar 2020 18:04:41 +0200 Subject: dm: core: support reading a single indexed u32 value The patch adds helper functions to allow reading a single indexed u32 value from a device-tree property containing multiple u32 values, that is an array of integers. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- drivers/core/of_access.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'drivers/core/of_access.c') diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 29e705e0b66..8b2ce7a0c21 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -485,6 +485,28 @@ int of_read_u32_array(const struct device_node *np, const char *propname, return 0; } +int of_read_u32_index(const struct device_node *np, const char *propname, + int index, u32 *outp) +{ + const __be32 *val; + + debug("%s: %s: ", __func__, propname); + if (!np) + return -EINVAL; + + val = of_find_property_value_of_size(np, propname, + sizeof(*outp) * (index + 1)); + if (IS_ERR(val)) { + debug("(not found)\n"); + return PTR_ERR(val); + } + + *outp = be32_to_cpup(val + index); + debug("%#x (%d)\n", *outp, *outp); + + return 0; +} + int of_read_u64(const struct device_node *np, const char *propname, u64 *outp) { const __be64 *val; -- cgit v1.2.3 From 59006608d65b242b19176f1a1fdeeb99391654d2 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Sun, 29 Mar 2020 18:04:42 +0200 Subject: dm: core: refactor functions reading an u32 from dt Now reading a 32 bit value from a device-tree property can be expressed as reading the first element of an array with a single value. Signed-off-by: Dario Binacchi Reviewed-by: Simon Glass --- drivers/core/of_access.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'drivers/core/of_access.c') diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 8b2ce7a0c21..c54baa140ad 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -449,21 +449,7 @@ static void *of_find_property_value_of_size(const struct device_node *np, int of_read_u32(const struct device_node *np, const char *propname, u32 *outp) { - const __be32 *val; - - debug("%s: %s: ", __func__, propname); - if (!np) - return -EINVAL; - val = of_find_property_value_of_size(np, propname, sizeof(*outp)); - if (IS_ERR(val)) { - debug("(not found)\n"); - return PTR_ERR(val); - } - - *outp = be32_to_cpup(val); - debug("%#x (%d)\n", *outp, *outp); - - return 0; + return of_read_u32_index(np, propname, 0, outp); } int of_read_u32_array(const struct device_node *np, const char *propname, -- cgit v1.2.3