Re: [PATCH v4 2/2] PCI: mediatek-gen3: Add support for restricting link width

Krzysztof Wilczyński
2024-11-04T13:20:49Z

Hello,

> + ret = of_property_read_u32(dev->of_node, "num-lanes", &num_lanes);
> + if (ret == 0) {
> + if (num_lanes == 0 || num_lanes > 16 || (num_lanes != 1 && num_lanes % 2))
> + dev_warn(dev, "Invalid num-lanes, using controller defaults\n");
> + else
> + pcie->num_lanes = num_lanes;
> + }
> +
> return 0;
> }

If you were to handle non-zero return value as an error here, perhaps the
property has not been set, then we could reduce the indentation here.

Something like this, perhaps?

ret = of_property_read_u32(dev->of_node, "num-lanes", &num_lanes);
if (ret) {
dev_err(dev, "Failed to read num-lanes: %d\n", ret);
return ret;
}

if (!num_lanes || num_lanes > 16 || (num_lanes != 1 && num_lanes % 2))
dev_warn(dev, "Invalid num-lanes, using controller defaults\n");
else
pcie->num_lanes = num_lanes;

Does this make sense here? Thoughts?

Krzysztof