]> git.ipfire.org Git - thirdparty/linux.git/commit
PCI: Add pcie_get_link_speed() helper for safe array access
authorHans Zhang <18255117159@163.com>
Fri, 13 Mar 2026 16:55:18 +0000 (00:55 +0800)
committerManivannan Sadhasivam <mani@kernel.org>
Thu, 26 Mar 2026 18:30:08 +0000 (00:00 +0530)
commit28d20b0d895849ce3fe8c6f77baffc08886c2157
tree58f8480cf19b236ea70fc459d9bf0bd6b7cfcec6
parent6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
PCI: Add pcie_get_link_speed() helper for safe array access

The pcie_link_speed[] array is indexed by PCIe generation numbers
(1 = 2.5 GT/s, 2 = 5 GT/s, ...).  Several drivers use it directly,
which can lead to out-of-bounds accesses if an invalid generation
number is used.

Introduce a helper function pcie_get_link_speed() that returns the
pci_bus_speed value for a given generation number, or PCI_SPEED_UNKNOWN if
the generation is out of range.  This will allow us to safely handle
invalid values after the range check is removed from
of_pci_get_max_link_speed().

Signed-off-by: Hans Zhang <18255117159@163.com>
[mani: Fixed kernel-doc]
Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20260313165522.123518-2-18255117159@163.com
drivers/pci/pci.h
drivers/pci/probe.c