From nobody Mon Nov 17 23:49:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606915246; cv=none; d=zohomail.com; s=zohoarc; b=EriRCewUjNEMtop0vPvZ0BdlHSDU5fMaiNwcsAnwnI5w414UJ9KZ65/JLFWqKp5wJFAIHD3O7/fedsJNmXdxzRYRaDQQ/+seGovEFDjJ9j2wOrRmQVmf13nEaQ3MzgE3V4tU/Ua34IDzyuvY5Gnmf9Ibc/IC8PxgQ+j8lC8Qsf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606915246; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=jh9TH7DrLfehy/SeQl5Z6oFCdoL+lKAc4y7mqOr0w7w=; b=UVi8Seh0o7ve1rD4LF4f4Ztj+eAb/No9b5hXHdBxEY5/NS1MoOHLghb83C+fCwKjrWEkOKW1lbGvCSyLqDTL2BT1evCTDJUkaib5kMmf9IpjQTe5CnY/F6N1Spvs4JCmtkcf2vlK92ekGzGtu0Uq9erIRax/vRStpdqJQ944yRM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606915246108814.3610789224368; Wed, 2 Dec 2020 05:20:46 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-91-S0aysCjRPS2JOLHB5IDszw-1; Wed, 02 Dec 2020 08:20:43 -0500 Received: by mail-wm1-f72.google.com with SMTP id u123so3868605wmu.5 for ; Wed, 02 Dec 2020 05:20:43 -0800 (PST) Return-Path: Return-Path: Received: from localhost.localdomain (111.red-88-21-205.staticip.rima-tde.net. [88.21.205.111]) by smtp.gmail.com with ESMTPSA id a15sm2098510wrn.75.2020.12.02.05.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 05:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606915245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jh9TH7DrLfehy/SeQl5Z6oFCdoL+lKAc4y7mqOr0w7w=; b=KnnOiiCzwpQPcGOlUcQtxCcsgfXHChZdJFpSosMmxScFPmSPeuVog/tGCChqnKoh3GFdQQ oEyGGzagW2xQJD5CEo491vnMUWP1F3SAHPiw0RldYnhhSYLEH2WKJTVHsSmQEEV/faSDZM PFkHePDpZ+rjdZKs7NuQNiZhGj3jGBs= X-MC-Unique: S0aysCjRPS2JOLHB5IDszw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jh9TH7DrLfehy/SeQl5Z6oFCdoL+lKAc4y7mqOr0w7w=; b=MZo1BLm82XojUryIViYuxtQZtwJzBbCRTjsifhyA4GY7TZrT0/WPxV4UCiQctaWaRB ANt8gBjeab+1tppEf1LdmsFp70YenxQrWIrI3NKzr9v3FlqCFl835/VITpnDKXt1Rjeg rDJpvy1Sp4fv7FR/okwYLclf2IQqeWLY7XT+7/RnlSnEHzZpZzrcOzml8epyOcFzop4N Ujh2omLHh7egcD/sM1QR+iXJH3qme5V5b6AOBFiGzqzOJaX1eqdvR4A/soxXbXrs8jfI A6w+/prDLLAZPIo/4DaSBuM/IubVudxRZgKz/H1r8l4W5JiohooJ12PTv8YMvwLjS8yc yKPQ== X-Gm-Message-State: AOAM532uBd3cgM4hHUEuuRXUcJzSbR5hTq0wSdm/4HxyonRbtI9ZRJCD EXndAj+Cx/GMy/YPE49enD+H+rC56Cb8b+Z05fu62tX+GuvERqGNhWJRE0bZVAXYY8RUHMzKCEy VJtmPKkjPXxlU6w== X-Received: by 2002:a7b:c00b:: with SMTP id c11mr3204079wmb.122.1606915241468; Wed, 02 Dec 2020 05:20:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq7TpvZh3YglVIJcfBh4bkbUOOV6dCzMRA3W9g6rGX5ipqxkboJjYY4rn2/kS+zgn3yDkSmQ== X-Received: by 2002:a7b:c00b:: with SMTP id c11mr3204063wmb.122.1606915241230; Wed, 02 Dec 2020 05:20:41 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum , qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH] hw/pci-host/pam: Replace magic number by PAM_REGIONS_COUNT definition Date: Wed, 2 Dec 2020 14:20:38 +0100 Message-Id: <20201202132038.1276404-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @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=C3=A9 Reviewed-by: Julia Suvorova --- include/hw/pci-host/i440fx.h | 2 +- include/hw/pci-host/pam.h | 2 ++ include/hw/pci-host/q35.h | 2 +- hw/pci-host/pam.c | 2 +- hw/pci-host/q35.c | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/hw/pci-host/i440fx.h b/include/hw/pci-host/i440fx.h index 6c16eaf876d..24fd53942ca 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 fec5cd35d60..c1fd06ba2ae 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 */ =20 +#define PAM_REGIONS_COUNT 13 + typedef struct PAMMemoryRegion { MemoryRegion alias[4]; /* index =3D PAM value */ unsigned current; diff --git a/include/hw/pci-host/q35.h b/include/hw/pci-host/q35.h index bbb95817656..ab989698ef8 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; diff --git a/hw/pci-host/pam.c b/hw/pci-host/pam.c index a4962057833..454dd120db9 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, =20 void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val) { - assert(0 <=3D idx && idx <=3D 12); + assert(0 <=3D idx && idx < PAM_REGIONS_COUNT); =20 memory_region_set_enabled(&pam->alias[pam->current], false); pam->current =3D (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK; diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index b67cb9c29f8..2eb729dff58 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 =3D 0; i < 12; ++i) { + for (i =3D 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); --=20 2.26.2