Re: [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()
From: Andy Shevchenko
Date: Thu Nov 19 2026 - 04:05:12 EST
On Wed, Nov 18, 2026 at 12:14:08PM -0600, Bjorn Helgaas wrote:
> [+cc Andy since he's fixed similar issues and may have better ideas]
Thanks! Yes, bitwise types in sparse are interesting thing, but since we want
to continue using them the easiest way out is to cast to pci_power_t.
> On Wed, Nov 18, 2026 at 04:16:03PM +0000, Habil Eren Türker wrote:
> > PCI_D0 is defined as pci_power_t, whereas pmcsr & PCI_PM_CTRL_STATE_MASK
> > evaluates to a u16 integer.
> >
> > This causes Sparse (make C=1) to report:
> > warning: restricted pci_power_t degrades to integer
> >
> > Add (__force u16) casts on PCI_D0 to explicitly eliminate warnings.
>
> We have a bunch of similar sparse warnings in drivers/pci, but I'm
> kind of hesitant to just throw in a cast at each one to avoid the
> warning.
>
> About a third of the sparse warnings related to pci_power_t are
> similar to this, where we're extracting the power state using
> PCI_PM_CTRL_STATE_MASK and assigning to a pci_power_t variable or
> comparing for equality with PCI_D0. I think we can fix these with an
> accessor something like this (better name ideas welcome):
>
> static inline pci_power_t pci_power_t_get(u32 csr)
> {
> return (pci_power_t __force) FIELD_GET(PCI_PM_CTRL_STATE_MASK, csr);
> }
>
> There are a few more we could fix with an analogous pci_power_t_set()
> or similar. Most of the rest are arithmetic comparisons (>, <, >=,
> etc).
So, we basically need only two (the rest can be derived with negation.
_eq() [equal to] and _gt() [great than]. It may lead to have code in
a better shape from readability point of view.
--
With Best Regards,
Andy Shevchenko