Re: [PATCH v4 2/6] PCI: spacemit-k1: Add multiple PHY handles support

From: Alex Elder

Date: Fri Jul 10 2026 - 08:59:19 EST


On 7/9/26 2:16 AM, Andy Shevchenko wrote:
+ if (IS_ERR(k1->phy[i])) {
+ if (PTR_ERR(k1->phy[i]) == -ENODEV)
+ break;
+
+ return PTR_ERR(k1->phy[i]);
+ }
if (PTR_ERR(k1->phy[i]) == -ENODEV)
break;
if (IS_ERR(k1->phy[i]))
return PTR_ERR(k1->phy[i]);

I'm not sure this is a huge improvement. Checking IS_ERR()
before using PTR_ERR() is comforting (a little along the
lines of the other issue you mentioned--assigning a result
before checking for an error). Anyway, it's a little bit
of an ugly construct no matter how you do it. Here's another
possible way to do it.

k1->phy[i] = devm_of_phy_get_by_index(dev, node, i);
if (!IS_ERR(k1->phy[i]))
continue;

ret = PTR_ERR(k1->phy[i]);
if (ret == -ENODEV)
break;

return ret;

-Alex