sandbox: Use malloc() and free() from os layer
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 <sjg@chromium.org> Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/ip.h>
|
#include <netinet/ip.h>
|
||||||
#include <netinet/udp.h>
|
#include <netinet/udp.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -23,6 +24,8 @@
|
|||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <linux/if_packet.h>
|
#include <linux/if_packet.h>
|
||||||
|
|
||||||
|
#include <os.h>
|
||||||
|
|
||||||
struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void)
|
struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void)
|
||||||
{
|
{
|
||||||
return (struct sandbox_eth_raw_if_nameindex *)if_nameindex();
|
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 */
|
/* Prepare device struct */
|
||||||
priv->local_bind_sd = -1;
|
priv->local_bind_sd = -1;
|
||||||
priv->device = malloc(sizeof(struct sockaddr_ll));
|
priv->device = os_malloc(sizeof(struct sockaddr_ll));
|
||||||
if (priv->device == NULL)
|
if (priv->device == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
device = priv->device;
|
device = priv->device;
|
||||||
@@ -144,7 +147,7 @@ static int _local_inet_start(struct eth_sandbox_raw_priv *priv)
|
|||||||
/* Prepare device struct */
|
/* Prepare device struct */
|
||||||
priv->local_bind_sd = -1;
|
priv->local_bind_sd = -1;
|
||||||
priv->local_bind_udp_port = 0;
|
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)
|
if (priv->device == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
device = priv->device;
|
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)
|
void sandbox_eth_raw_os_stop(struct eth_sandbox_raw_priv *priv)
|
||||||
{
|
{
|
||||||
free(priv->device);
|
os_free(priv->device);
|
||||||
priv->device = NULL;
|
priv->device = NULL;
|
||||||
close(priv->sd);
|
close(priv->sd);
|
||||||
priv->sd = -1;
|
priv->sd = -1;
|
||||||
|
@@ -381,7 +381,7 @@ void os_dirent_free(struct os_dirent_node *node)
|
|||||||
|
|
||||||
while (node) {
|
while (node) {
|
||||||
next = node->next;
|
next = node->next;
|
||||||
free(node);
|
os_free(node);
|
||||||
node = next;
|
node = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,7 +406,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
|||||||
/* Create a buffer upfront, with typically sufficient size */
|
/* Create a buffer upfront, with typically sufficient size */
|
||||||
dirlen = strlen(dirname) + 2;
|
dirlen = strlen(dirname) + 2;
|
||||||
len = dirlen + 256;
|
len = dirlen + 256;
|
||||||
fname = malloc(len);
|
fname = os_malloc(len);
|
||||||
if (!fname) {
|
if (!fname) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto done;
|
goto done;
|
||||||
@@ -419,7 +419,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
|||||||
ret = errno;
|
ret = errno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
|
next = os_malloc(sizeof(*node) + strlen(entry->d_name) + 1);
|
||||||
if (!next) {
|
if (!next) {
|
||||||
os_dirent_free(head);
|
os_dirent_free(head);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
@@ -428,10 +428,10 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
|||||||
if (dirlen + strlen(entry->d_name) > len) {
|
if (dirlen + strlen(entry->d_name) > len) {
|
||||||
len = dirlen + strlen(entry->d_name);
|
len = dirlen + strlen(entry->d_name);
|
||||||
old_fname = fname;
|
old_fname = fname;
|
||||||
fname = realloc(fname, len);
|
fname = os_realloc(fname, len);
|
||||||
if (!fname) {
|
if (!fname) {
|
||||||
free(old_fname);
|
os_free(old_fname);
|
||||||
free(next);
|
os_free(next);
|
||||||
os_dirent_free(head);
|
os_dirent_free(head);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto done;
|
goto done;
|
||||||
@@ -465,7 +465,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
free(fname);
|
os_free(fname);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +582,7 @@ static int add_args(char ***argvp, char *add_args[], int count)
|
|||||||
for (argv = *argvp, argc = 0; (*argvp)[argc]; argc++)
|
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) {
|
if (!argv) {
|
||||||
printf("Out of memory for %d argv\n", count);
|
printf("Out of memory for %d argv\n", count);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@@ -645,7 +645,7 @@ static int os_jump_to_file(const char *fname)
|
|||||||
os_exit(2);
|
os_exit(2);
|
||||||
|
|
||||||
err = execv(fname, argv);
|
err = execv(fname, argv);
|
||||||
free(argv);
|
os_free(argv);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user