of: Introduce of_phandle_iterator_args()
authorJoerg Roedel <jroedel@suse.de>
Mon, 4 Apr 2016 15:49:21 +0000 (17:49 +0200)
committerRob Herring <robh@kernel.org>
Tue, 19 Apr 2016 22:25:15 +0000 (17:25 -0500)
This helper function can be used to copy the arguments of a
phandle to an array.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Rob Herring <robh@kernel.org>
drivers/of/base.c
include/linux/of.h

index ea5a13d3c5a5697e0d0e3bc12d100adb503c6db0..e87e21df19d8fcf177750fa1d9266240917ecd2b 100644 (file)
@@ -1534,6 +1534,23 @@ err:
        return -EINVAL;
 }
 
+int of_phandle_iterator_args(struct of_phandle_iterator *it,
+                            uint32_t *args,
+                            int size)
+{
+       int i, count;
+
+       count = it->cur_count;
+
+       if (WARN_ON(size < count))
+               count = size;
+
+       for (i = 0; i < count; i++)
+               args[i] = be32_to_cpup(it->cur++);
+
+       return count;
+}
+
 static int __of_parse_phandle_with_args(const struct device_node *np,
                                        const char *list_name,
                                        const char *cells_name,
@@ -1557,13 +1574,13 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
                                goto err;
 
                        if (out_args) {
-                               int i;
-                               if (WARN_ON(it.cur_count > MAX_PHANDLE_ARGS))
-                                       it.cur_count = MAX_PHANDLE_ARGS;
+                               int c;
+
+                               c = of_phandle_iterator_args(&it,
+                                                            out_args->args,
+                                                            MAX_PHANDLE_ARGS);
                                out_args->np = it.node;
-                               out_args->args_count = it.cur_count;
-                               for (i = 0; i < it.cur_count; i++)
-                                       out_args->args[i] = be32_to_cpup(it.cur++);
+                               out_args->args_count = c;
                        } else {
                                of_node_put(it.node);
                        }
index b0b80716fbfb327584832f06dfe1af70861730bb..71e1c35a59602be43b27533c5dd6600e40655cff 100644 (file)
@@ -359,6 +359,9 @@ extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
                                    int cell_count);
 
 extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
+extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
+                                   uint32_t *args,
+                                   int size);
 
 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
 extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -648,6 +651,13 @@ static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
        return -ENOSYS;
 }
 
+static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
+                                          uint32_t *args,
+                                          int size)
+{
+       return 0;
+}
+
 static inline int of_alias_get_id(struct device_node *np, const char *stem)
 {
        return -ENOSYS;
This page took 0.045276 seconds and 5 git commands to generate.