public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 1/3] arm, am335x, siemens: fix factoryset interpretation
Date: Tue, 18 Nov 2014 11:51:04 +0100	[thread overview]
Message-ID: <1416307867-32182-2-git-send-email-hs@denx.de> (raw)
In-Reply-To: <1416307867-32182-1-git-send-email-hs@denx.de>

a record could contain other records, so after an ">" (begin mark)
there not always come an end mark "<", instead a ">" is possible.
Take care of this.

Signed-off-by: Heiko Schocher <hs@denx.de>

---

 board/siemens/common/factoryset.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/board/siemens/common/factoryset.c b/board/siemens/common/factoryset.c
index 266dbbb..d98e59d 100644
--- a/board/siemens/common/factoryset.c
+++ b/board/siemens/common/factoryset.c
@@ -86,6 +86,7 @@ int get_factory_record_val(unsigned char *eeprom_buf, int size,	uchar *record,
 	int i, nxt = 0;
 	int c;
 	unsigned char end = 0xff;
+	unsigned char tmp;
 
 	for (i = 0; fact_get_char(i) != end; i = nxt) {
 		nxt = i + 1;
@@ -93,6 +94,7 @@ int get_factory_record_val(unsigned char *eeprom_buf, int size,	uchar *record,
 			int pos;
 			int endpos;
 			int z;
+			int level = 0;
 
 			c = strncmp((char *)&eeprom_buf[i + 1], (char *)record,
 				    strlen((char *)record));
@@ -103,22 +105,30 @@ int get_factory_record_val(unsigned char *eeprom_buf, int size,	uchar *record,
 				/* search for "<" */
 				c = -1;
 				for (z = pos; fact_get_char(z) != end; z++) {
-					if ((fact_get_char(z) == '<')  ||
-					    (fact_get_char(z) == '>')) {
-						endpos = z;
-						nxt = endpos;
-						c = 0;
-						break;
+					if (fact_get_char(z) == '<') {
+						if (level == 0) {
+							endpos = z;
+							nxt = endpos;
+							c = 0;
+							break;
+						} else {
+							level--;
+						}
 					}
+					if (fact_get_char(z) == '>')
+						level++;
 				}
+			} else {
+				continue;
 			}
 			if (c == 0) {
 				/* end found -> call get_factory_val */
+				tmp = eeprom_buf[endpos];
 				eeprom_buf[endpos] = end;
 				ret = get_factory_val(&eeprom_buf[pos],
-					size - pos, name, buf, len);
+					endpos - pos, name, buf, len);
 				/* fix buffer */
-				eeprom_buf[endpos] = '<';
+				eeprom_buf[endpos] = tmp;
 				debug("%s: %s.%s = %s\n",
 				      __func__, record, name, buf);
 				return ret;
-- 
1.8.3.1

  reply	other threads:[~2014-11-18 10:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18 10:51 [U-Boot] [PATCH v1 0/3] arm, am335x: siemens board updates Heiko Schocher
2014-11-18 10:51 ` Heiko Schocher [this message]
2014-12-05 14:53   ` [U-Boot] [U-Boot, v1, 1/3] arm, am335x, siemens: fix factoryset interpretation Tom Rini
2014-11-18 10:51 ` [U-Boot] [PATCH v1 2/3] arm, am335x, siemens: read COMP/ver from factoryset Heiko Schocher
2014-12-05 14:53   ` [U-Boot] [U-Boot, v1, " Tom Rini
2014-11-18 10:51 ` [U-Boot] [PATCH v1 3/3] arm, am335x: siemens boards add FIT support Heiko Schocher
2014-12-05 14:53   ` [U-Boot] [U-Boot, v1, " Tom Rini

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=1416307867-32182-2-git-send-email-hs@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox