mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: "Habil Eren Türker" <habilerenturker@hotmail.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86/quirks: Cast PCI_D0 to u16 in apple_airport_reset()
Date: Wed, 18 Nov 2026 12:14:08 -0600	[thread overview]
Message-ID: <20261118181408.GA625801@bhelgaas> (raw)
In-Reply-To: <20261118161559.63617-1-habilerenturker@hotmail.com>

[+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
> 

      reply	other threads:[~2026-11-18 18:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 16:16 Habil Eren Türker
2026-11-18 18:14 ` Bjorn Helgaas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118181408.GA625801@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=habilerenturker@hotmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®