aboutsummaryrefslogtreecommitdiff
path: root/drivers/mtd
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-06-12 00:05:01 -0600
committerTom Rini <trini@konsulko.com>2018-06-19 07:31:44 -0400
commitfb95283931011aef78d885f2799ad9d7367f4e48 (patch)
tree37b3d2f8be779022f3bc6ed28ce6feb7ebdfb2f7 /drivers/mtd
parent8a682e03d7d18b3d20810ea83fcec69f8d09c909 (diff)
downloadu-boot-fb95283931011aef78d885f2799ad9d7367f4e48.zip
u-boot-fb95283931011aef78d885f2799ad9d7367f4e48.tar.gz
u-boot-fb95283931011aef78d885f2799ad9d7367f4e48.tar.bz2
spi: sandbox: Fix memory leak in sandbox_sf_bind_emul()
Move the strdup() call so that it is only done when we know we will bind the device. Reported-by: Coverity (CID: 131216) Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/spi/sandbox.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
index 7893efe..f23c0e1 100644
--- a/drivers/mtd/spi/sandbox.c
+++ b/drivers/mtd/spi/sandbox.c
@@ -567,16 +567,17 @@ int sandbox_sf_bind_emul(struct sandbox_state *state, int busnum, int cs,
strncpy(name, spec, sizeof(name) - 6);
name[sizeof(name) - 6] = '\0';
strcat(name, "-emul");
- str = strdup(name);
- if (!str)
- return -ENOMEM;
drv = lists_driver_lookup_name("sandbox_sf_emul");
if (!drv) {
puts("Cannot find sandbox_sf_emul driver\n");
return -ENOENT;
}
+ str = strdup(name);
+ if (!str)
+ return -ENOMEM;
ret = device_bind(bus, drv, str, NULL, of_offset, &emul);
if (ret) {
+ free(str);
printf("Cannot create emul device for spec '%s' (err=%d)\n",
spec, ret);
return ret;