Re: [PATCH 06/10] PCI/DPC: Use FIELD_GET()

Jonathan Cameron
2023-10-11T11:37:55Z

On Tue, 10 Oct 2023 15:44:32 -0500
Bjorn Helgaas <helgaas@kernel.org> wrote:

> From: Bjorn Helgaas <bhelgaas@google.com>
>
> Use FIELD_GET() to remove dependences on the field position, i.e., the
> shift value. No functional change intended.
>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
A question about what 'rules' you are applying for using these macros
vs choosing not not do so. Personally I prefer using them even for
flag fields mostly because it makes the code more consistent and
the compiler should remove any unnecessary shifts that result.

> ---

> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index eeec1d6f9023..a9fdc2e3f110 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -6154,7 +6154,7 @@ static void dpc_log_size(struct pci_dev *dev)
> if (!(val & PCI_EXP_DPC_CAP_RP_EXT))

This is what I'm commenting on below.

> return;
>
> - if (!((val & PCI_EXP_DPC_RP_PIO_LOG_SIZE) >> 8)) {
> + if (FIELD_GET(PCI_EXP_DPC_RP_PIO_LOG_SIZE, val) == 0) {

Why do this one and not the one just above?
In both cases extracting a field then comparing it to 0, I'm not sure
it makes sense to care if that field is 1 bit or multiple bit.

> pci_info(dev, "Overriding RP PIO Log Size to 4\n");
> dev->dpc_rp_log_size = 4;
> }