mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-06-25 16:12:05 +00:00
sandbox: Drop use of special os_malloc() where possible
Some sandbox files are not built with U-Boot headers, so with the renamed malloc functions there is now no need to use the special os_... allocation functions to access the system routines. Instead we can just call them directly. Update the affected files accordingly. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
f72bdc60b2
commit
0db1b4305a
2 changed files with 15 additions and 15 deletions
|
@ -74,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 = os_malloc(sizeof(struct sockaddr_ll));
|
priv->device = malloc(sizeof(struct sockaddr_ll));
|
||||||
if (priv->device == NULL)
|
if (priv->device == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
device = priv->device;
|
device = priv->device;
|
||||||
|
@ -147,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 = os_malloc(sizeof(struct sockaddr_in));
|
priv->device = malloc(sizeof(struct sockaddr_in));
|
||||||
if (priv->device == NULL)
|
if (priv->device == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
device = priv->device;
|
device = priv->device;
|
||||||
|
@ -282,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)
|
||||||
{
|
{
|
||||||
os_free(priv->device);
|
free(priv->device);
|
||||||
priv->device = NULL;
|
priv->device = NULL;
|
||||||
close(priv->sd);
|
close(priv->sd);
|
||||||
priv->sd = -1;
|
priv->sd = -1;
|
||||||
|
|
|
@ -137,7 +137,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)
|
||||||
printf("Cannot seek to start of file '%s'\n", fname);
|
printf("Cannot seek to start of file '%s'\n", fname);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
*bufp = os_malloc(size);
|
*bufp = malloc(size);
|
||||||
if (!*bufp) {
|
if (!*bufp) {
|
||||||
printf("Not enough memory to read file '%s'\n", fname);
|
printf("Not enough memory to read file '%s'\n", fname);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
@ -306,8 +306,8 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[])
|
||||||
state->argv = argv;
|
state->argv = argv;
|
||||||
|
|
||||||
/* dynamically construct the arguments to the system getopt_long */
|
/* dynamically construct the arguments to the system getopt_long */
|
||||||
short_opts = os_malloc(sizeof(*short_opts) * num_options * 2 + 1);
|
short_opts = malloc(sizeof(*short_opts) * num_options * 2 + 1);
|
||||||
long_opts = os_malloc(sizeof(*long_opts) * num_options);
|
long_opts = malloc(sizeof(*long_opts) * num_options);
|
||||||
if (!short_opts || !long_opts)
|
if (!short_opts || !long_opts)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ void os_dirent_free(struct os_dirent_node *node)
|
||||||
|
|
||||||
while (node) {
|
while (node) {
|
||||||
next = node->next;
|
next = node->next;
|
||||||
os_free(node);
|
free(node);
|
||||||
node = next;
|
node = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,7 +410,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 = os_malloc(len);
|
fname = malloc(len);
|
||||||
if (!fname) {
|
if (!fname) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -423,7 +423,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
||||||
ret = errno;
|
ret = errno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
next = os_malloc(sizeof(*node) + strlen(entry->d_name) + 1);
|
next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
|
||||||
if (!next) {
|
if (!next) {
|
||||||
os_dirent_free(head);
|
os_dirent_free(head);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
@ -432,10 +432,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 = os_realloc(fname, len);
|
fname = realloc(fname, len);
|
||||||
if (!fname) {
|
if (!fname) {
|
||||||
os_free(old_fname);
|
free(old_fname);
|
||||||
os_free(next);
|
free(next);
|
||||||
os_dirent_free(head);
|
os_dirent_free(head);
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -469,7 +469,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
os_free(fname);
|
free(fname);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ static int add_args(char ***argvp, char *add_args[], int count)
|
||||||
for (argc = 0; (*argvp)[argc]; argc++)
|
for (argc = 0; (*argvp)[argc]; argc++)
|
||||||
;
|
;
|
||||||
|
|
||||||
argv = os_malloc((argc + count + 1) * sizeof(char *));
|
argv = 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;
|
||||||
|
@ -669,7 +669,7 @@ static int os_jump_to_file(const char *fname)
|
||||||
os_exit(2);
|
os_exit(2);
|
||||||
|
|
||||||
err = execv(fname, argv);
|
err = execv(fname, argv);
|
||||||
os_free(argv);
|
free(argv);
|
||||||
if (err) {
|
if (err) {
|
||||||
perror("Unable to run image");
|
perror("Unable to run image");
|
||||||
printf("Image filename '%s'\n", fname);
|
printf("Image filename '%s'\n", fname);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue