pci: pci_add_option_rom(): refactor: use g_autofree for path variable
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: David Hildenbrand <david@redhat.com> Message-Id: <20230515125229.44836-3-vsementsov@yandex-team.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
4ab049c7e6
commit
5b52692f9d
@ -2307,7 +2307,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
|
|||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
int64_t size;
|
int64_t size;
|
||||||
char *path;
|
g_autofree char *path = NULL;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
char name[32];
|
char name[32];
|
||||||
const VMStateDescription *vmsd;
|
const VMStateDescription *vmsd;
|
||||||
@ -2349,16 +2349,13 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
|
|||||||
size = get_image_size(path);
|
size = get_image_size(path);
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile);
|
error_setg(errp, "failed to find romfile \"%s\"", pdev->romfile);
|
||||||
g_free(path);
|
|
||||||
return;
|
return;
|
||||||
} else if (size == 0) {
|
} else if (size == 0) {
|
||||||
error_setg(errp, "romfile \"%s\" is empty", pdev->romfile);
|
error_setg(errp, "romfile \"%s\" is empty", pdev->romfile);
|
||||||
g_free(path);
|
|
||||||
return;
|
return;
|
||||||
} else if (size > 2 * GiB) {
|
} else if (size > 2 * GiB) {
|
||||||
error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 GiB)",
|
error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 GiB)",
|
||||||
pdev->romfile);
|
pdev->romfile);
|
||||||
g_free(path);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pdev->romsize != -1) {
|
if (pdev->romsize != -1) {
|
||||||
@ -2366,7 +2363,6 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
|
|||||||
error_setg(errp, "romfile \"%s\" (%u bytes) "
|
error_setg(errp, "romfile \"%s\" (%u bytes) "
|
||||||
"is too large for ROM size %u",
|
"is too large for ROM size %u",
|
||||||
pdev->romfile, (uint32_t)size, pdev->romsize);
|
pdev->romfile, (uint32_t)size, pdev->romsize);
|
||||||
g_free(path);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2384,10 +2380,8 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
|
|||||||
ptr = memory_region_get_ram_ptr(&pdev->rom);
|
ptr = memory_region_get_ram_ptr(&pdev->rom);
|
||||||
if (load_image_size(path, ptr, size) < 0) {
|
if (load_image_size(path, ptr, size) < 0) {
|
||||||
error_setg(errp, "failed to load romfile \"%s\"", pdev->romfile);
|
error_setg(errp, "failed to load romfile \"%s\"", pdev->romfile);
|
||||||
g_free(path);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_free(path);
|
|
||||||
|
|
||||||
if (is_default_rom) {
|
if (is_default_rom) {
|
||||||
/* Only the default rom images will be patched (if needed). */
|
/* Only the default rom images will be patched (if needed). */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user