[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/19] hw/pci-host/pam: Replace magic number by PAM_REGIONS_COUNT
From: |
Laurent Vivier |
Subject: |
[PULL 05/19] hw/pci-host/pam: Replace magic number by PAM_REGIONS_COUNT definition |
Date: |
Mon, 14 Dec 2020 16:57:19 +0100 |
From: Philippe Mathieu-Daudé <philmd@redhat.com>
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é <philmd@redhat.com>
Reviewed-by: Julia Suvorova <jusual@redhat.com>
Message-Id: <20201202132038.1276404-1-philmd@redhat.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
hw/pci-host/pam.c | 2 +-
hw/pci-host/q35.c | 2 +-
include/hw/pci-host/i440fx.h | 2 +-
include/hw/pci-host/pam.h | 2 ++
include/hw/pci-host/q35.h | 2 +-
5 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/hw/pci-host/pam.c b/hw/pci-host/pam.c
index a4962057833f..454dd120db97 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 b67cb9c29f8e..2eb729dff585 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);
diff --git a/include/hw/pci-host/i440fx.h b/include/hw/pci-host/i440fx.h
index 6c16eaf876dd..24fd53942cab 100644
--- a/include/hw/pci-host/i440fx.h
+++ b/include/hw/pci-host/i440fx.h
@@ -29,7 +29,7 @@ struct PCII440FXState {
MemoryRegion *system_memory;
MemoryRegion *pci_address_space;
MemoryRegion *ram_memory;
- PAMMemoryRegion pam_regions[13];
+ PAMMemoryRegion pam_regions[PAM_REGIONS_COUNT];
MemoryRegion smram_region;
MemoryRegion smram, low_smram;
};
diff --git a/include/hw/pci-host/pam.h b/include/hw/pci-host/pam.h
index fec5cd35d60f..c1fd06ba2ae6 100644
--- a/include/hw/pci-host/pam.h
+++ b/include/hw/pci-host/pam.h
@@ -80,6 +80,8 @@
#define SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7)
#define SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */
+#define PAM_REGIONS_COUNT 13
+
typedef struct PAMMemoryRegion {
MemoryRegion alias[4]; /* index = PAM value */
unsigned current;
diff --git a/include/hw/pci-host/q35.h b/include/hw/pci-host/q35.h
index bbb958176565..ab989698ef8f 100644
--- a/include/hw/pci-host/q35.h
+++ b/include/hw/pci-host/q35.h
@@ -44,7 +44,7 @@ struct MCHPCIState {
MemoryRegion *pci_address_space;
MemoryRegion *system_memory;
MemoryRegion *address_space_io;
- PAMMemoryRegion pam_regions[13];
+ PAMMemoryRegion pam_regions[PAM_REGIONS_COUNT];
MemoryRegion smram_region, open_high_smram;
MemoryRegion smram, low_smram, high_smram;
MemoryRegion tseg_blackhole, tseg_window;
--
2.29.2
- [PULL 00/19] Trivial branch for 6.0 patches, Laurent Vivier, 2020/12/14
- [PULL 02/19] qemu-options.hx: Fix minor issues in icount documentation, Laurent Vivier, 2020/12/14
- [PULL 01/19] target/i386: tracing: format length values as hex, Laurent Vivier, 2020/12/14
- [PULL 15/19] configure / meson: Move check for pty.h to meson.build, Laurent Vivier, 2020/12/14
- [PULL 16/19] configure / meson: Move check for drm.h to meson.build, Laurent Vivier, 2020/12/14
- [PULL 03/19] MAINTAINERS: update my email address, Laurent Vivier, 2020/12/14
- [PULL 05/19] hw/pci-host/pam: Replace magic number by PAM_REGIONS_COUNT definition,
Laurent Vivier <=
- [PULL 10/19] elf2dmp/qemu_elf: Plug memleak in QEMU_Elf_init, Laurent Vivier, 2020/12/14
- [PULL 08/19] ads7846: moves from the hw/display folder to the hw/input folder., Laurent Vivier, 2020/12/14
- [PULL 07/19] CODING_STYLE.rst: Be less strict about 80 character limit, Laurent Vivier, 2020/12/14
- [PULL 04/19] hw/xen: Don't use '#' flag of printf format, Laurent Vivier, 2020/12/14
- [PULL 14/19] configure: Remove the obsolete check for ifaddrs.h, Laurent Vivier, 2020/12/14
- [PULL 09/19] configure: Test if $make actually exists, Laurent Vivier, 2020/12/14
- [PULL 17/19] configure / meson: Move check for sys/signal.h to meson.build, Laurent Vivier, 2020/12/14
- [PULL 18/19] configure / meson: Move check for sys/kcov.h to meson.build, Laurent Vivier, 2020/12/14
- [PULL 19/19] configure / meson: Move check for linux/btrfs.h to meson.build, Laurent Vivier, 2020/12/14
- [PULL 13/19] blockdev: Fix a memleak in drive_backup_prepare(), Laurent Vivier, 2020/12/14