[PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node()
Bryan O'Donoghue
bryan.odonoghue at linaro.org
Tue Jul 28 03:51:31 PDT 2026
On 28/07/2026 11:46, Dmitry Baryshkov wrote:
> On Tue, Jul 28, 2026 at 10:35:33AM +0100, Bryan O'Donoghue wrote:
>> Add a devm variant of phy_get_by_of_node() to allow for the familiar
>> pattern of having devres automatically release resources on the driver's
>> exit path.
>>
>> Signed-off-by: Bryan O'Donoghue<bryan.odonoghue at linaro.org>
>> ---
>> drivers/phy/phy-core.c | 34 ++++++++++++++++++++++++++++++++++
>> include/linux/phy/phy.h | 7 +++++++
>> 2 files changed, 41 insertions(+)
>>
>> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
>> index ebfad5325072e..7af24f2f4120f 100644
>> --- a/drivers/phy/phy-core.c
>> +++ b/drivers/phy/phy-core.c
>> @@ -1029,6 +1029,40 @@ struct phy *phy_get_by_of_node(struct device_node *np)
>> }
>> EXPORT_SYMBOL_GPL(phy_get_by_of_node);
>>
>> +/**
>> + * devm_phy_get_by_of_node() - devm managed lookup and obtain phy reference by device node
>> + * @dev: device requesting the PHY
>> + * @np: device_node of the PHY provider
>> + *
>> + * Returns phy associated with the device_node or ERR_PTR. devres manages
>> + * releasing resources.
>> + */
>> +struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np)
>> +{
>> + struct phy **ptr, *phy;
>> + struct device_link *link;
>> +
>> + ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
>> + if (!ptr)
>> + return ERR_PTR(-ENOMEM);
>> +
>> + phy = phy_get_by_of_node(np);
>> + if (IS_ERR(phy)) {
>> + devres_free(ptr);
>> + return phy;
>> + }
>> +
>> + *ptr = phy;
>> + devres_add(dev, ptr);
>> + link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
> Why are you adding devlink here?
Looking at 987351e1ea77 ("phy: core: Add consumer device link support")
- adds this link to
phy_get()/devm_of_phy_get()/devm_of_phy_get_by_index() to enforce
suspend/resume ordering between PHY consumer and provider.
So the get_by_of_node() replicates that logic.
---
bod
More information about the linux-phy
mailing list