diff mbox

[U-Boot,1/2] dfu: dfu_sf: Pass duplicate devstr to parse_dev

Message ID 1445334721-10839-2-git-send-email-vigneshr@ti.com
State Accepted
Delegated to: Przemyslaw Marczak
Headers show

Commit Message

Raghavendra, Vignesh Oct. 20, 2015, 9:52 a.m. UTC
parse_dev() alters the string pointed by devstr parameter. Due to this
subsequent parsing of sf entities will fail, as string pointed by devstr
is no longer valid sf dev arguments.
Fix this by passing pointer to the copy of the string to parse_dev
instead of pointer to the actual devstr.

Signed-off-by: Vignesh R <vigneshr@ti.com>
---
 drivers/dfu/dfu_sf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tom Rini Oct. 20, 2015, 3:45 p.m. UTC | #1
On Tue, Oct 20, 2015 at 03:22:00PM +0530, Vignesh R wrote:

> parse_dev() alters the string pointed by devstr parameter. Due to this
> subsequent parsing of sf entities will fail, as string pointed by devstr
> is no longer valid sf dev arguments.
> Fix this by passing pointer to the copy of the string to parse_dev
> instead of pointer to the actual devstr.
> 
> Signed-off-by: Vignesh R <vigneshr@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
diff mbox

Patch

diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c
index 7646c6b7270c..9702eeea202a 100644
--- a/drivers/dfu/dfu_sf.c
+++ b/drivers/dfu/dfu_sf.c
@@ -115,8 +115,10 @@  static struct spi_flash *parse_dev(char *devstr)
 int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s)
 {
 	char *st;
+	char *devstr_bkup = strdup(devstr);
 
-	dfu->data.sf.dev = parse_dev(devstr);
+	dfu->data.sf.dev = parse_dev(devstr_bkup);
+	free(devstr_bkup);
 	if (!dfu->data.sf.dev)
 		return -ENODEV;