[RESEND PATCH 00/16] PCI: Use FIELD_MODIFY() to simplify bitfield operations

Hans Zhang posted 16 patches 1 month, 2 weeks ago
drivers/pci/controller/dwc/pcie-al.c          | 12 ++----
.../controller/dwc/pcie-designware-debugfs.c  | 23 ++++-------
.../pci/controller/dwc/pcie-designware-ep.c   |  3 +-
drivers/pci/controller/dwc/pcie-designware.c  |  3 +-
drivers/pci/controller/dwc/pcie-eswin.c       |  3 +-
drivers/pci/controller/dwc/pcie-nxp-s32g.c    |  3 +-
drivers/pci/controller/dwc/pcie-qcom-common.c | 40 +++++++------------
drivers/pci/controller/dwc/pcie-qcom-ep.c     |  6 +--
drivers/pci/controller/dwc/pcie-tegra194.c    |  8 ++--
drivers/pci/controller/pci-mvebu.c            |  3 +-
drivers/pci/controller/pcie-mediatek-gen3.c   |  3 +-
drivers/pci/ide.c                             |  6 +--
drivers/pci/iov.c                             |  3 +-
drivers/pci/msi/msi.c                         | 11 ++---
drivers/pci/pci.c                             |  3 +-
drivers/pci/pcie/ptm.c                        |  3 +-
drivers/pci/rebar.c                           |  6 +--
drivers/pci/setup-cardbus.c                   |  3 +-
drivers/pci/tph.c                             | 10 ++---
19 files changed, 51 insertions(+), 101 deletions(-)
[RESEND PATCH 00/16] PCI: Use FIELD_MODIFY() to simplify bitfield operations
Posted by Hans Zhang 1 month, 2 weeks ago
Replace open-coded bitmask clear + FIELD_PREP() sequences with the
dedicated FIELD_MODIFY() macro.  FIELD_MODIFY() performs the same
operation but is shorter, less error-prone, and includes compile-time
checks to prevent field overflow.

This series touches the PCI core, PCIe extended capabilities (PTM, IDE,
TPH, MSI, REBAR, IOV, CardBus), and several DesignWare-based and
other PCI host controllers.  No functional change is intended.

The patches are split per subsystem or per driver to ease review:
---
Hi, If the Maintainers think it's not necessary, please ignore it.
---

Hans Zhang (16):
  PCI: Use FIELD_MODIFY()
  PCI/PTM: Use FIELD_MODIFY()
  PCI/IDE: Use FIELD_MODIFY()
  PCI/IOV: Use FIELD_MODIFY()
  PCI/TPH: Use FIELD_MODIFY()
  PCI/MSI: Use FIELD_MODIFY()
  PCI/REBAR: Use FIELD_MODIFY()
  PCI/CARDBUS: Use FIELD_MODIFY()
  PCI: al: Use FIELD_MODIFY()
  PCI: eswin: Use FIELD_MODIFY()
  PCI: s32g: Use FIELD_MODIFY()
  PCI: tegra194: Use FIELD_MODIFY()
  PCI: qcom: Use FIELD_MODIFY()
  PCI: dwc: Use FIELD_MODIFY()
  PCI: mvebu: Use FIELD_MODIFY()
  PCI: mediatek-gen3: Use FIELD_MODIFY()

 drivers/pci/controller/dwc/pcie-al.c          | 12 ++----
 .../controller/dwc/pcie-designware-debugfs.c  | 23 ++++-------
 .../pci/controller/dwc/pcie-designware-ep.c   |  3 +-
 drivers/pci/controller/dwc/pcie-designware.c  |  3 +-
 drivers/pci/controller/dwc/pcie-eswin.c       |  3 +-
 drivers/pci/controller/dwc/pcie-nxp-s32g.c    |  3 +-
 drivers/pci/controller/dwc/pcie-qcom-common.c | 40 +++++++------------
 drivers/pci/controller/dwc/pcie-qcom-ep.c     |  6 +--
 drivers/pci/controller/dwc/pcie-tegra194.c    |  8 ++--
 drivers/pci/controller/pci-mvebu.c            |  3 +-
 drivers/pci/controller/pcie-mediatek-gen3.c   |  3 +-
 drivers/pci/ide.c                             |  6 +--
 drivers/pci/iov.c                             |  3 +-
 drivers/pci/msi/msi.c                         | 11 ++---
 drivers/pci/pci.c                             |  3 +-
 drivers/pci/pcie/ptm.c                        |  3 +-
 drivers/pci/rebar.c                           |  6 +--
 drivers/pci/setup-cardbus.c                   |  3 +-
 drivers/pci/tph.c                             | 10 ++---
 19 files changed, 51 insertions(+), 101 deletions(-)


