Re: [PATCH v4 2/6] PCI: spacemit-k1: Add multiple PHY handles support
From: Andy Shevchenko
Date: Sat Jul 11 2026 - 09:04:33 EST
On Fri, Jul 10, 2026 at 07:51:05AM -0500, Alex Elder wrote:
> 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.
Yeah...
> 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;
In this case one can simplify to
k1->phy[i] = devm_of_phy_get_by_index(dev, node, i);
ret = PTR_ERR_OR_ZERO(k1->phy[i]);
if (ret == -ENODEV)
break;
else if (ret)
return ret;
--
With Best Regards,
Andy Shevchenko