Re: [PATCH v7 1/2] PCI: of: Remove max-link-speed generation validation

From: Shawn Lin

Date: Sun Mar 08 2026 - 20:54:02 EST


在 2026/03/08 星期日 22:26, 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.

This change allows future PCIe generations to be supported without
modifying drivers/pci/of.c.

Signed-off-by: Hans Zhang <18255117159@xxxxxxx>
Acked-by: Manivannan Sadhasivam <mani@xxxxxxxxxx>
---
drivers/pci/of.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 9f8eb5df279e..cff5fd337c2b 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -889,10 +889,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;

Should update the comment of this function, as it states:
"-EINVAL - Invalid "max-link-speed" property value...
a negative value if the * required property is not found or is invalid."

So it won't validate the speed after this patch. Perhaps it's even
better to note the caller to take the responsiblity to validate it.

- 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;
}