* [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access
2026-03-12 16:36 [PATCH v8 0/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
@ 2026-03-12 16:36 ` Hans Zhang
2026-03-13 18:18 ` kernel test robot
2026-03-13 23:19 ` kernel test robot
2026-03-12 16:36 ` [PATCH v8 2/5] PCI: dwc: Use " Hans Zhang
` (3 subsequent siblings)
4 siblings, 2 replies; 11+ messages in thread
From: Hans Zhang @ 2026-03-12 16:36 UTC (permalink / raw)
To: lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas, helgaas,
florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel,
Hans Zhang
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
corresponding enum 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>
---
drivers/pci/pci.h | 2 ++
drivers/pci/probe.c | 16 ++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 13d998fbacce..6bf3e59f42e5 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -108,6 +108,8 @@ struct pcie_tlp_log;
PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE)
extern const unsigned char pcie_link_speed[];
+unsigned char pcie_get_link_speed(int speed);
+
extern bool pci_early_dump;
extern struct mutex pci_rescan_remove_lock;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index bccc7a4bdd79..a95afbcee421 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -783,6 +783,22 @@ const unsigned char pcie_link_speed[] = {
};
EXPORT_SYMBOL_GPL(pcie_link_speed);
+/**
+ * pcie_link_speed_value - Get speed value from PCIe generation number
+ * @speed: PCIe speed (1-based: 1 = 2.5GT, 2 = 5GT, ...)
+ *
+ * Returns the speed value (e.g., PCIE_SPEED_2_5GT) if @speed is valid,
+ * otherwise returns PCI_SPEED_UNKNOWN.
+ */
+unsigned char pcie_get_link_speed(int speed)
+{
+ if (speed <= 0 || speed >= ARRAY_SIZE(pcie_link_speed))
+ return PCI_SPEED_UNKNOWN;
+
+ return pcie_link_speed[speed];
+}
+EXPORT_SYMBOL_GPL(pcie_get_link_speed);
+
const char *pci_speed_string(enum pci_bus_speed speed)
{
/* Indexed by the pci_bus_speed enum */
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access
2026-03-12 16:36 ` [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access Hans Zhang
@ 2026-03-13 18:18 ` kernel test robot
2026-03-13 23:19 ` kernel test robot
1 sibling, 0 replies; 11+ messages in thread
From: kernel test robot @ 2026-03-13 18:18 UTC (permalink / raw)
To: Hans Zhang, lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas,
helgaas, florian.fainelli, jim2101024
Cc: llvm, oe-kbuild-all, robh, ilpo.jarvinen, linux-arm-msm,
linux-arm-kernel, linux-renesas-soc, claudiu.beznea.uj,
linux-mediatek, linux-tegra, linux-omap, bcm-kernel-feedback-list,
linux-pci, linux-kernel, Hans Zhang
Hi Hans,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 80234b5ab240f52fa45d201e899e207b9265ef91]
url: https://github.com/intel-lab-lkp/linux/commits/Hans-Zhang/PCI-Add-pcie_get_link_speed-helper-for-safe-array-access/20260313-220734
base: 80234b5ab240f52fa45d201e899e207b9265ef91
patch link: https://lore.kernel.org/r/20260312163652.113228-2-18255117159%40163.com
patch subject: [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260313/202603131934.SHJnSGL9-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260313/202603131934.SHJnSGL9-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603131934.SHJnSGL9-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> Warning: drivers/pci/probe.c:793 expecting prototype for pcie_link_speed_value(). Prototype was for pcie_get_link_speed() instead
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access
2026-03-12 16:36 ` [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access Hans Zhang
2026-03-13 18:18 ` kernel test robot
@ 2026-03-13 23:19 ` kernel test robot
1 sibling, 0 replies; 11+ messages in thread
From: kernel test robot @ 2026-03-13 23:19 UTC (permalink / raw)
To: Hans Zhang, lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas,
helgaas, florian.fainelli, jim2101024
Cc: oe-kbuild-all, robh, ilpo.jarvinen, linux-arm-msm,
linux-arm-kernel, linux-renesas-soc, claudiu.beznea.uj,
linux-mediatek, linux-tegra, linux-omap, bcm-kernel-feedback-list,
linux-pci, linux-kernel, Hans Zhang
Hi Hans,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 80234b5ab240f52fa45d201e899e207b9265ef91]
url: https://github.com/intel-lab-lkp/linux/commits/Hans-Zhang/PCI-Add-pcie_get_link_speed-helper-for-safe-array-access/20260313-220734
base: 80234b5ab240f52fa45d201e899e207b9265ef91
patch link: https://lore.kernel.org/r/20260312163652.113228-2-18255117159%40163.com
patch subject: [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access
config: alpha-allnoconfig (https://download.01.org/0day-ci/archive/20260314/202603140748.u17h0ZM8-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260314/202603140748.u17h0ZM8-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603140748.u17h0ZM8-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> Warning: drivers/pci/probe.c:793 expecting prototype for pcie_link_speed_value(). Prototype was for pcie_get_link_speed() instead
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v8 2/5] PCI: dwc: Use pcie_get_link_speed() helper for safe array access
2026-03-12 16:36 [PATCH v8 0/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
2026-03-12 16:36 ` [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access Hans Zhang
@ 2026-03-12 16:36 ` Hans Zhang
2026-03-12 16:36 ` [PATCH v8 3/5] PCI: j721e: Validate max-link-speed from DT Hans Zhang
` (2 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Hans Zhang @ 2026-03-12 16:36 UTC (permalink / raw)
To: lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas, helgaas,
florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel,
Hans Zhang
Replace direct indexing of pcie_link_speed[] with the new helper
pcie_get_link_speed() in all DesignWare core and glue drivers. This
ensures that out-of-range generation numbers do not cause out-of-bounds
accesses when the helper returns PCI_SPEED_UNKNOWN, and prepares for
the removal of the range check in of_pci_get_max_link_speed().
The actual validation of the "max-link-speed" DT property (e.g., fallback
to a safe default and warning) is added in subsequent patches for each
driver that reads the property.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/dwc/pcie-designware-host.c | 2 +-
drivers/pci/controller/dwc/pcie-designware.c | 2 +-
drivers/pci/controller/dwc/pcie-qcom-common.c | 2 +-
drivers/pci/controller/dwc/pcie-qcom-ep.c | 4 ++--
drivers/pci/controller/dwc/pcie-qcom.c | 6 +++---
drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
6 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 6ae6189e9b8a..0e05c5280344 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -1081,7 +1081,7 @@ static void dw_pcie_program_presets(struct dw_pcie_rp *pp, enum pci_bus_speed sp
static void dw_pcie_config_presets(struct dw_pcie_rp *pp)
{
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
- enum pci_bus_speed speed = pcie_link_speed[pci->max_link_speed];
+ enum pci_bus_speed speed = pcie_get_link_speed(pci->max_link_speed);
/*
* Lane equalization settings need to be applied for all data rates the
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index 5741c09dde7f..06792ba92aa7 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -861,7 +861,7 @@ static void dw_pcie_link_set_max_speed(struct dw_pcie *pci)
ctrl2 = dw_pcie_readl_dbi(pci, offset + PCI_EXP_LNKCTL2);
ctrl2 &= ~PCI_EXP_LNKCTL2_TLS;
- switch (pcie_link_speed[pci->max_link_speed]) {
+ switch (pcie_get_link_speed(pci->max_link_speed)) {
case PCIE_SPEED_2_5GT:
link_speed = PCI_EXP_LNKCTL2_TLS_2_5GT;
break;
diff --git a/drivers/pci/controller/dwc/pcie-qcom-common.c b/drivers/pci/controller/dwc/pcie-qcom-common.c
index 01c5387e53bf..5aa73c628737 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-common.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-common.c
@@ -22,7 +22,7 @@ void qcom_pcie_common_set_equalization(struct dw_pcie *pci)
* applied.
*/
- for (speed = PCIE_SPEED_8_0GT; speed <= pcie_link_speed[pci->max_link_speed]; speed++) {
+ for (speed = PCIE_SPEED_8_0GT; speed <= pcie_get_link_speed(pci->max_link_speed); speed++) {
if (speed > PCIE_SPEED_32_0GT) {
dev_warn(dev, "Skipped equalization settings for unsupported data rate\n");
break;
diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index 18460f01b2c6..4b7184d4a6fa 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -152,7 +152,7 @@
#define WAKE_DELAY_US 2000 /* 2 ms */
#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
- Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
+ Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_get_link_speed(speed)))
#define to_pcie_ep(x) dev_get_drvdata((x)->dev)
@@ -531,7 +531,7 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci)
qcom_pcie_common_set_equalization(pci);
- if (pcie_link_speed[pci->max_link_speed] == PCIE_SPEED_16_0GT)
+ if (pcie_get_link_speed(pci->max_link_speed) == PCIE_SPEED_16_0GT)
qcom_pcie_common_set_16gt_lane_margining(pci);
/*
diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c
index 67a16af69ddc..5c7c105bb745 100644
--- a/drivers/pci/controller/dwc/pcie-qcom.c
+++ b/drivers/pci/controller/dwc/pcie-qcom.c
@@ -170,7 +170,7 @@
#define QCOM_PCIE_CRC8_POLYNOMIAL (BIT(2) | BIT(1) | BIT(0))
#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
- Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
+ Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_get_link_speed(speed)))
struct qcom_pcie_resources_1_0_0 {
struct clk_bulk_data *clks;
@@ -320,7 +320,7 @@ static int qcom_pcie_start_link(struct dw_pcie *pci)
qcom_pcie_common_set_equalization(pci);
- if (pcie_link_speed[pci->max_link_speed] == PCIE_SPEED_16_0GT)
+ if (pcie_get_link_speed(pci->max_link_speed) == PCIE_SPEED_16_0GT)
qcom_pcie_common_set_16gt_lane_margining(pci);
/* Enable Link Training state machine */
@@ -1579,7 +1579,7 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
ret);
}
} else if (pcie->use_pm_opp) {
- freq_mbps = pcie_dev_speed_mbps(pcie_link_speed[speed]);
+ freq_mbps = pcie_dev_speed_mbps(pcie_get_link_speed(speed));
if (freq_mbps < 0)
return;
diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index 06571d806ab3..47f08adfbd79 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -310,7 +310,7 @@ static void tegra_pcie_icc_set(struct tegra_pcie_dw *pcie)
speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
- val = width * PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]);
+ val = width * PCIE_SPEED2MBS_ENC(pcie_get_link_speed(speed));
if (icc_set_bw(pcie->icc_path, Mbps_to_icc(val), 0))
dev_err(pcie->dev, "can't set bw[%u]\n", val);
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v8 3/5] PCI: j721e: Validate max-link-speed from DT
2026-03-12 16:36 [PATCH v8 0/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
2026-03-12 16:36 ` [PATCH v8 1/5] PCI: Add pcie_get_link_speed() helper for safe array access Hans Zhang
2026-03-12 16:36 ` [PATCH v8 2/5] PCI: dwc: Use " Hans Zhang
@ 2026-03-12 16:36 ` Hans Zhang
2026-03-12 16:36 ` [PATCH v8 4/5] PCI: controller: Validate max-link-speed Hans Zhang
2026-03-12 16:36 ` [PATCH v8 5/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
4 siblings, 0 replies; 11+ messages in thread
From: Hans Zhang @ 2026-03-12 16:36 UTC (permalink / raw)
To: lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas, helgaas,
florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel,
Hans Zhang
Use the new pcie_get_link_speed() helper to validate the value read from
the "max-link-speed" DT property. If the value is missing or invalid,
fall back to Gen2 (speed = 2). This prepares for the removal of the
range check in of_pci_get_max_link_speed().
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/cadence/pci-j721e.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c
index 6f2501479c70..bfdfe98d5aba 100644
--- a/drivers/pci/controller/cadence/pci-j721e.c
+++ b/drivers/pci/controller/cadence/pci-j721e.c
@@ -202,7 +202,8 @@ static int j721e_pcie_set_link_speed(struct j721e_pcie *pcie,
int ret;
link_speed = of_pci_get_max_link_speed(np);
- if (link_speed < 2)
+ if ((link_speed < 2) ||
+ (pcie_get_link_speed(link_speed) == PCI_SPEED_UNKNOWN))
link_speed = 2;
val = link_speed - 1;
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v8 4/5] PCI: controller: Validate max-link-speed
2026-03-12 16:36 [PATCH v8 0/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
` (2 preceding siblings ...)
2026-03-12 16:36 ` [PATCH v8 3/5] PCI: j721e: Validate max-link-speed from DT Hans Zhang
@ 2026-03-12 16:36 ` Hans Zhang
2026-03-12 17:06 ` Florian Fainelli
2026-03-12 16:36 ` [PATCH v8 5/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
4 siblings, 1 reply; 11+ messages in thread
From: Hans Zhang @ 2026-03-12 16:36 UTC (permalink / raw)
To: lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas, helgaas,
florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel,
Hans Zhang
Add validation for the "max-link-speed" DT property in three more
drivers, using the pcie_get_link_speed() helper.
- brcmstb: If the value is missing or invalid, fall back to no
limitation (pcie->gen = 0). Fix the previous incorrect logic.
- mediatek-gen3: If the value is missing or invalid, use the maximum
speed supported by the controller.
- rzg3s-host: If the value is missing or invalid, fall back to Gen2.
This ensures that all users of of_pci_get_max_link_speed() are ready
for the removal of the central range check.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/pcie-brcmstb.c | 5 +++--
drivers/pci/controller/pcie-mediatek-gen3.c | 2 +-
drivers/pci/controller/pcie-rzg3s-host.c | 2 +-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
index 062f55690012..714bcab97b60 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -1442,7 +1442,7 @@ static int brcm_pcie_start_link(struct brcm_pcie *pcie)
cls = FIELD_GET(PCI_EXP_LNKSTA_CLS, lnksta);
nlw = FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta);
dev_info(dev, "link up, %s x%u %s\n",
- pci_speed_string(pcie_link_speed[cls]), nlw,
+ pci_speed_string(pcie_get_link_speed(cls)), nlw,
ssc_good ? "(SSC)" : "(!SSC)");
return 0;
@@ -2072,7 +2072,8 @@ static int brcm_pcie_probe(struct platform_device *pdev)
return PTR_ERR(pcie->clk);
ret = of_pci_get_max_link_speed(np);
- pcie->gen = (ret < 0) ? 0 : ret;
+ if (pcie_get_link_speed(ret) == PCI_SPEED_UNKNOWN)
+ pcie->gen = 0;
pcie->ssc = of_property_read_bool(np, "brcm,enable-ssc");
diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
index 75ddb8bee168..3b903ef7d3cf 100644
--- a/drivers/pci/controller/pcie-mediatek-gen3.c
+++ b/drivers/pci/controller/pcie-mediatek-gen3.c
@@ -1150,7 +1150,7 @@ static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie)
return err;
err = of_pci_get_max_link_speed(pcie->dev->of_node);
- if (err) {
+ if (pcie_get_link_speed(err) != PCI_SPEED_UNKNOWN) {
/* Get the maximum speed supported by the controller */
max_speed = mtk_pcie_get_controller_max_link_speed(pcie);
diff --git a/drivers/pci/controller/pcie-rzg3s-host.c b/drivers/pci/controller/pcie-rzg3s-host.c
index 2809112e6317..00a11f986117 100644
--- a/drivers/pci/controller/pcie-rzg3s-host.c
+++ b/drivers/pci/controller/pcie-rzg3s-host.c
@@ -966,7 +966,7 @@ static int rzg3s_pcie_set_max_link_speed(struct rzg3s_pcie_host *host)
ls = readw_relaxed(host->pcie + pcie_cap + PCI_EXP_LNKSTA);
cs2 = readl_relaxed(host->axi + RZG3S_PCI_PCSTAT2);
- switch (pcie_link_speed[host->max_link_speed]) {
+ switch (pcie_get_link_speed(host->max_link_speed)) {
case PCIE_SPEED_5_0GT:
max_supported_link_speeds = GENMASK(PCI_EXP_LNKSTA_CLS_5_0GB - 1, 0);
link_speed = PCI_EXP_LNKCTL2_TLS_5_0GT;
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v8 4/5] PCI: controller: Validate max-link-speed
2026-03-12 16:36 ` [PATCH v8 4/5] PCI: controller: Validate max-link-speed Hans Zhang
@ 2026-03-12 17:06 ` Florian Fainelli
0 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2026-03-12 17:06 UTC (permalink / raw)
To: Hans Zhang, lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas,
helgaas, florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel
On 3/12/26 09:36, Hans Zhang wrote:
> Add validation for the "max-link-speed" DT property in three more
> drivers, using the pcie_get_link_speed() helper.
>
> - brcmstb: If the value is missing or invalid, fall back to no
> limitation (pcie->gen = 0). Fix the previous incorrect logic.
> - mediatek-gen3: If the value is missing or invalid, use the maximum
> speed supported by the controller.
> - rzg3s-host: If the value is missing or invalid, fall back to Gen2.
>
> This ensures that all users of of_pci_get_max_link_speed() are ready
> for the removal of the central range check.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/controller/pcie-brcmstb.c | 5 +++--
For pcie-brcmstb.c:
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v8 5/5] PCI: of: Remove max-link-speed generation validation
2026-03-12 16:36 [PATCH v8 0/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
` (3 preceding siblings ...)
2026-03-12 16:36 ` [PATCH v8 4/5] PCI: controller: Validate max-link-speed Hans Zhang
@ 2026-03-12 16:36 ` Hans Zhang
2026-03-13 7:04 ` Shawn Lin
4 siblings, 1 reply; 11+ messages in thread
From: Hans Zhang @ 2026-03-12 16:36 UTC (permalink / raw)
To: lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas, helgaas,
florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel,
Hans Zhang
The of_pci_get_max_link_speed() function currently validates the
"max-link-speed" DT property to be in the range 1..4 (Gen1..Gen4).
This imposes a maintenance burden because each new PCIe generation
would require updating this validation.
Remove the range check so the function returns the raw property value
(or a negative error code if the property is missing or malformed).
Callers must now validate the returned speed against the range they
support. A subsequent patch adds such validation to the DWC driver,
which is the primary user of this function.
Removing the validation from this common function allows future PCIe
generations to be supported without modifying drivers/pci/of.c.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/of.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 9f8eb5df279e..fbb779a94202 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -875,8 +875,9 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
* of_pci_get_max_link_speed - Find the maximum link speed of the given device node.
* @node: Device tree node with the maximum link speed information.
*
- * This function will try to find the limitation of link speed by finding
- * a property called "max-link-speed" of the given device node.
+ * This function will try to read the "max-link-speed" property of the given
+ * device tree node. It does NOT validate the value of the property (e.g.,
+ * range checks for PCIe generations).
*
* Return:
* * > 0 - On success, a maximum link speed.
@@ -889,10 +890,11 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
int of_pci_get_max_link_speed(struct device_node *node)
{
u32 max_link_speed;
+ int ret;
- if (of_property_read_u32(node, "max-link-speed", &max_link_speed) ||
- max_link_speed == 0 || max_link_speed > 4)
- return -EINVAL;
+ ret = of_property_read_u32(node, "max-link-speed", &max_link_speed);
+ if (ret)
+ return ret;
return max_link_speed;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v8 5/5] PCI: of: Remove max-link-speed generation validation
2026-03-12 16:36 ` [PATCH v8 5/5] PCI: of: Remove max-link-speed generation validation Hans Zhang
@ 2026-03-13 7:04 ` Shawn Lin
2026-03-13 16:55 ` Hans Zhang
0 siblings, 1 reply; 11+ messages in thread
From: Shawn Lin @ 2026-03-13 7:04 UTC (permalink / raw)
To: Hans Zhang, lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas,
helgaas, florian.fainelli, jim2101024
Cc: shawn.lin, robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel
Hi Hans
在 2026/03/13 星期五 0:36, Hans Zhang 写道:
> The of_pci_get_max_link_speed() function currently validates the
> "max-link-speed" DT property to be in the range 1..4 (Gen1..Gen4).
> This imposes a maintenance burden because each new PCIe generation
> would require updating this validation.
>
> Remove the range check so the function returns the raw property value
> (or a negative error code if the property is missing or malformed).
> Callers must now validate the returned speed against the range they
> support. A subsequent patch adds such validation to the DWC driver,
> which is the primary user of this function.
>
> Removing the validation from this common function allows future PCIe
> generations to be supported without modifying drivers/pci/of.c.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> ---
> drivers/pci/of.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 9f8eb5df279e..fbb779a94202 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -875,8 +875,9 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
> * of_pci_get_max_link_speed - Find the maximum link speed of the given device node.
> * @node: Device tree node with the maximum link speed information.
> *
> - * This function will try to find the limitation of link speed by finding
> - * a property called "max-link-speed" of the given device node.
> + * This function will try to read the "max-link-speed" property of the given
> + * device tree node. It does NOT validate the value of the property (e.g.,
> + * range checks for PCIe generations).
> *
> * Return:
> * * > 0 - On success, a maximum link speed.
Thanks for the patch. However, after applying it, I noticed this part
still seems off. There is a detailed comment in the file saying this
function checks if the max-link-speed is invalid, just a few lines below
your change. Could you please take another look at that comment and
adjust them?
> @@ -889,10 +890,11 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
> int of_pci_get_max_link_speed(struct device_node *node)
> {
> u32 max_link_speed;
> + int ret;
>
> - if (of_property_read_u32(node, "max-link-speed", &max_link_speed) ||
> - max_link_speed == 0 || max_link_speed > 4)
> - return -EINVAL;
> + ret = of_property_read_u32(node, "max-link-speed", &max_link_speed);
> + if (ret)
> + return ret;
>
> return max_link_speed;
> }
>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v8 5/5] PCI: of: Remove max-link-speed generation validation
2026-03-13 7:04 ` Shawn Lin
@ 2026-03-13 16:55 ` Hans Zhang
0 siblings, 0 replies; 11+ messages in thread
From: Hans Zhang @ 2026-03-13 16:55 UTC (permalink / raw)
To: Shawn Lin, lpieralisi, jingoohan1, mani, kwilczynski, bhelgaas,
helgaas, florian.fainelli, jim2101024
Cc: robh, ilpo.jarvinen, linux-arm-msm, linux-arm-kernel,
linux-renesas-soc, claudiu.beznea.uj, linux-mediatek, linux-tegra,
linux-omap, bcm-kernel-feedback-list, linux-pci, linux-kernel
On 2026/3/13 15:04, Shawn Lin wrote:
> Hi Hans
>
> 在 2026/03/13 星期五 0:36, Hans Zhang 写道:
>> The of_pci_get_max_link_speed() function currently validates the
>> "max-link-speed" DT property to be in the range 1..4 (Gen1..Gen4).
>> This imposes a maintenance burden because each new PCIe generation
>> would require updating this validation.
>>
>> Remove the range check so the function returns the raw property value
>> (or a negative error code if the property is missing or malformed).
>> Callers must now validate the returned speed against the range they
>> support. A subsequent patch adds such validation to the DWC driver,
>> which is the primary user of this function.
>>
>> Removing the validation from this common function allows future PCIe
>> generations to be supported without modifying drivers/pci/of.c.
>>
>> Signed-off-by: Hans Zhang <18255117159@163.com>
>> ---
>> drivers/pci/of.c | 12 +++++++-----
>> 1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
>> index 9f8eb5df279e..fbb779a94202 100644
>> --- a/drivers/pci/of.c
>> +++ b/drivers/pci/of.c
>> @@ -875,8 +875,9 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
>> * of_pci_get_max_link_speed - Find the maximum link speed of the
>> given device node.
>> * @node: Device tree node with the maximum link speed information.
>> *
>> - * This function will try to find the limitation of link speed by
>> finding
>> - * a property called "max-link-speed" of the given device node.
>> + * This function will try to read the "max-link-speed" property of
>> the given
>> + * device tree node. It does NOT validate the value of the property
>> (e.g.,
>> + * range checks for PCIe generations).
>> *
>> * Return:
>> * * > 0 - On success, a maximum link speed.
>
> Thanks for the patch. However, after applying it, I noticed this part
> still seems off. There is a detailed comment in the file saying this
> function checks if the max-link-speed is invalid, just a few lines below
> your change. Could you please take another look at that comment and
> adjust them?
Hi Shawn,
Thanks. Will change.
Best regards,
Hans
>
>> @@ -889,10 +890,11 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
>> int of_pci_get_max_link_speed(struct device_node *node)
>> {
>> u32 max_link_speed;
>> + int ret;
>> - if (of_property_read_u32(node, "max-link-speed", &max_link_speed) ||
>> - max_link_speed == 0 || max_link_speed > 4)
>> - return -EINVAL;
>> + ret = of_property_read_u32(node, "max-link-speed", &max_link_speed);
>> + if (ret)
>> + return ret;
>> return max_link_speed;
>> }
>>
^ permalink raw reply [flat|nested] 11+ messages in thread