From f6a3c86ebd39aaedf1ebf89629ec91b5d44b670d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Wed, 2 Dec 2020 14:20:38 +0100 Subject: hw/pci-host/pam: Replace magic number by PAM_REGIONS_COUNT definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While this change helps triskaidekaphobic developers, it is a good practice to avoid magic values and using constant definitions instead. Introduce the PAM_REGIONS_COUNT and use it. No logical change. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Julia Suvorova Message-Id: <20201202132038.1276404-1-philmd@redhat.com> Signed-off-by: Laurent Vivier --- hw/pci-host/pam.c | 2 +- hw/pci-host/q35.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'hw/pci-host') diff --git a/hw/pci-host/pam.c b/hw/pci-host/pam.c index a496205783..454dd120db 100644 --- a/hw/pci-host/pam.c +++ b/hw/pci-host/pam.c @@ -62,7 +62,7 @@ void init_pam(DeviceState *dev, MemoryRegion *ram_memory, void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val) { - assert(0 <= idx && idx <= 12); + assert(0 <= idx && idx < PAM_REGIONS_COUNT); memory_region_set_enabled(&pam->alias[pam->current], false); pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK; diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index b67cb9c29f..2eb729dff5 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -641,7 +641,7 @@ static void mch_realize(PCIDevice *d, Error **errp) init_pam(DEVICE(mch), mch->ram_memory, mch->system_memory, mch->pci_address_space, &mch->pam_regions[0], PAM_BIOS_BASE, PAM_BIOS_SIZE); - for (i = 0; i < 12; ++i) { + for (i = 0; i < ARRAY_SIZE(mch->pam_regions) - 1; ++i) { init_pam(DEVICE(mch), mch->ram_memory, mch->system_memory, mch->pci_address_space, &mch->pam_regions[i+1], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); -- cgit v1.2.3