From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Tue, 2 Oct 2018 05:22:50 -0600 Subject: [U-Boot] [PATCH v2 20/23] sandbox: Use malloc() and free() from os layer In-Reply-To: <20181002112253.202931-1-sjg@chromium.org> References: <20181002112253.202931-1-sjg@chromium.org> Message-ID: <20181002112253.202931-21-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de At present sandbox calls malloc() from various places in the OS layer and this results in calls to U-Boot's malloc() implementation. It is better to use the on in the OS layer, since it does not mix allocations with the main U-Boot code. Fix this by replacing calls with malloc() to os_malloc(), etc. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger --- Changes in v2: None arch/sandbox/cpu/eth-raw-os.c | 9 ++++++--- arch/sandbox/cpu/os.c | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c index 75bfaa4c90a..8d05bc2eda0 100644 --- a/arch/sandbox/cpu/eth-raw-os.c +++ b/arch/sandbox/cpu/eth-raw-os.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,8 @@ #include #include +#include + struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void) { return (struct sandbox_eth_raw_if_nameindex *)if_nameindex(); @@ -71,7 +74,7 @@ static int _raw_packet_start(struct eth_sandbox_raw_priv *priv, /* Prepare device struct */ priv->local_bind_sd = -1; - priv->device = malloc(sizeof(struct sockaddr_ll)); + priv->device = os_malloc(sizeof(struct sockaddr_ll)); if (priv->device == NULL) return -ENOMEM; device = priv->device; @@ -144,7 +147,7 @@ static int _local_inet_start(struct eth_sandbox_raw_priv *priv) /* Prepare device struct */ priv->local_bind_sd = -1; priv->local_bind_udp_port = 0; - priv->device = malloc(sizeof(struct sockaddr_in)); + priv->device = os_malloc(sizeof(struct sockaddr_in)); if (priv->device == NULL) return -ENOMEM; device = priv->device; @@ -279,7 +282,7 @@ int sandbox_eth_raw_os_recv(void *packet, int *length, void sandbox_eth_raw_os_stop(struct eth_sandbox_raw_priv *priv) { - free(priv->device); + os_free(priv->device); priv->device = NULL; close(priv->sd); priv->sd = -1; diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 1723e274535..a91fd069dfe 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -309,7 +309,7 @@ void os_dirent_free(struct os_dirent_node *node) while (node) { next = node->next; - free(node); + os_free(node); node = next; } } @@ -334,7 +334,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) /* Create a buffer upfront, with typically sufficient size */ dirlen = strlen(dirname) + 2; len = dirlen + 256; - fname = malloc(len); + fname = os_malloc(len); if (!fname) { ret = -ENOMEM; goto done; @@ -347,7 +347,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) ret = errno; break; } - next = malloc(sizeof(*node) + strlen(entry->d_name) + 1); + next = os_malloc(sizeof(*node) + strlen(entry->d_name) + 1); if (!next) { os_dirent_free(head); ret = -ENOMEM; @@ -356,10 +356,10 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) if (dirlen + strlen(entry->d_name) > len) { len = dirlen + strlen(entry->d_name); old_fname = fname; - fname = realloc(fname, len); + fname = os_realloc(fname, len); if (!fname) { - free(old_fname); - free(next); + os_free(old_fname); + os_free(next); os_dirent_free(head); ret = -ENOMEM; goto done; @@ -393,7 +393,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) done: closedir(dir); - free(fname); + os_free(fname); return ret; } @@ -510,7 +510,7 @@ static int add_args(char ***argvp, char *add_args[], int count) for (argv = *argvp, argc = 0; (*argvp)[argc]; argc++) ; - argv = malloc((argc + count + 1) * sizeof(char *)); + argv = os_malloc((argc + count + 1) * sizeof(char *)); if (!argv) { printf("Out of memory for %d argv\n", count); return -ENOMEM; @@ -573,7 +573,7 @@ static int os_jump_to_file(const char *fname) os_exit(2); err = execv(fname, argv); - free(argv); + os_free(argv); if (err) return err; -- 2.19.0.605.g01d371f741-goog