[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e2e41af9-ed09-4ac5-9481-e605d1340b3d@collabora.com>
Date: Wed, 6 Nov 2024 14:29:29 +0100
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
To: Krzysztof Wilczyński <kw@...ux.com>
Cc: linux-pci@...r.kernel.org, ryder.lee@...iatek.com,
jianjun.wang@...iatek.com, lpieralisi@...nel.org, robh@...nel.org,
bhelgaas@...gle.com, matthias.bgg@...il.com,
linux-mediatek@...ts.infradead.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, kernel@...labora.com,
fshao@...omium.org, Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>
Subject: Re: [PATCH v4 2/2] PCI: mediatek-gen3: Add support for restricting
link width
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
Powered by blists - more mailing lists