base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
-- 
2.34.1
Re: [RESEND PATCH 00/16] PCI: Use FIELD_MODIFY() to simplify bitfield operations
Posted by Bjorn Helgaas 1 month, 2 weeks ago
On Fri, May 01, 2026 at 12:24:04AM +0800, Hans Zhang wrote:
> Replace open-coded bitmask clear + FIELD_PREP() sequences with the
> dedicated FIELD_MODIFY() macro.  FIELD_MODIFY() performs the same
> operation but is shorter, less error-prone, and includes compile-time
> checks to prevent field overflow.
> 
> This series touches the PCI core, PCIe extended capabilities (PTM, IDE,
> TPH, MSI, REBAR, IOV, CardBus), and several DesignWare-based and
> other PCI host controllers.  No functional change is intended.
> 
> The patches are split per subsystem or per driver to ease review:

A "resend" implies that this is the same series as posted earlier but
forgotten for some reason.  But the original was only twelve minutes
earlier, and this adds more instances.  This should be a "v2" with a
note about what changed from the original posting.  In any event, I'll
ignore the original posting in favor of this one.

Looks like a good candidate for coccinelle.

> Hans Zhang (16):
>   PCI: Use FIELD_MODIFY()
>   PCI/PTM: Use FIELD_MODIFY()
>   PCI/IDE: Use FIELD_MODIFY()
>   PCI/IOV: Use FIELD_MODIFY()
>   PCI/TPH: Use FIELD_MODIFY()
>   PCI/MSI: Use FIELD_MODIFY()
>   PCI/REBAR: Use FIELD_MODIFY()
>   PCI/CARDBUS: Use FIELD_MODIFY()
>   PCI: al: Use FIELD_MODIFY()
>   PCI: eswin: Use FIELD_MODIFY()
>   PCI: s32g: Use FIELD_MODIFY()
>   PCI: tegra194: Use FIELD_MODIFY()
>   PCI: qcom: Use FIELD_MODIFY()
>   PCI: dwc: Use FIELD_MODIFY()
>   PCI: mvebu: Use FIELD_MODIFY()
>   PCI: mediatek-gen3: Use FIELD_MODIFY()
> 
>  drivers/pci/controller/dwc/pcie-al.c          | 12 ++----
>  .../controller/dwc/pcie-designware-debugfs.c  | 23 ++++-------
>  .../pci/controller/dwc/pcie-designware-ep.c   |  3 +-
>  drivers/pci/controller/dwc/pcie-designware.c  |  3 +-
>  drivers/pci/controller/dwc/pcie-eswin.c       |  3 +-
>  drivers/pci/controller/dwc/pcie-nxp-s32g.c    |  3 +-
>  drivers/pci/controller/dwc/pcie-qcom-common.c | 40 +++++++------------
>  drivers/pci/controller/dwc/pcie-qcom-ep.c     |  6 +--
>  drivers/pci/controller/dwc/pcie-tegra194.c    |  8 ++--
>  drivers/pci/controller/pci-mvebu.c            |  3 +-
>  drivers/pci/controller/pcie-mediatek-gen3.c   |  3 +-
>  drivers/pci/ide.c                             |  6 +--
>  drivers/pci/iov.c                             |  3 +-
>  drivers/pci/msi/msi.c                         | 11 ++---
>  drivers/pci/pci.c                             |  3 +-
>  drivers/pci/pcie/ptm.c                        |  3 +-
>  drivers/pci/rebar.c                           |  6 +--
>  drivers/pci/setup-cardbus.c                   |  3 +-
>  drivers/pci/tph.c                             | 10 ++---
>  19 files changed, 51 insertions(+), 101 deletions(-)
> 
> 
> base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
> -- 
> 2.34.1
>
Re: [RESEND PATCH 00/16] PCI: Use FIELD_MODIFY() to simplify bitfield operations
Posted by Hans Zhang 1 month, 2 weeks ago

