* [PATCH 1/1] PCI/bwctrl: Fix link speed return type
@ 2025-03-21 16:31 Ilpo Järvinen
2025-03-21 17:13 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Ilpo Järvinen @ 2025-03-21 16:31 UTC (permalink / raw)
To: Ilpo Järvinen, Bjorn Helgaas, Jonathan Cameron, linux-pci,
linux-kernel
pcie_bwctrl_select_speed() should take __fls() of the speed bit, not
return it as a raw value. Instead of directly returning 2.5GT/s speed
bit, simply assign the fallback speed (2.5GT/s) into supported_speeds
variable to share the normal return path that calls
pcie_supported_speeds2target_speed() to calculate __fls().
This code path is not very likely to execute because
pcie_get_supported_speeds() should provide valid ->supported_speeds but
a spec violating device could fail to synthetize any speed in
pcie_get_supported_speeds(). It could also happen in case the
supported_speeds intersection is empty (also a violation of the current
PCIe specs).
Fixes: de9a6c8d5dbf ("PCI/bwctrl: Add pcie_set_target_speed() to set PCIe Link Speed")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/pcie/bwctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/pcie/bwctrl.c b/drivers/pci/pcie/bwctrl.c
index 0a5e7efbce2c..58ba8142c9a3 100644
--- a/drivers/pci/pcie/bwctrl.c
+++ b/drivers/pci/pcie/bwctrl.c
@@ -113,7 +113,7 @@ static u16 pcie_bwctrl_select_speed(struct pci_dev *port, enum pci_bus_speed spe
up_read(&pci_bus_sem);
}
if (!supported_speeds)
- return PCI_EXP_LNKCAP2_SLS_2_5GB;
+ supported_speeds = PCI_EXP_LNKCAP2_SLS_2_5GB;
return pcie_supported_speeds2target_speed(supported_speeds & desired_speeds);
}
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 1/1] PCI/bwctrl: Fix link speed return type
2025-03-21 16:31 [PATCH 1/1] PCI/bwctrl: Fix link speed return type Ilpo Järvinen
@ 2025-03-21 17:13 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2025-03-21 17:13 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Bjorn Helgaas, Jonathan Cameron, linux-pci, linux-kernel
On Fri, Mar 21, 2025 at 06:31:03PM +0200, Ilpo Järvinen wrote:
> pcie_bwctrl_select_speed() should take __fls() of the speed bit, not
> return it as a raw value. Instead of directly returning 2.5GT/s speed
> bit, simply assign the fallback speed (2.5GT/s) into supported_speeds
> variable to share the normal return path that calls
> pcie_supported_speeds2target_speed() to calculate __fls().
>
> This code path is not very likely to execute because
> pcie_get_supported_speeds() should provide valid ->supported_speeds but
> a spec violating device could fail to synthetize any speed in
> pcie_get_supported_speeds(). It could also happen in case the
> supported_speeds intersection is empty (also a violation of the current
> PCIe specs).
>
> Fixes: de9a6c8d5dbf ("PCI/bwctrl: Add pcie_set_target_speed() to set PCIe Link Speed")
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Applied to pci/bwctrl for v6.15, thanks!
> ---
> drivers/pci/pcie/bwctrl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pcie/bwctrl.c b/drivers/pci/pcie/bwctrl.c
> index 0a5e7efbce2c..58ba8142c9a3 100644
> --- a/drivers/pci/pcie/bwctrl.c
> +++ b/drivers/pci/pcie/bwctrl.c
> @@ -113,7 +113,7 @@ static u16 pcie_bwctrl_select_speed(struct pci_dev *port, enum pci_bus_speed spe
> up_read(&pci_bus_sem);
> }
> if (!supported_speeds)
> - return PCI_EXP_LNKCAP2_SLS_2_5GB;
> + supported_speeds = PCI_EXP_LNKCAP2_SLS_2_5GB;
>
> return pcie_supported_speeds2target_speed(supported_speeds & desired_speeds);
> }
>
> base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-21 17:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-21 16:31 [PATCH 1/1] PCI/bwctrl: Fix link speed return type Ilpo Järvinen
2025-03-21 17:13 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox