Commit 1889a7e275c82cfa120004595a652e834c3723e1

Authored by Peng Fan
Committed by Anatolij Gustschin
1 parent c4a45d4bdd

fdt: introduce fdtdec_get_child_count

Introduce fdtdec_get_child_count for get the number of subnodes
of one parent node.

Signed-off-by: Peng Fan <van.freenix@gmail.com>
Cc: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 20 additions and 0 deletions Side-by-side Diff

... ... @@ -722,6 +722,15 @@
722 722 */
723 723 int fdtdec_get_bool(const void *blob, int node, const char *prop_name);
724 724  
  725 +/*
  726 + * Count child nodes of one parent node.
  727 + *
  728 + * @param blob FDT blob
  729 + * @param node parent node
  730 + * @return number of child node; 0 if there is not child node
  731 + */
  732 +int fdtdec_get_child_count(const void *blob, int node);
  733 +
725 734 /**
726 735 * Look in the FDT for a config item with the given name and return its value
727 736 * as a 32-bit integer. The property must have at least 4 bytes of data. The
... ... @@ -831,6 +831,17 @@
831 831 return rc;
832 832 }
833 833  
  834 +int fdtdec_get_child_count(const void *blob, int node)
  835 +{
  836 + int subnode;
  837 + int num = 0;
  838 +
  839 + fdt_for_each_subnode(blob, subnode, node)
  840 + num++;
  841 +
  842 + return num;
  843 +}
  844 +
834 845 int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
835 846 u8 *array, int count)
836 847 {