pc_fw_add_pflash_drv() fixes
cover pc_fw_add_pflash_drv() fixes
Straightforward bug fixes, so they could qualify for 1.3. But since the bugs are fairly harmless, we might want to postpone to 1.4 regardless. If we do, perhaps qemu-trivial could pick them up.
Markus Armbruster (2):
pc_sysfw: Check for qemu_find_file() failure
pc_sysfw: Plug memory leak on pc_fw_add_pflash_drv() error path
hw/pc_sysfw.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.11.7
PATCH 2/2 pc_sysfw: Plug memory leak on pc_fw_add_pflash_drv() error path
Harmless, because we the error inevitably leads to another, fatal one in pc_system_flash_init(): PC system firmware (pflash) not available. Fix it anyway.
--- hw/pc_sysfw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/pc_sysfw.c +3 -1
@@ -103,7 +103,9 @@ static void pc_fw_add_pflash_drv(void)return ; } -drive_init (opts, machine->use_scsi); +if (!drive_init (opts, machine->use_scsi)) { +qemu_opts_del (opts); + } } static void pc_system_flash_init(MemoryRegion *rom_memory,
Signature · 1 line
1.7.11.7
PATCH 1/2 pc_sysfw: Check for qemu_find_file() failure
In reply to Markus Armbrusterpc_fw_add_pflash_drv() ignores qemu_find_file() failure, and happily creates a drive without a medium.
When pc_system_flash_init() asks for its size, bdrv_getlength() fails with -ENOMEDIUM, which isn't checked either. It fails relatively cleanly only because -ENOMEDIUM isn't a multiple of 4096:
$ qemu-system-x86_64 -S -vnc :0 -bios nonexistant
qemu: PC system firmware (pflash) must be a multiple of 0x1000
[Exit 1 ]Fix by handling the qemu_find_file() failure.
--- hw/pc_sysfw.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/pc_sysfw.c +5 -0
@@ -84,6 +84,11 @@ static void pc_fw_add_pflash_drv(void) bios_name =BIOS_FILENAME ; } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_report ("Can't open BIOS image %s: %s" , + bios_name,strerror (errno)); +exit (1 ); + } opts =drive_add (IF_PFLASH ,-1 , filename,"readonly=on" );
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] pc_sysfw: Check for qemu_find_file() failure
hw/pc_sysfw.c static void pc_fw_add_pflash_drv(void) · line 89
Quoted 11 lines · Markus Armbruster
hw/pc_sysfw.c +3
-0@@ -84,6 +84,11 @@ static void pc_fw_add_pflash_drv(void) bios_name =BIOS_FILENAME ; } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_report ("Can't open BIOS image %s: %s" , + bios_name,strerror (errno));
qemu_find_file() does not document that errno is set when returning NULL. I can't find other callers to qemu_find_file() that use errno either.
Please add a doc comment to qemu_find_file() that errno will be set on NULL return, otherwise we can't rely on it in the caller.
Stefan
Stefan Hajnoczi
AppliedRe: [Qemu-devel] [PATCH 2/2] pc_sysfw: Plug memory leak on pc_fw_add_pflash_drv() error path
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
Harmless, because we the error inevitably leads to another, fatal one in
pc_system_flash_init(): PC system firmware (pflash) not available. Fix it anyway.Signed-off-by Markus Armbruster <[email protected]>--- hw/pc_sysfw.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches
Stefan
Re: [Qemu-devel] [Qemu-trivial] [PATCH 1/2] pc_sysfw: Check for qemu_find_file() failure
In reply to Stefan HajnocziQuoted 17 lines · Stefan Hajnoczi
hw/pc_sysfw.c static void pc_fw_add_pflash_drv(void) · line 89
Quoted 11 lines · Markus Armbruster
hw/pc_sysfw.c +3
-0@@ -84,6 +84,11 @@ static void pc_fw_add_pflash_drv(void) bios_name =BIOS_FILENAME ; } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_report ("Can't open BIOS image %s: %s" , + bios_name,strerror (errno));
qemu_find_file()does not document that errno is set when returning NULL. I can't find other callers toqemu_find_file()that use errno either.
Quoted 2 lines
Please add a doc comment to
qemu_find_file()that errno will be set on NULL return, otherwise we can't rely on it in the caller.
Good point, v2 coming.
PATCH v2 1/2 pc_sysfw: Check for qemu_find_file() failure
In reply to Stefan Hajnoczipc_fw_add_pflash_drv() ignores qemu_find_file() failure, and happily creates a drive without a medium.
When pc_system_flash_init() asks for its size, bdrv_getlength() fails with -ENOMEDIUM, which isn't checked either. It fails relatively cleanly only because -ENOMEDIUM isn't a multiple of 4096:
$ qemu-system-x86_64 -S -vnc :0 -bios nonexistant
qemu: PC system firmware (pflash) must be a multiple of 0x1000
[Exit 1 ]Fix by handling the qemu_find_file() failure.
---
v2: Don't report errno, because that can produce misleading error messages. For instance, when "seabios/out/bios.bin" is unreadable, we fall back to $data_dir/seabios/out/bios.bin, which doesn't exist, and then report "seabios/out/bios.bin: No such file or directory". No other caller reports errno.
hw/pc_sysfw.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/pc_sysfw.c +4 -0
@@ -84,6 +84,10 @@ static void pc_fw_add_pflash_drv(void) bios_name =BIOS_FILENAME ; } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_report ("Can't open BIOS image %s" , bios_name); +exit (1 ); + } opts =drive_add (IF_PFLASH ,-1 , filename,"readonly=on" );
Signature · 1 line
1.7.11.7
Stefan Hajnoczi
AppliedRe: [Qemu-devel] [PATCH v2 1/2] pc_sysfw: Check for qemu_find_file() failure
Quoted 21 lines · Markus Armbruster
pc_fw_add_pflash_drv()ignoresqemu_find_file()failure, and happily creates a drive without a medium.When
pc_system_flash_init()asks for its size,bdrv_getlength()fails with-ENOMEDIUM, which isn't checked either. It fails relatively cleanly only because-ENOMEDIUMisn't a multiple of 4096:$ qemu-system-x86_64 -S -vnc :0 -bios nonexistant qemu: PC system firmware (pflash) must be a multiple of 0x1000 [Exit 1 ]Fix by handling the
qemu_find_file()failure.Signed-off-by Markus Armbruster <[email protected]>---
v2: Don't report errno, because that can produce misleading error messages. For instance, when "seabios/out/bios.bin" is unreadable, we fall back to $data_dir/seabios/out/bios.bin, which doesn't exist, and then report "seabios/out/bios.bin: No such file or directory". No other caller reports errno.
Quoted 2 lines
hw/pc_sysfw.c | 4 ++++ 1 file changed, 4 insertions(+)
Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches
Stefan