Re: [PATCH 06/10] PCI/DPC: Use FIELD_GET()
From: Ilpo Järvinen
Date: Wed Oct 11 2023 - 07:14:19 EST
On Wed, 11 Oct 2023, Jonathan Cameron wrote:
> On Tue, 10 Oct 2023 15:44:32 -0500
> Bjorn Helgaas <helgaas@xxxxxxxxxx> wrote:
>
> > From: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> >
> > 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@xxxxxxxxxx>
> 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.
I cannot speak for Bjorn but at least I've left flag checks untouched
(but when pulling the flag into a variable, I've made it with FIELD_GET()).
In anycase, that seems minor issue though compared with defined values of
the field being incompatible with the FIELD_GET()ed value (when the shift
is non-zero). I wish there would be good solution to that but so far I've
not come up anything that would be short and simple enough.
--
i.