aboutsummaryrefslogtreecommitdiff
path: root/hw/loader.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-08-20 22:09:37 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2011-08-20 23:01:08 -0500
commit7267c0947d7e8ae5dff7bafd932c3bc285f43e5c (patch)
tree9aa05d6e05ed83e67bf014f6745a3081b8407dc5 /hw/loader.c
parent14015304b662e8f8ccce46c5a6927af6a14c510b (diff)
downloadqemu-7267c0947d7e8ae5dff7bafd932c3bc285f43e5c.zip
qemu-7267c0947d7e8ae5dff7bafd932c3bc285f43e5c.tar.gz
qemu-7267c0947d7e8ae5dff7bafd932c3bc285f43e5c.tar.bz2
Use glib memory allocation and free functions
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/loader.c')
-rw-r--r--hw/loader.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/hw/loader.c b/hw/loader.c
index 35d792e..8efb146 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -91,11 +91,11 @@ int read_targphys(const char *name,
uint8_t *buf;
size_t did;
- buf = qemu_malloc(nbytes);
+ buf = g_malloc(nbytes);
did = read(fd, buf, nbytes);
if (did > 0)
rom_add_blob_fixed("read", buf, did, dst_addr);
- qemu_free(buf);
+ g_free(buf);
return did;
}
@@ -234,9 +234,9 @@ static void *load_at(int fd, int offset, int size)
void *ptr;
if (lseek(fd, offset, SEEK_SET) < 0)
return NULL;
- ptr = qemu_malloc(size);
+ ptr = g_malloc(size);
if (read(fd, ptr, size) != size) {
- qemu_free(ptr);
+ g_free(ptr);
return NULL;
}
return ptr;
@@ -351,14 +351,14 @@ static void *zalloc(void *x, unsigned items, unsigned size)
size *= items;
size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
- p = qemu_malloc(size);
+ p = g_malloc(size);
return (p);
}
static void zfree(void *x, void *addr)
{
- qemu_free(addr);
+ g_free(addr);
}
@@ -476,7 +476,7 @@ int load_uimage(const char *filename, target_phys_addr_t *ep,
}
*ep = hdr->ih_ep;
- data = qemu_malloc(hdr->ih_size);
+ data = g_malloc(hdr->ih_size);
if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
fprintf(stderr, "Error reading file\n");
@@ -490,10 +490,10 @@ int load_uimage(const char *filename, target_phys_addr_t *ep,
compressed_data = data;
max_bytes = UBOOT_MAX_GUNZIP_BYTES;
- data = qemu_malloc(max_bytes);
+ data = g_malloc(max_bytes);
bytes = gunzip(data, max_bytes, compressed_data, hdr->ih_size);
- qemu_free(compressed_data);
+ g_free(compressed_data);
if (bytes < 0) {
fprintf(stderr, "Unable to decompress gzipped image!\n");
goto out;
@@ -510,7 +510,7 @@ int load_uimage(const char *filename, target_phys_addr_t *ep,
out:
if (data)
- qemu_free(data);
+ g_free(data);
close(fd);
return ret;
}
@@ -564,11 +564,11 @@ int rom_add_file(const char *file, const char *fw_dir,
int rc, fd = -1;
char devpath[100];
- rom = qemu_mallocz(sizeof(*rom));
- rom->name = qemu_strdup(file);
+ rom = g_malloc0(sizeof(*rom));
+ rom->name = g_strdup(file);
rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
if (rom->path == NULL) {
- rom->path = qemu_strdup(file);
+ rom->path = g_strdup(file);
}
fd = open(rom->path, O_RDONLY | O_BINARY);
@@ -579,12 +579,12 @@ int rom_add_file(const char *file, const char *fw_dir,
}
if (fw_dir) {
- rom->fw_dir = qemu_strdup(fw_dir);
- rom->fw_file = qemu_strdup(file);
+ rom->fw_dir = g_strdup(fw_dir);
+ rom->fw_file = g_strdup(file);
}
rom->addr = addr;
rom->romsize = lseek(fd, 0, SEEK_END);
- rom->data = qemu_mallocz(rom->romsize);
+ rom->data = g_malloc0(rom->romsize);
lseek(fd, 0, SEEK_SET);
rc = read(fd, rom->data, rom->romsize);
if (rc != rom->romsize) {
@@ -618,10 +618,10 @@ int rom_add_file(const char *file, const char *fw_dir,
err:
if (fd != -1)
close(fd);
- qemu_free(rom->data);
- qemu_free(rom->path);
- qemu_free(rom->name);
- qemu_free(rom);
+ g_free(rom->data);
+ g_free(rom->path);
+ g_free(rom->name);
+ g_free(rom);
return -1;
}
@@ -630,11 +630,11 @@ int rom_add_blob(const char *name, const void *blob, size_t len,
{
Rom *rom;
- rom = qemu_mallocz(sizeof(*rom));
- rom->name = qemu_strdup(name);
+ rom = g_malloc0(sizeof(*rom));
+ rom->name = g_strdup(name);
rom->addr = addr;
rom->romsize = len;
- rom->data = qemu_mallocz(rom->romsize);
+ rom->data = g_malloc0(rom->romsize);
memcpy(rom->data, blob, len);
rom_insert(rom);
return 0;
@@ -664,7 +664,7 @@ static void rom_reset(void *unused)
cpu_physical_memory_write_rom(rom->addr, rom->data, rom->romsize);
if (rom->isrom) {
/* rom needs to be written only once */
- qemu_free(rom->data);
+ g_free(rom->data);
rom->data = NULL;
}
}