[U-Boot] [PATCH v2 02/12] fw_env.c: Switch get_config to use '%ms' in sscanf

Tom Rini trini at ti.com
Mon Dec 9 19:08:48 CET 2013


We currently limit ourself to 16 characters for the device name to read
the environment from.  This is insufficient for /dev/mmcblk0boot1 to
work for example.  Switch to '%ms' which gives us a dynamically
allocated buffer instead.  We're short lived enough to not bother
free()ing the buffer.

Signed-off-by: Tom Rini <trini at ti.com>

---
Changes in v2:
- Rework to use '%ms' in get_config per Wolfgang

Signed-off-by: Tom Rini <trini at ti.com>
---
 tools/env/fw_env.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 577ce2d..14485c1 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -40,7 +40,7 @@
 	_min1 < _min2 ? _min1 : _min2; })
 
 struct envdev_s {
-	char devname[16];		/* Device name */
+	const char *devname;		/* Device name */
 	ulong devoff;			/* Device offset */
 	ulong env_size;			/* environment size */
 	ulong erase_size;		/* device erase size */
@@ -1243,7 +1243,7 @@ static int parse_config ()
 		return -1;
 	}
 #else
-	strcpy (DEVNAME (0), DEVICE1_NAME);
+	DEVNAME (0) = DEVICE1_NAME;
 	DEVOFFSET (0) = DEVICE1_OFFSET;
 	ENVSIZE (0) = ENV1_SIZE;
 	/* Default values are: erase-size=env-size, #sectors=1 */
@@ -1257,7 +1257,7 @@ static int parse_config ()
 #endif
 
 #ifdef HAVE_REDUND
-	strcpy (DEVNAME (1), DEVICE2_NAME);
+	DEVNAME (1) = DEVICE2_NAME;
 	DEVOFFSET (1) = DEVICE2_OFFSET;
 	ENVSIZE (1) = ENV2_SIZE;
 	/* Default values are: erase-size=env-size, #sectors=1 */
@@ -1295,6 +1295,7 @@ static int get_config (char *fname)
 	int i = 0;
 	int rc;
 	char dump[128];
+	char *devname;
 
 	fp = fopen (fname, "r");
 	if (fp == NULL)
@@ -1305,8 +1306,8 @@ static int get_config (char *fname)
 		if (dump[0] == '#')
 			continue;
 
-		rc = sscanf (dump, "%s %lx %lx %lx %lx",
-			     DEVNAME (i),
+		rc = sscanf (dump, "%ms %lx %lx %lx %lx",
+			     &devname,
 			     &DEVOFFSET (i),
 			     &ENVSIZE (i),
 			     &DEVESIZE (i),
@@ -1315,6 +1316,8 @@ static int get_config (char *fname)
 		if (rc < 3)
 			continue;
 
+		DEVNAME(i) = devname;
+
 		if (rc < 4)
 			/* Assume the erase size is the same as the env-size */
 			DEVESIZE(i) = ENVSIZE(i);
-- 
1.7.9.5



More information about the U-Boot mailing list