diff options
author | Scott Wood <scottwood@freescale.com> | 2007-03-12 16:41:54 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-03-16 00:49:10 -0400 |
commit | c350038b2bdabb07611dcc8116b55f917ada09fa (patch) | |
tree | 431879cc84411c82fc458e9280eebc56a61a8b57 /arch | |
parent | fc583411617bf8a466c68350697a806704e88fc3 (diff) |
[POWERPC] bootwrapper: Refactor ft_get_prop() into internal and external functions.
The property searching part of ft_get_prop is factored out into an
internal __ft_get_prop() which does not deal with phandles and does not
copy the property data. ft_get_prop() is then a wrapper that does the
phandle translation and copying.
Signed-off-by: Scott Wood <scottwood@freescale.com>
Acked-by: Mark A. Greer <mgreer@mvista.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/powerpc/boot/flatdevtree.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/arch/powerpc/boot/flatdevtree.c b/arch/powerpc/boot/flatdevtree.c index bd006f75e5ed..9de267dd1cdc 100644 --- a/arch/powerpc/boot/flatdevtree.c +++ b/arch/powerpc/boot/flatdevtree.c | |||
@@ -765,38 +765,53 @@ void *ft_get_parent(struct ft_cxt *cxt, const void *phandle) | |||
765 | return NULL; | 765 | return NULL; |
766 | } | 766 | } |
767 | 767 | ||
768 | int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname, | 768 | static const void *__ft_get_prop(struct ft_cxt *cxt, void *node, |
769 | void *buf, const unsigned int buflen) | 769 | const char *propname, unsigned int *len) |
770 | { | 770 | { |
771 | struct ft_atom atom; | 771 | struct ft_atom atom; |
772 | void *node; | 772 | int depth = 0; |
773 | char *p; | ||
774 | int depth; | ||
775 | unsigned int size; | ||
776 | |||
777 | node = ft_node_ph2node(cxt, phandle); | ||
778 | if (node == NULL) | ||
779 | return -1; | ||
780 | |||
781 | depth = 0; | ||
782 | p = (char *)node; | ||
783 | 773 | ||
784 | while ((p = ft_next(cxt, p, &atom)) != NULL) { | 774 | while ((node = ft_next(cxt, node, &atom)) != NULL) { |
785 | switch (atom.tag) { | 775 | switch (atom.tag) { |
786 | case OF_DT_BEGIN_NODE: | 776 | case OF_DT_BEGIN_NODE: |
787 | ++depth; | 777 | ++depth; |
788 | break; | 778 | break; |
779 | |||
789 | case OF_DT_PROP: | 780 | case OF_DT_PROP: |
790 | if ((depth != 1) || strcmp(atom.name, propname)) | 781 | if (depth != 1 || strcmp(atom.name, propname)) |
791 | break; | 782 | break; |
792 | size = min(atom.size, buflen); | 783 | |
793 | memcpy(buf, atom.data, size); | 784 | if (len) |
794 | return atom.size; | 785 | *len = atom.size; |
786 | |||
787 | return atom.data; | ||
788 | |||
795 | case OF_DT_END_NODE: | 789 | case OF_DT_END_NODE: |
796 | if (--depth <= 0) | 790 | if (--depth <= 0) |
797 | return -1; | 791 | return NULL; |
798 | } | 792 | } |
799 | } | 793 | } |
794 | |||
795 | return NULL; | ||
796 | } | ||
797 | |||
798 | int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname, | ||
799 | void *buf, const unsigned int buflen) | ||
800 | { | ||
801 | const void *data; | ||
802 | unsigned int size; | ||
803 | |||
804 | void *node = ft_node_ph2node(cxt, phandle); | ||
805 | if (!node) | ||
806 | return -1; | ||
807 | |||
808 | data = __ft_get_prop(cxt, node, propname, &size); | ||
809 | if (data) { | ||
810 | unsigned int clipped_size = min(size, buflen); | ||
811 | memcpy(buf, data, clipped_size); | ||
812 | return size; | ||
813 | } | ||
814 | |||
800 | return -1; | 815 | return -1; |
801 | } | 816 | } |
802 | 817 | ||