diff mbox series

[02/10] PCI: Use FIELD_GET() in Sapphire RX 5600 XT Pulse quirk

Message ID 20231010204436.1000644-3-helgaas@kernel.org
State New
Headers show
Series PCI: Use FIELD_GET() and FIELD_PREP() | expand

Commit Message

Bjorn Helgaas Oct. 10, 2023, 8:44 p.m. UTC
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.

Separate because this isn't as trivial as the other FIELD_GET() changes.

See 907830b0fc9e ("PCI: Add a REBAR size quirk for Sapphire RX 5600 XT
Pulse")

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/pci/pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jonathan Cameron Oct. 11, 2023, 10:59 a.m. UTC | #1
On Tue, 10 Oct 2023 15:44:28 -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.
> 
> Separate because this isn't as trivial as the other FIELD_GET() changes.
> 
> See 907830b0fc9e ("PCI: Add a REBAR size quirk for Sapphire RX 5600 XT
> Pulse")
> 
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Nirmoy Das <nirmoy.das@amd.com>

Change would be a tiny bit more obvious without the early return, but I can see
why you think that is an improvement over relying on the return just below.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/pci/pci.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 848c9ee65d7f..5dc6e7cdfb71 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3751,14 +3751,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
>  		return 0;
>  
>  	pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap);
> -	cap &= PCI_REBAR_CAP_SIZES;
> +	cap = FIELD_GET(PCI_REBAR_CAP_SIZES, cap);
>  
>  	/* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */
>  	if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f &&
> -	    bar == 0 && cap == 0x7000)
> -		cap = 0x3f000;
> +	    bar == 0 && cap == 0x700)
> +		return 0x3f00;
>  
> -	return cap >> 4;
> +	return cap;
>  }
>  EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
>
Ilpo Järvinen Oct. 11, 2023, 11:31 a.m. UTC | #2
On Tue, 10 Oct 2023, Bjorn Helgaas 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.
> 
> Separate because this isn't as trivial as the other FIELD_GET() changes.
> 
> See 907830b0fc9e ("PCI: Add a REBAR size quirk for Sapphire RX 5600 XT
> Pulse")
> 
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Nirmoy Das <nirmoy.das@amd.com>
> ---
>  drivers/pci/pci.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 848c9ee65d7f..5dc6e7cdfb71 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -3751,14 +3751,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
>  		return 0;
>  
>  	pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap);
> -	cap &= PCI_REBAR_CAP_SIZES;
> +	cap = FIELD_GET(PCI_REBAR_CAP_SIZES, cap);
>  
>  	/* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */
>  	if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f &&
> -	    bar == 0 && cap == 0x7000)
> -		cap = 0x3f000;
> +	    bar == 0 && cap == 0x700)
> +		return 0x3f00;
>  
> -	return cap >> 4;
> +	return cap;
>  }
>  EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
>  
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 848c9ee65d7f..5dc6e7cdfb71 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3751,14 +3751,14 @@  u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
 		return 0;
 
 	pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap);
-	cap &= PCI_REBAR_CAP_SIZES;
+	cap = FIELD_GET(PCI_REBAR_CAP_SIZES, cap);
 
 	/* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */
 	if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f &&
-	    bar == 0 && cap == 0x7000)
-		cap = 0x3f000;
+	    bar == 0 && cap == 0x700)
+		return 0x3f00;
 
-	return cap >> 4;
+	return cap;
 }
 EXPORT_SYMBOL(pci_rebar_get_possible_sizes);