On 5/1/26 02:08, Bjorn Helgaas wrote:
> On Fri, May 01, 2026 at 12:24:04AM +0800, Hans Zhang wrote:
>> Replace open-coded bitmask clear + FIELD_PREP() sequences with the
>> dedicated FIELD_MODIFY() macro.  FIELD_MODIFY() performs the same
>> operation but is shorter, less error-prone, and includes compile-time
>> checks to prevent field overflow.
>>
>> This series touches the PCI core, PCIe extended capabilities (PTM, IDE,
>> TPH, MSI, REBAR, IOV, CardBus), and several DesignWare-based and
>> other PCI host controllers.  No functional change is intended.
>>
>> The patches are split per subsystem or per driver to ease review:
> 
> A "resend" implies that this is the same series as posted earlier but
> forgotten for some reason.  But the original was only twelve minutes
> earlier, and this adds more instances.  This should be a "v2" with a
> note about what changed from the original posting.  In any event, I'll
> ignore the original posting in favor of this one.


Hi Bjorn,

Sorry.

Due to the fact that my development environment uses the 163 email 
service provided by China, the command "git send-email 
--no-chain-reply-to --quiet --to xxx --cc xxx" will not send the patches 
if there are more than 10 of them. Therefore, the following command 
needs to be executed: git send-email --no-chain-reply-to --quiet 
--batch-size=5 --relogin-delay=10 --to xxx --cc xxx. This way, you can 
send more than 10 patches. Next time, I will be more careful when 
sending and will also increment the version number.

Best regards,
Hans

