All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: paulus@samba.org
Cc: linuxppc-dev@ozlabs.org
Subject: [PATCH 12/19] bootwrapper: Refactor ft_get_prop() into internal and external functions.
Date: Wed, 7 Feb 2007 17:01:34 -0600	[thread overview]
Message-ID: <20070207230134.GL3849@ld0162-tx32.am.freescale.net> (raw)
In-Reply-To: <20070207230017.GA3758@ld0162-tx32.am.freescale.net>

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>
---
 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 b0d27c9..b7ae463 100644
--- a/arch/powerpc/boot/flatdevtree.c
+++ b/arch/powerpc/boot/flatdevtree.c
@@ -769,38 +769,53 @@ void *ft_get_parent(struct ft_cxt *cxt,
 	return NULL;
 }
 
-int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
-		void *buf, const unsigned int buflen)
+static const void *__ft_get_prop(struct ft_cxt *cxt, void *node,
+                                 const char *propname, unsigned int *len)
 {
 	struct ft_atom atom;
-	void *node;
-	char *p;
-	int depth;
-	unsigned int size;
-
-	node = ft_node_ph2node(cxt, phandle);
-	if (node == NULL)
-		return -1;
-
-	depth = 0;
-	p = (char *)node;
+	int depth = 0;
 
-	while ((p = ft_next(cxt, p, &atom)) != NULL) {
+	while ((node = ft_next(cxt, node, &atom)) != NULL) {
 		switch (atom.tag) {
 		case OF_DT_BEGIN_NODE:
 			++depth;
 			break;
+
 		case OF_DT_PROP:
-			if ((depth != 1) || strcmp(atom.name, propname))
+			if (depth != 1 || strcmp(atom.name, propname))
 				break;
-			size = min(atom.size, buflen);
-			memcpy(buf, atom.data, size);
-			return atom.size;
+
+			if (len)
+				*len = atom.size;
+
+			return atom.data;
+
 		case OF_DT_END_NODE:
 			if (--depth <= 0)
-				return -1;
+				return NULL;
 		}
 	}
+
+	return NULL;
+}
+
+int ft_get_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
+		void *buf, const unsigned int buflen)
+{
+	const void *data;
+	unsigned int size;
+
+	void *node = ft_node_ph2node(cxt, phandle);
+	if (!node)
+		return -1;
+
+	data = __ft_get_prop(cxt, node, propname, &size);
+	if (data) {
+		unsigned int clipped_size = min(size, buflen);
+		memcpy(buf, data, clipped_size);
+		return size;
+	}
+
 	return -1;
 }
 
-- 
1.4.4

  parent reply	other threads:[~2007-02-07 23:01 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-07 23:00 [PATCH 00/19] cuboot bootwrapper patchset Scott Wood
2007-02-07 23:01 ` [PATCH 01/19] bootwrapper: Add stddef.h to ops.h Scott Wood
2007-02-07 23:01 ` [PATCH 02/19] bootwrapper: Set -msoft-float and assembler target options Scott Wood
2007-02-07 23:01 ` [PATCH 03/19] bootwrapper: Remove OF-isms Scott Wood
2007-02-07 23:01 ` [PATCH 04/19] bootwrapper: Add ft_root_node() Scott Wood
2007-02-07 23:01 ` [PATCH 05/19] bootwrapper: Rename ft_node_add() to ft_get_phandle() Scott Wood
2007-02-07 23:01 ` [PATCH 06/19] bootwrapper: Make ft_get_phandle() accept and return NULL Scott Wood
2007-02-07 23:01 ` [PATCH 07/19] bootwrapper: Preserve the pp pointer in ft_make_space() when calling ft_reorder() Scott Wood
2007-02-07 23:01 ` [PATCH 08/19] bootwrapper: Modify *pp, not *p, in ft_shuffle() Scott Wood
2007-02-07 23:01 ` [PATCH 09/19] bootwrapper: Rename p and pp to anchor and anchorptr Scott Wood
2007-02-07 23:01 ` [PATCH 10/19] bootwrapper: Use map_string() instead of lookup_string() in ft_prop() Scott Wood
2007-02-07 23:01 ` [PATCH 11/19] bootwrapper: Add ft_find_device_rel() Scott Wood
2007-02-08  1:11   ` David Gibson
2007-02-08 17:14     ` Scott Wood
2007-02-07 23:01 ` Scott Wood [this message]
2007-02-07 23:01 ` [PATCH 13/19] bootwrapper: Make ft_get_parent() return a phandle, and NULL if already top-level Scott Wood
2007-02-07 23:01 ` [PATCH 14/19] bootwrapper: Add ft_find_node_by_prop_value() Scott Wood
2007-02-07 23:01 ` [PATCH 15/19] bootwrapper: Add initrd information to the device tree in ft_finalize() Scott Wood
2007-02-09 23:02   ` Mark A. Greer
2007-02-10  0:37     ` David Gibson
2007-02-12 16:42     ` Scott Wood
2007-02-13  4:29       ` David Gibson
2007-02-13 16:07         ` Scott Wood
2007-02-14  4:43           ` David Gibson
2007-02-07 23:01 ` [PATCH 16/19] bootwrapper: Make ft_create_node() pay attention to the parent parameter Scott Wood
2007-02-07 23:01 ` [PATCH 17/19] bootwrapper: Add dt_ops methods Scott Wood
2007-02-09 23:05   ` Mark A. Greer
2007-02-07 23:01 ` [PATCH 18/19] bootwrapper: Add xlate_reg(), and use it to find serial registers Scott Wood
2007-02-09 23:07   ` Mark A. Greer
2007-02-12 16:45     ` Scott Wood
2007-02-12 21:10       ` Josh Boyer
2007-02-13  4:30         ` David Gibson
2007-02-13 16:00         ` Scott Wood
2007-02-07 23:01 ` [PATCH 19/19] bootwrapper: compatibility layer for old U-Boots (a.k.a. cuImage, cuboot) Scott Wood
2007-02-08 21:15   ` David Gibson
2007-02-09 17:11     ` Scott Wood
2007-02-10  1:02       ` David Gibson
2007-02-12 16:52         ` Scott Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070207230134.GL3849@ld0162-tx32.am.freescale.net \
    --to=scottwood@freescale.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.