[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 20/25] hw/block/pflash_cfi*.c: fix confusing assert f
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 20/25] hw/block/pflash_cfi*.c: fix confusing assert fail message |
Date: |
Thu, 22 Dec 2016 16:22:55 +0100 |
From: Ziyue Yang <address@hidden>
The patch is to fix the confusing assert fail message caused by
un-initialized device structure (from bite sized tasks).
The bug can be reproduced by
./qemu-system-x86_64 -nographic -device cfi.pflash01
The CFI hardware is dynamically loaded by QOM realizing mechanism,
however the realizing function in pflash_cfi01_realize function
requires the device being initialized manually before calling, like
./qemu-system-x86_64 -nographic
-device cfi.pflash01,num-blocks=1024,sector-length=4096,name=testcard
Once the initializing parameters are left off in the command, it will
leave the device structure not initialized, which makes
pflash_cfi01_realize try to realize a zero-volume card, causing
/mnt/EXT_volume/projects/qemu/qemu-dev/exec.c:1378:
find_ram_offset: Assertion `size != 0\' failed.
Through my test, at least the flash device's block-number, sector-length
and its name is needed for pflash_cfi01_realize to behave correctly. So
I think the new asserts are needed to hint the QEMU user to specify
the device's parameters correctly.
Signed-off-by: Ziyue Yang <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Ziyue Yang <address@hidden>
---
hw/block/pflash_cfi01.c | 13 +++++++++++++
hw/block/pflash_cfi02.c | 13 +++++++++++++
2 files changed, 26 insertions(+)
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 62d7a56..5f0ee9d 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -707,6 +707,19 @@ static void pflash_cfi01_realize(DeviceState *dev, Error
**errp)
int num_devices;
Error *local_err = NULL;
+ if (pfl->sector_len == 0) {
+ error_setg(errp, "attribute \"sector-length\" not specified or zero.");
+ return;
+ }
+ if (pfl->nb_blocs == 0) {
+ error_setg(errp, "attribute \"num-blocks\" not specified or zero.");
+ return;
+ }
+ if (pfl->name == NULL) {
+ error_setg(errp, "attribute \"name\" not specified.");
+ return;
+ }
+
total_len = pfl->sector_len * pfl->nb_blocs;
/* These are only used to expose the parameters of each device
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 4f6105c..ef71322 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -600,6 +600,19 @@ static void pflash_cfi02_realize(DeviceState *dev, Error
**errp)
int ret;
Error *local_err = NULL;
+ if (pfl->sector_len == 0) {
+ error_setg(errp, "attribute \"sector-length\" not specified or zero.");
+ return;
+ }
+ if (pfl->nb_blocs == 0) {
+ error_setg(errp, "attribute \"num-blocks\" not specified or zero.");
+ return;
+ }
+ if (pfl->name == NULL) {
+ error_setg(errp, "attribute \"name\" not specified.");
+ return;
+ }
+
chip_len = pfl->sector_len * pfl->nb_blocs;
/* XXX: to be fixed */
#if 0
--
2.9.3
- [Qemu-devel] [PULL 09/25] virtio-scsi: introduce virtio_scsi_acquire/release, (continued)
- [Qemu-devel] [PULL 09/25] virtio-scsi: introduce virtio_scsi_acquire/release, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 10/25] qemu-timer: check active_timers outside lock/event, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 11/25] timer: fix misleading comment in timer.h, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 12/25] main-loop: update comment for qemu_mutex_lock/unlock_iothread, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 13/25] block: drop remaining legacy aio functions in comment, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 15/25] pc: make smbus configurable, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 17/25] pc: make pit configurable, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 14/25] target-i386: Add Intel SHA_NI instruction support., Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 16/25] pc: make sata configurable, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 19/25] multiboot: copy the cmdline verbatim, unescape module strings, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 20/25] hw/block/pflash_cfi*.c: fix confusing assert fail message,
Paolo Bonzini <=
- [Qemu-devel] [PULL 18/25] x86: Fix x86_64 'g' packet response to gdb from 32-bit mode., Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 21/25] scsi-disk: fix VERIFY for scsi-block, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 22/25] kvm: sync linux headers, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 24/25] target-i386: Fix eflags.TF/#DB handling of syscall/sysret insns, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 23/25] kvmclock: reduce kvmclock difference on migration, Paolo Bonzini, 2016/12/22
- [Qemu-devel] [PULL 25/25] x86: implement la57 paging mode, Paolo Bonzini, 2016/12/22
- Re: [Qemu-devel] [PULL 00/25] First round of misc patches for QEMU 2.9, no-reply, 2016/12/22
- Re: [Qemu-devel] [PULL 00/25] First round of misc patches for QEMU 2.9, Peter Maydell, 2016/12/23