]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI/bwctrl: Fix pcie_bwctrl_select_speed() return type
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 21 Mar 2025 16:31:03 +0000 (18:31 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 21 Mar 2025 17:11:38 +0000 (12:11 -0500)
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 synthesize 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).

Link: https://lore.kernel.org/r/20250321163103.5145-1-ilpo.jarvinen@linux.intel.com
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>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pcie/bwctrl.c

index 0a5e7efbce2ccafb67b8a8e7a67e5d5623663208..58ba8142c9a31f1eb0e94223be93dccb79272e7e 100644 (file)
@@ -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);
 }