backends: Use g_autofree in HostMemoryBackendClass::alloc() handlers
In preparation of having HostMemoryBackendClass::alloc() handlers return a boolean, have them use g_autofree. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Gavin Shan <gshan@redhat.com> Message-Id: <20231120213301.24349-15-philmd@linaro.org>
This commit is contained in:
parent
9583a90579
commit
2d7a1eb6e6
@ -20,8 +20,8 @@
|
|||||||
static void
|
static void
|
||||||
sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
||||||
{
|
{
|
||||||
|
g_autofree char *name = NULL;
|
||||||
uint32_t ram_flags;
|
uint32_t ram_flags;
|
||||||
char *name;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (!backend->size) {
|
if (!backend->size) {
|
||||||
@ -41,7 +41,6 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
|||||||
memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
|
memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend),
|
||||||
name, backend->size, ram_flags,
|
name, backend->size, ram_flags,
|
||||||
fd, 0, errp);
|
fd, 0, errp);
|
||||||
g_free(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sgx_epc_backend_instance_init(Object *obj)
|
static void sgx_epc_backend_instance_init(Object *obj)
|
||||||
|
@ -44,8 +44,8 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
|||||||
object_get_typename(OBJECT(backend)));
|
object_get_typename(OBJECT(backend)));
|
||||||
#else
|
#else
|
||||||
HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
|
HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
|
||||||
|
g_autofree gchar *name = NULL;
|
||||||
uint32_t ram_flags;
|
uint32_t ram_flags;
|
||||||
gchar *name;
|
|
||||||
|
|
||||||
if (!backend->size) {
|
if (!backend->size) {
|
||||||
error_setg(errp, "can't create backend with size 0");
|
error_setg(errp, "can't create backend with size 0");
|
||||||
@ -89,7 +89,6 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
|||||||
memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name,
|
memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name,
|
||||||
backend->size, fb->align, ram_flags,
|
backend->size, fb->align, ram_flags,
|
||||||
fb->mem_path, fb->offset, errp);
|
fb->mem_path, fb->offset, errp);
|
||||||
g_free(name);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ static void
|
|||||||
memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
||||||
{
|
{
|
||||||
HostMemoryBackendMemfd *m = MEMORY_BACKEND_MEMFD(backend);
|
HostMemoryBackendMemfd *m = MEMORY_BACKEND_MEMFD(backend);
|
||||||
|
g_autofree char *name = NULL;
|
||||||
uint32_t ram_flags;
|
uint32_t ram_flags;
|
||||||
char *name;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (!backend->size) {
|
if (!backend->size) {
|
||||||
@ -57,7 +57,6 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
|||||||
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
|
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
|
||||||
memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name,
|
memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name,
|
||||||
backend->size, ram_flags, fd, 0, errp);
|
backend->size, ram_flags, fd, 0, errp);
|
||||||
g_free(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
static void
|
static void
|
||||||
ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
||||||
{
|
{
|
||||||
|
g_autofree char *name = NULL;
|
||||||
uint32_t ram_flags;
|
uint32_t ram_flags;
|
||||||
char *name;
|
|
||||||
|
|
||||||
if (!backend->size) {
|
if (!backend->size) {
|
||||||
error_setg(errp, "can't create backend with size 0");
|
error_setg(errp, "can't create backend with size 0");
|
||||||
@ -32,7 +32,6 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
|||||||
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
|
ram_flags |= backend->reserve ? 0 : RAM_NORESERVE;
|
||||||
memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), name,
|
memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), name,
|
||||||
backend->size, ram_flags, errp);
|
backend->size, ram_flags, errp);
|
||||||
g_free(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user