> 
> Looks like a good candidate for coccinelle.
> 
>> Hans Zhang (16):
>>    PCI: Use FIELD_MODIFY()
>>    PCI/PTM: Use FIELD_MODIFY()
>>    PCI/IDE: Use FIELD_MODIFY()
>>    PCI/IOV: Use FIELD_MODIFY()
>>    PCI/TPH: Use FIELD_MODIFY()
>>    PCI/MSI: Use FIELD_MODIFY()
>>    PCI/REBAR: Use FIELD_MODIFY()
>>    PCI/CARDBUS: Use FIELD_MODIFY()
>>    PCI: al: Use FIELD_MODIFY()
>>    PCI: eswin: Use FIELD_MODIFY()
>>    PCI: s32g: Use FIELD_MODIFY()
>>    PCI: tegra194: Use FIELD_MODIFY()
>>    PCI: qcom: Use FIELD_MODIFY()
>>    PCI: dwc: Use FIELD_MODIFY()
>>    PCI: mvebu: Use FIELD_MODIFY()
>>    PCI: mediatek-gen3: Use FIELD_MODIFY()
>>
>>   drivers/pci/controller/dwc/pcie-al.c          | 12 ++----
>>   .../controller/dwc/pcie-designware-debugfs.c  | 23 ++++-------
>>   .../pci/controller/dwc/pcie-designware-ep.c   |  3 +-
>>   drivers/pci/controller/dwc/pcie-designware.c  |  3 +-
>>   drivers/pci/controller/dwc/pcie-eswin.c       |  3 +-
>>   drivers/pci/controller/dwc/pcie-nxp-s32g.c    |  3 +-
>>   drivers/pci/controller/dwc/pcie-qcom-common.c | 40 +++++++------------
>>   drivers/pci/controller/dwc/pcie-qcom-ep.c     |  6 +--
>>   drivers/pci/controller/dwc/pcie-tegra194.c    |  8 ++--
>>   drivers/pci/controller/pci-mvebu.c            |  3 +-
>>   drivers/pci/controller/pcie-mediatek-gen3.c   |  3 +-
>>   drivers/pci/ide.c                             |  6 +--
>>   drivers/pci/iov.c                             |  3 +-
>>   drivers/pci/msi/msi.c                         | 11 ++---
>>   drivers/pci/pci.c                             |  3 +-
>>   drivers/pci/pcie/ptm.c                        |  3 +-
>>   drivers/pci/rebar.c                           |  6 +--
>>   drivers/pci/setup-cardbus.c                   |  3 +-
>>   drivers/pci/tph.c                             | 10 ++---
>>   19 files changed, 51 insertions(+), 101 deletions(-)
>>
>>
>> base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b
>> -- 
>> 2.34.1
>>
Re: [RESEND PATCH 00/16] PCI: Use FIELD_MODIFY() to simplify bitfield operations
Posted by Bjorn Helgaas 1 month, 2 weeks ago
On Fri, May 01, 2026 at 12:24:04AM +0800, Hans Zhang wrote:
> Replace open-coded bitmask clear + FIELD_PREP() sequences with the
> dedicated FIELD_MODIFY() macro.  FIELD_MODIFY() performs the same
> operation but is shorter, less error-prone, and includes compile-time
> checks to prevent field overflow.
> 
> This series touches the PCI core, PCIe extended capabilities (PTM, IDE,
> TPH, MSI, REBAR, IOV, CardBus), and several DesignWare-based and
> other PCI host controllers.  No functional change is intended.
> 
> The patches are split per subsystem or per driver to ease review:
> ---
> Hi, If the Maintainers think it's not necessary, please ignore it.
> ---
> 
> Hans Zhang (16):
>   PCI: Use FIELD_MODIFY()
>   PCI/PTM: Use FIELD_MODIFY()
>   PCI/IDE: Use FIELD_MODIFY()
>   PCI/IOV: Use FIELD_MODIFY()
>   PCI/TPH: Use FIELD_MODIFY()
>   PCI/MSI: Use FIELD_MODIFY()
>   PCI/REBAR: Use FIELD_MODIFY()
>   PCI/CARDBUS: Use FIELD_MODIFY()
>   PCI: al: Use FIELD_MODIFY()
>   PCI: eswin: Use FIELD_MODIFY()
>   PCI: s32g: Use FIELD_MODIFY()
>   PCI: tegra194: Use FIELD_MODIFY()
>   PCI: qcom: Use FIELD_MODIFY()
>   PCI: dwc: Use FIELD_MODIFY()
>   PCI: mvebu: Use FIELD_MODIFY()
>   PCI: mediatek-gen3: Use FIELD_MODIFY()
> 
>  drivers/pci/controller/dwc/pcie-al.c          | 12 ++----
>  .../controller/dwc/pcie-designware-debugfs.c  | 23 ++++-------
>  .../pci/controller/dwc/pcie-designware-ep.c   |  3 +-
>  drivers/pci/controller/dwc/pcie-designware.c  |  3 +-
>  drivers/pci/controller/dwc/pcie-eswin.c       |  3 +-
>  drivers/pci/controller/dwc/pcie-nxp-s32g.c    |  3 +-
>  drivers/pci/controller/dwc/pcie-qcom-common.c | 40 +++++++------------
>  drivers/pci/controller/dwc/pcie-qcom-ep.c     |  6 +--
>  drivers/pci/controller/dwc/pcie-tegra194.c    |  8 ++--
>  drivers/pci/controller/pci-mvebu.c            |  3 +-
>  drivers/pci/controller/pcie-mediatek-gen3.c   |  3 +-
>  drivers/pci/ide.c                             |  6 +--
>  drivers/pci/iov.c                             |  3 +-
>  drivers/pci/msi/msi.c                         | 11 ++---
>  drivers/pci/pci.c                             |  3 +-
>  drivers/pci/pcie/ptm.c                        |  3 +-
>  drivers/pci/rebar.c                           |  6 +--
>  drivers/pci/setup-cardbus.c                   |  3 +-
>  drivers/pci/tph.c                             | 10 ++---
>  19 files changed, 51 insertions(+), 101 deletions(-)

I squashed these together since they're all doing exactly the same
thing and applied to pci/misc for v7.2, thanks!  I think this makes it
noticeably easier to read, especially in the cases where we update
several register fields at once.

Sashiko noticed the dev->sriov->barsz[] array bounds issue, which is
mostly addressed by another pending patch: https://patch.msgid.link/44a4ae53ec2825816b816c85cd378430d9a95cc6.1776429882.git.mnencia@kcore.it

Sashiko also flagged a potential pcie-mediatek-gen3.c issue related to
checking the return from pci_runtime_get_sync(), but that has nothing
to do with this patch, so I'll just forward that to the Mediatek
folks.

https://sashiko.dev/#/patchset/20260430162420.42839-1-18255117159%40163.com