qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org, Bernhard Beschow <shentey@gmail.com>
Cc: "Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	qemu-ppc@nongnu.org, "Bin Meng" <bin.meng@windriver.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	qemu-block@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Bin Meng" <bmeng.cn@gmail.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH v5 3/6] hw/block/pflash_cfi0{1, 2}: Error out if device length isn't a power of two
Date: Mon, 31 Oct 2022 12:53:59 +0100	[thread overview]
Message-ID: <20221031115402.91912-4-philmd@linaro.org> (raw)
In-Reply-To: <20221031115402.91912-1-philmd@linaro.org>

From: Bernhard Beschow <shentey@gmail.com>

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: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/block/pflash_cfi01.c | 8 ++++++--
 hw/block/pflash_cfi02.c | 5 +++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 0cbc2fb4cb..9c235bf66e 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -690,7 +690,7 @@ static const MemoryRegionOps pflash_cfi01_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl)
+static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl, Error **errp)
 {
     uint64_t blocks_per_device, sector_len_per_device, device_len;
     int num_devices;
@@ -708,6 +708,10 @@ static void pflash_cfi01_fill_cfi_table(PFlashCFI01 *pfl)
         sector_len_per_device = pfl->sector_len / num_devices;
     }
     device_len = sector_len_per_device * blocks_per_device;
+    if (!is_power_of_2(device_len)) {
+        error_setg(errp, "Device size must be a power of two.");
+        return;
+    }
 
     /* Hardcoded CFI table */
     /* Standard "QRY" string */
@@ -865,7 +869,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
      */
     pfl->cmd = 0x00;
     pfl->status = 0x80; /* WSM ready */
-    pflash_cfi01_fill_cfi_table(pfl);
+    pflash_cfi01_fill_cfi_table(pfl, errp);
 }
 
 static void pflash_cfi01_system_reset(DeviceState *dev)
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);
-- 
2.37.3



  parent reply	other threads:[~2022-10-31 11:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 11:53 [PATCH v5 0/6] ppc/e500: Add support for two types of flash, cleanup Philippe Mathieu-Daudé
2022-10-31 11:53 ` [PATCH v5 1/6] hw/sd/sdhci: MMIO region is implemented in 32-bit accesses Philippe Mathieu-Daudé
2022-11-01 22:32   ` Bernhard Beschow
2022-10-31 11:53 ` [RFC PATCH v5 2/6] hw/sd/sdhci: Map host controller interface in host endianess Philippe Mathieu-Daudé
2022-10-31 15:28   ` Philippe Mathieu-Daudé
2022-10-31 11:53 ` Philippe Mathieu-Daudé [this message]
2022-10-31 11:54 ` [PATCH v5 4/6] docs/system/ppc/ppce500: Use qemu-system-ppc64 across the board(s) Philippe Mathieu-Daudé
2022-10-31 11:54 ` [PATCH v5 5/6] hw/ppc/e500: Implement pflash handling Philippe Mathieu-Daudé
2022-10-31 11:54 ` [PATCH v5 6/6] hw/ppc/e500: Add Freescale eSDHC to e500plat Philippe Mathieu-Daudé
2022-10-31 15:12   ` Philippe Mathieu-Daudé
2022-10-31 15:19     ` Philippe Mathieu-Daudé
2022-11-01 10:37       ` Bernhard Beschow
2022-11-01 10:41 ` [PATCH v5 0/6] ppc/e500: Add support for two types of flash, cleanup Bernhard Beschow
2022-11-01 16:01   ` Bernhard Beschow
2022-11-01 16:58     ` Philippe Mathieu-Daudé
2022-11-01 17:43       ` Philippe Mathieu-Daudé
2022-11-01 17:56         ` Philippe Mathieu-Daudé
2022-11-01 19:37         ` B

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221031115402.91912-4-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=bin.meng@windriver.com \
    --cc=bmeng.cn@gmail.com \
    --cc=danielhb413@gmail.com \
    --cc=f4bug@amsat.org \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=shentey@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).