From: Inochi Amaoto <inochiama@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Inochi Amaoto <inochiama@gmail.com>
Cc: Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org,
Yixun Lan <dlan@gentoo.org>, Longbin Li <looong.bin@gmail.com>
Subject: Re: [PATCH 3/3] phy: core: Add phy bulk data helper functions
Date: Mon, 31 Aug 2026 18:00:32 +0800 [thread overview]
Message-ID: <apVOES6c42e_NBbe@inochi.infowork> (raw)
In-Reply-To: <apVJW6H8_y0uiVtj@ashevche-desk.local>
On Mon, Aug 31, 2026 at 12:28:59PM +0300, Andy Shevchenko wrote:
> On Mon, Aug 31, 2026 at 10:55:05AM +0800, Inochi Amaoto wrote:
> > Add several helper functions that allow drivers to get several phy
> > consumers in one operation. If any of the phy cannot be acquired then
> > any phys that were got will be put before returning to the caller.
> >
> > This can relieve the driver owners' life who needs to handle many phys,
> > as well as each phy error reporting.
>
> ...
>
> > +/**
> > + * of_phy_get_parent_count() - Get the number of phys of a device node
> > + * @np: device_node for which to get the phy
> > + *
> > + * Return: the phy count if successful, 0 if no phy handle is found,
> > + * negative error value if error occurs.
>
> Just for the reference, here is the correct format of the kernel-doc!
>
> > + */
> > +static int of_phy_get_parent_count(const struct device_node *np)
> > +{
> > + int count;
> > +
> > + count = of_count_phandle_with_args(np, "phys", "#phy-cells");
>
> > + if (count == -ENOENT)
> > + return 0;
>
> Why? And if so, the function perhaps needs to return unsigned type. Also
> kernel-doc says about negative error codes.
>
There is a special reason for -ENOENT is the of_count_phandle_with_args()
return -ENOENT if is can not find "phys" property. I think it is the case
that there is no phy required for this device. So I judge it and return
0. For other errors, they should not be translated so return them as they
are.
> > + return count;
> > +}
>
> ...
>
> > +void phy_bulk_put(struct device *dev, int num_phys, struct phy_bulk_data *phys)
> > +{
> > + if (!phys)
> > + return;
>
> > + while (--num_phys >= 0) {
>
> It's hard to follow.
>
> while (num_phys--) {
>
> will do the job. Ditto for other similar cases.
>
Thanks.
> > + if (phys[num_phys].phy)
> > + phy_put(dev, phys[num_phys].phy);
> > + phys[num_phys].phy = NULL;
> > + }
> > +}
>
> ...
>
> > +static int __phy_bulk_get(struct device *dev, int num_phys,
> > + struct phy_bulk_data *phys, bool optional)
> > +{
> > + int ret;
>
> > + int i;
>
> Do you expect num_phys to be negative?
>
> static int __phy_bulk_get(struct device *dev, unsigned int num_phys,
> ...
> unsigned int i;
>
> Same comment to the rest of the similar changes.
>
No, all should be postive, this is a mistake I have made, thanks
for pointing out.
> > +
> > + for (i = 0; i < num_phys; i++)
> > + phys[i].phy = NULL;
> > +
> > + for (i = 0; i < num_phys; i++) {
> > + phys[i].phy = phy_get(dev, phys[i].id);
>
> ret = PTR_ERR_OR_ZERO(...);
>
> > + if (IS_ERR(phys[i].phy)) {
>
> if (ret) {
>
> > + ret = PTR_ERR(phys[i].phy);
> > + phys[i].phy = NULL;
> > +
> > + if (ret == -ENODEV && optional)
> > + continue;
> > +
> > + dev_err_probe(dev, ret,
> > + "Failed to get phy: (%s)\n",
>
> There is room on the previous line.
>
> > + phys[i].id);
> > + goto err;
> > + }
> > + }
> > +
> > + return 0;
> > +
> > +err:
> > + phy_bulk_put(dev, i, phys);
> > +
> > + return ret;
> > +}
>
> ...
>
> > + * Return: %0 if successful, a negative error code otherwise
>
> Note, the reference to 0 is inconsistent with the previous changes.
> Make it there [of_phy_get_parent_count()] to follow.
>
Thanks for this information.
> ...
>
> > +static int of_phy_bulk_get_by_index(struct device_node *np, int num_phys,
> > + struct phy_bulk_data *phys)
> > +{
> > + int ret, i;
> > +
> > + for (i = 0; i < num_phys; i++) {
> > + phys[i].id = NULL;
> > + phys[i].phy = NULL;
> > + }
> > +
> > + for (i = 0; i < num_phys; i++) {
> > + of_property_read_string_index(np, "phy-names", i,
> > + &phys[i].id);
>
> The line limit is exactly 80, please fix your editor and double check that you
> use as much room as available (with the correction on the logical splits where
> it makes sense).
>
Yes, you are right, I misjudge this as my completion plugin output the
arguments name. I will change that.
> > +
> > + phys[i].phy = of_phy_get_by_index(np, i);
>
> ret = PTR_ERR_OR_ZERO(...);
>
> ?
>
Right, I missed this.
> > + if (IS_ERR(phys[i].phy)) {
> > + ret = PTR_ERR(phys[i].phy);
> > + phys[i].phy = NULL;
> > + goto err;
> > + }
> > + }
> > +
> > + return 0;
> > +
> > +err:
> > + of_phy_bulk_put(i, phys);
> > +
> > + return ret;
> > +}
>
> ...
>
> > +int of_phy_bulk_get_all(struct device_node *np, struct phy_bulk_data **phys)
> > +{
> > + struct phy_bulk_data *phy_bulk;
> > + int num_phys;
> > + int ret;
> > +
> > + *phys = NULL;
>
> > + if (!np)
> > + return 0;
>
> Dup check? The OF APIs are usually NULL-aware.
> Same Q to the ress of the code.
>
Thanks, I will remove them.
> > + num_phys = of_phy_get_parent_count(np);
> > + if (num_phys <= 0)
> > + return num_phys;
> > +
> > + phy_bulk = kmalloc_objs(*phy_bulk, num_phys);
> > + if (!phy_bulk)
> > + return -ENOMEM;
> > +
> > + ret = of_phy_bulk_get_by_index(np, num_phys, phy_bulk);
> > + if (ret) {
> > + kfree(phy_bulk);
> > + return ret;
> > + }
> > +
> > + *phys = phy_bulk;
> > +
> > + return num_phys;
> > +}
>
> ...
>
> > +struct phy_bulk_devres {
> > + struct phy_bulk_data *phys;
> > + int num_phys;
>
> Why signed?
>
My mistake. It always needs to be unsigned.
> > + bool free_phys;
> > +};
>
> ...
>
> I stopped here. It's too many stuff in a single patch. Please, split to two for
> a starter:
> - non-devm additions
> - devm coverage
>
Sorry for a bad time, I will do a better check and fix them. And I will split
the patch into two in the next version.
Regards,
Inochi
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-08-31 10:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 2:53 [PATCH 0/3] phy: core: Add phy bulk helpers support Inochi Amaoto
2026-08-31 2:55 ` [PATCH 1/3] phy: core: Add common helper to add phy phandle device link Inochi Amaoto
2026-08-31 2:55 ` [PATCH 2/3] phy: core: Add common helper for get phy phandle by index Inochi Amaoto
2026-08-31 3:03 ` sashiko-bot
2026-08-31 9:13 ` Andy Shevchenko
2026-08-31 9:48 ` Inochi Amaoto
2026-08-31 2:55 ` [PATCH 3/3] phy: core: Add phy bulk data helper functions Inochi Amaoto
2026-08-31 9:28 ` Andy Shevchenko
2026-08-31 10:00 ` Inochi Amaoto [this message]
2026-08-31 3:03 ` [PATCH 1/3] phy: core: Add common helper to add phy phandle device link sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=apVOES6c42e_NBbe@inochi.infowork \
--to=inochiama@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dlan@gentoo.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=looong.bin@gmail.com \
--cc=mani@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.