From: Neil Armstrong <neil.armstrong@linaro.org>
To: johannes.goede@oss.qualcomm.com,
Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
Bjorn Andersson <andersson@kernel.org>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Robert Foss <rfoss@kernel.org>, Todor Tomov <todor.too@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>,
Bryan O'Donoghue <bod@kernel.org>,
Loic Poulain <loic.poulain@oss.qualcomm.com>,
Vinod Koul <vkoul@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Kishon Vijay Abraham I <kishon@kernel.org>,
Felipe Balbi <balbi@ti.com>,
Manivannan Sadhasivam <mani@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linux-phy@lists.infradead.org,
Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: [PATCH v20 2/6] phy: core: Add phy_get_by_of_node()
Date: Tue, 22 Sep 2026 14:19:03 +0200 [thread overview]
Message-ID: <5cadf2e6-9dbb-4320-b866-cf2fad599c41@linaro.org> (raw)
In-Reply-To: <49c7b4d8-a8ec-44e1-ab06-220cf3698ea0@oss.qualcomm.com>
On 9/18/26 17:35, johannes.goede@oss.qualcomm.com wrote:
> Hi Neil,
>
> On 18-Sep-26 16:10, Neil Armstrong wrote:
>> On 9/18/26 15:56, Bryan O'Donoghue wrote:
>>> Add new function phy_get_by_of_node() allowing lookup of a phy by
>>> device_node. Separates existing logic in _of_phy_get() into an internal
>>> helper method _of_phy_get_with_args() to allow for reuse in new method.
>>>
>>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>>> ---
>>> drivers/phy/phy-core.c | 83 ++++++++++++++++++++++++++++++++++++++-----------
>>> include/linux/phy/phy.h | 6 ++++
>>> 2 files changed, 71 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
>>> index 89addd732bff3..42c27a2b45159 100644
>>> --- a/drivers/phy/phy-core.c
>>> +++ b/drivers/phy/phy-core.c
>>> @@ -606,6 +606,38 @@ int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
>>> }
>>> EXPORT_SYMBOL_GPL(phy_validate);
>>> +/**
>>> + * _of_phy_get_with_args() - lookup and obtain a reference to a phy by of_phandle_args
>>> + * @args: of_phandle_args to the phy
>>> + *
>>> + * Returns: the phy from the provider's of_xlate, -ENODEV if disabled,
>>> + * -EPROBE_DEFER if the provider is not yet registered.
>>> + */
>>> +static struct phy *_of_phy_get_with_args(struct of_phandle_args *args)
>>> +{
>>> + struct phy *phy;
>>> + struct phy_provider *phy_provider;
>>> +
>>> + lockdep_assert_held(&phy_provider_mutex);
>>> +
>>> + phy_provider = of_phy_provider_lookup(args->np);
>>> + if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner))
>>> + return ERR_PTR(-EPROBE_DEFER);
>>> +
>>> + if (!of_device_is_available(args->np)) {
>>> + dev_warn(phy_provider->dev, "Requested PHY is disabled\n");
>>> + phy = ERR_PTR(-ENODEV);
>>> + goto out_put_module;
>>> + }
>>> +
>>> + phy = phy_provider->of_xlate(phy_provider->dev, args);
>>> +
>>> +out_put_module:
>>> + module_put(phy_provider->owner);
>>> +
>>> + return phy;
>>> +}
>>> +
>>> /**
>>> * _of_phy_get() - lookup and obtain a reference to a phy by phandle
>>> * @np: device_node for which to get the phy
>>> @@ -620,8 +652,7 @@ EXPORT_SYMBOL_GPL(phy_validate);
>>> static struct phy *_of_phy_get(struct device_node *np, int index)
>>> {
>>> int ret;
>>> - struct phy_provider *phy_provider;
>>> - struct phy *phy = NULL;
>>> + struct phy *phy;
>>> struct of_phandle_args args;
>>> lockdep_assert_held(&phy_provider_mutex);
>>> @@ -637,22 +668,7 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
>>> goto out_put_node;
>>> }
>>> - phy_provider = of_phy_provider_lookup(args.np);
>>> - if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) {
>>> - phy = ERR_PTR(-EPROBE_DEFER);
>>> - goto out_put_node;
>>> - }
>>> -
>>> - if (!of_device_is_available(args.np)) {
>>> - dev_warn(phy_provider->dev, "Requested PHY is disabled\n");
>>> - phy = ERR_PTR(-ENODEV);
>>> - goto out_put_module;
>>> - }
>>> -
>>> - phy = phy_provider->of_xlate(phy_provider->dev, &args);
>>> -
>>> -out_put_module:
>>> - module_put(phy_provider->owner);
>>> + phy = _of_phy_get_with_args(&args);
>>> out_put_node:
>>> of_node_put(args.np);
>>> @@ -1001,6 +1017,37 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
>>> }
>>> EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
>>> +/**
>>> + * phy_get_by_of_node() - lookup and obtain a reference to a phy by device_node
>>> + * @np: node containing the phy
>>> + *
>>> + * Returns: the phy associated with the device node or ERR_PTR.
>>> + */
>>> +struct phy *phy_get_by_of_node(struct device_node *np)
>>> +{
>>> + struct of_phandle_args args = { .np = np, .args_count = 0 };
>>> + struct phy *phy;
>>> +
>>> + mutex_lock(&phy_provider_mutex);
>>
>> I don't really understand the usage of lockdep_assert_held(), but why
>> does _of_phy_get() uses lockdep_assert_held() and here you use mutex_lock()
>> like before patch 1 ?
>
> Hi, not Bryan but I can answer this question.
>
> lockdep_assert_held() check that the mutex is lock and triggers
> a WARN() when not held.
>
> So lockdep_assert_held() is used in functions which expect to
> be called with the mutex already locked, like the new
> _of_phy_get_with_args() helper which is added here.
>
> This new helper factors out bits of _of_phy_get(), which itself
> already has lockdep_assert_held(), but since this new helper
> also is directly called from the new phy_get_by_of_node() it
> is good for it to also check the mutex is locked itself.
>
> And since the new phy_get_by_of_node() calls this new helper
> it must lock the mutex.
>
> Note that _of_phy_get() is already always called with the mutex
> locked from of_phy_get(), phy_get(), or devm_of_phy_get_by_index().
Ok thanks for the detailed explanation, I missed that !
Neil
>
> Regards,
>
> Hans
>
>
>
>
>>
>> Neil
>>
>>> +
>>> + phy = _of_phy_get_with_args(&args);
>>> + if (IS_ERR(phy))
>>> + goto out_unlock;
>>> +
>>> + if (!try_module_get(phy->ops->owner)) {
>>> + phy = ERR_PTR(-EPROBE_DEFER);
>>> + goto out_unlock;
>>> + }
>>> +
>>> + get_device(&phy->dev);
>>> +
>>> +out_unlock:
>>> + mutex_unlock(&phy_provider_mutex);
>>> +
>>> + return phy;
>>> +}
>>> +EXPORT_SYMBOL_GPL(phy_get_by_of_node);
>>> +
>>> /**
>>> * phy_create() - create a new phy
>>> * @dev: device that is creating the new phy
>>> diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
>>> index ea47975e288ae..71c2e16397130 100644
>>> --- a/include/linux/phy/phy.h
>>> +++ b/include/linux/phy/phy.h
>>> @@ -284,6 +284,7 @@ struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np,
>>> const char *con_id);
>>> struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
>>> int index);
>>> +struct phy *phy_get_by_of_node(struct device_node *np);
>>> void of_phy_put(struct phy *phy);
>>> void phy_put(struct device *dev, struct phy *phy);
>>> void devm_phy_put(struct device *dev, struct phy *phy);
>>> @@ -493,6 +494,11 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
>>> return ERR_PTR(-ENOSYS);
>>> }
>>> +static inline struct phy *phy_get_by_of_node(struct device_node *np)
>>> +{
>>> + return ERR_PTR(-ENOSYS);
>>> +}
>>> +
>>> static inline void of_phy_put(struct phy *phy)
>>> {
>>> }
>>>
>>
>>
>
next prev parent reply other threads:[~2026-09-22 12:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 13:56 [PATCH v20 0/6] Add phy_get_by_of_node and devm helper Bryan O'Donoghue
2026-09-18 13:56 ` [PATCH v20 1/6] phy: core: Fix race-condition between _of_phy_get() and try_module_get() Bryan O'Donoghue
2026-09-18 13:56 ` [PATCH v20 2/6] phy: core: Add phy_get_by_of_node() Bryan O'Donoghue
2026-09-18 14:10 ` Neil Armstrong
2026-09-18 14:27 ` Bryan O'Donoghue
2026-09-18 15:35 ` johannes.goede
2026-09-22 12:19 ` Neil Armstrong [this message]
2026-09-22 12:14 ` Neil Armstrong
2026-09-22 12:36 ` Manivannan Sadhasivam
2026-09-18 13:56 ` [PATCH v20 3/6] phy: core: Add devm_phy_get_by_of_node() Bryan O'Donoghue
2026-09-18 14:10 ` Neil Armstrong
2026-09-18 13:56 ` [PATCH v20 4/6] phy: core: Add missing kerneldoc colon in two locations Bryan O'Donoghue
2026-09-18 14:11 ` Neil Armstrong
2026-09-22 12:37 ` Manivannan Sadhasivam
2026-09-18 13:56 ` [PATCH v20 5/6] media: qcom: camss: Add support for PHY API devices Bryan O'Donoghue
2026-09-18 14:48 ` Loic Poulain
2026-09-22 9:15 ` Konrad Dybcio
2026-09-22 9:32 ` Bryan O'Donoghue
2026-09-25 16:40 ` Liviu Nicoara
2026-09-27 8:40 ` johannes.goede
2026-09-27 15:32 ` Liviu Nicoara
2026-09-18 13:56 ` [PATCH v20 6/6] media: qcom: camss: Use data-lanes starting at 1 for new CSIPHY mode Bryan O'Donoghue
2026-09-25 16:41 ` Liviu Nicoara
2026-09-23 12:35 ` (subset) [PATCH v20 0/6] Add phy_get_by_of_node and devm helper Vinod Koul
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=5cadf2e6-9dbb-4320-b866-cf2fad599c41@linaro.org \
--to=neil.armstrong@linaro.org \
--cc=andersson@kernel.org \
--cc=balbi@ti.com \
--cc=bod@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=johannes.goede@oss.qualcomm.com \
--cc=kishon@kernel.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=mani@kernel.org \
--cc=mchehab@kernel.org \
--cc=mturquette@baylibre.com \
--cc=rfoss@kernel.org \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=todor.too@gmail.com \
--cc=vkoul@kernel.org \
--cc=vladimir.zapolskiy@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®