[PATCH v4 2/2] PCI: mediatek-gen3: Add support for restricting link width
AngeloGioacchino Del Regno
angelogioacchino.delregno at collabora.com
Wed Nov 6 05:29:29 PST 2024
Il 04/11/24 14:20, Krzysztof Wilczyński ha scritto:
>
> 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
Sorry I've just seen this email.
There's a problem here: this property has to be optional - and if you change that
to return like that, you're breaking compatibility with older device trees, which
are not specifying any "num-lanes" property.
Please remember that of_property_read_u32() returns:
- 0 on success
- -EINVAL if the property does not exist
- -ENODATA or -EOVERFLOW
Please either keep the error checking like I wrote, or alternatively you can do..
ret = of_property_read_u32(...)
if (ret != -EINVAL) {
dev_err(dev, "Failed to read num-lanes: %d\n", ret);
return ret;
} else {
if (num_lanes == 0 || ..... etc etc)
dev_warn()
else
pcie->num_lanes = num_lanes
}
Cheers,
Angelo
More information about the Linux-mediatek
mailing list