* [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()
@ 2026-11-18 16:16 Habil Eren Türker
2026-11-18 16:20 ` sashiko-bot
2026-11-18 18:14 ` Bjorn Helgaas
0 siblings, 2 replies; 3+ messages in thread
From: Habil Eren Türker @ 2026-11-18 16:16 UTC (permalink / raw)
To: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86@kernel.org
Cc: H . Peter Anvin, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, Habil Eren Türker
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.
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
arch/x86/kernel/early-quirks.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 6b6f32f40cbe..7459a073c74d 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -644,13 +644,13 @@ static void __init apple_airport_reset(int bus, int slot, int func)
/* Card may have been put into PCI_D3hot by grub quirk */
pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
- if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
+ if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
write_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL, pmcsr);
mdelay(10);
pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
- if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
+ if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
pr_err("pci 0000:%02x:%02x.%d: Cannot power up Apple AirPort card\n",
bus, slot, func);
return;
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()
2026-11-18 16:16 [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset() Habil Eren Türker
@ 2026-11-18 16:20 ` sashiko-bot
2026-11-18 18:14 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-18 16:20 UTC (permalink / raw)
To: Habil Eren Türker; +Cc: linux-pci@vger.kernel.org
> 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.
>
> Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118161559.63617-1-habilerenturker@hotmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()
2026-11-18 16:16 [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset() Habil Eren Türker
2026-11-18 16:20 ` sashiko-bot
@ 2026-11-18 18:14 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2026-11-18 18:14 UTC (permalink / raw)
To: Habil Eren Türker
Cc: Bjorn Helgaas, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86@kernel.org, H . Peter Anvin, Andy Shevchenko,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
[+cc Andy since he's fixed similar issues and may have better ideas]
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).
> Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
> ---
> arch/x86/kernel/early-quirks.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
> index 6b6f32f40cbe..7459a073c74d 100644
> --- a/arch/x86/kernel/early-quirks.c
> +++ b/arch/x86/kernel/early-quirks.c
> @@ -644,13 +644,13 @@ static void __init apple_airport_reset(int bus, int slot, int func)
> /* Card may have been put into PCI_D3hot by grub quirk */
> pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
>
> - if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
> + if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
> pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
> write_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL, pmcsr);
> mdelay(10);
>
> pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
> - if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
> + if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != (__force u16)PCI_D0) {
> pr_err("pci 0000:%02x:%02x.%d: Cannot power up Apple AirPort card\n",
> bus, slot, func);
> return;
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 18:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 16:16 [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset() Habil Eren Türker
2026-11-18 16:20 ` sashiko-bot
2026-11-18 18:14 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox