aboutsummaryrefslogtreecommitdiff
path: root/hw/block/pflash_cfi02.c
diff options
context:
space:
mode:
authorBernhard Beschow <shentey@gmail.com>2022-10-18 23:01:41 +0200
committerDaniel Henrique Barboza <danielhb413@gmail.com>2022-10-28 13:26:20 -0300
commit334c388f25707a234c4a0dea05b9df08d7746638 (patch)
treed2867aba34227a42bf102e5e52fc8d7662ed3154 /hw/block/pflash_cfi02.c
parentc593d1cc2555c5fe6a6a558f4d2bdc3bfd6713de (diff)
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);