[PATCH] phy: core: fix an OF node reference leak in _of_phy_get()
Lk Sii
lk_sii at 163.com
Thu Dec 12 02:50:51 PST 2024
On 2024/12/12 10:11, Joe Hattori wrote:
> _of_phy_get() does not decrement the refcount of the obtained OF node in
> the error path. Add a of_node_put() call before returning.
>
> This bug was found by an experimental static analysis tool that I am
> developing.
>
Good tool.
this fix is same as my v1 fix below:
https://lore.kernel.org/all/20241020-phy_core_fix-v1-4-078062f7da71@quicinc.com/
My latest v5 patch series is here, and it has another OF leakage fix.
https://lore.kernel.org/all/20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com/
(^^).
> Fixes: b7563e2796f8 ("phy: work around 'phys' references to usb-nop-xceiv devices")
> Signed-off-by: Joe Hattori <joe at pf.is.s.u-tokyo.ac.jp>
> ---
> drivers/phy/phy-core.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index f053b525ccff..bca303d51fd2 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -629,8 +629,10 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
> return ERR_PTR(-ENODEV);
>
> /* This phy type handled by the usb-phy subsystem for now */
> - if (of_device_is_compatible(args.np, "usb-nop-xceiv"))
> + if (of_device_is_compatible(args.np, "usb-nop-xceiv")) {
> + of_node_put(args.np);
> return ERR_PTR(-ENODEV);
> + }
>
> mutex_lock(&phy_provider_mutex);
> phy_provider = of_phy_provider_lookup(args.np);
More information about the linux-phy
mailing list