summaryrefslogtreecommitdiffstats
path: root/hw/block/pflash_cfi02.c
diff options
context:
space:
mode:
authorBernhard Beschow2022-10-18 23:01:41 +0200
committerDaniel Henrique Barboza2022-10-28 18:26:20 +0200
commit334c388f25707a234c4a0dea05b9df08d7746638 (patch)
treed2867aba34227a42bf102e5e52fc8d7662ed3154 /hw/block/pflash_cfi02.c
parentdocs/system/ppc/ppce500: Use qemu-system-ppc64 across the board(s) (diff)
downloadqemu-334c388f25707a234c4a0dea05b9df08d7746638.tar.gz
qemu-334c388f25707a234c4a0dea05b9df08d7746638.tar.xz
qemu-334c388f25707a234c4a0dea05b9df08d7746638.zip
hw/block/pflash_cfi0{1, 2}: Error out if device length isn't a power of two
According to the JEDEC standard the device length is communicated to an OS as an exponent (power of two). Signed-off-by: Bernhard Beschow <shentey@gmail.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20221018210146.193159-3-shentey@gmail.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Diffstat (limited to 'hw/block/pflash_cfi02.c')
-rw-r--r--hw/block/pflash_cfi02.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 2a99b286b0..ff2fe154c1 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -880,6 +880,11 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp)
return;
}
+ if (!is_power_of_2(pfl->chip_len)) {
+ error_setg(errp, "Device size must be a power of two.");
+ return;
+ }
+
memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl),
&pflash_cfi02_ops, pfl, pfl->name,
pfl->chip_len, errp);