linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] phy/tegra: add put_device() after of_find_device_by_node()
@ 2021-08-20  2:46 jing yangyang
  2021-08-20 11:34 ` Thierry Reding
  0 siblings, 1 reply; 2+ messages in thread
From: jing yangyang @ 2021-08-20  2:46 UTC (permalink / raw)
  To: JC Kuo
  Cc: Kishon Vijay Abraham I, Vinod Koul, Thierry Reding,
	Jonathan Hunter, linux-phy, linux-tegra, linux-kernel,
	jing yangyang, Zeal Robot

This was found by coccicheck:
./drivers/phy/tegra/xusb-tegra210.c:3174: 2-8:ERROR:
missing put_device;call of_find_device_by_node on line 3167,
but without a corresponding object release within this function.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: jing yangyang <jing.yangyang@zte.com.cn>
---
 drivers/phy/tegra/xusb-tegra210.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c
index eedfc7c..f26eb5a 100644
--- a/drivers/phy/tegra/xusb-tegra210.c
+++ b/drivers/phy/tegra/xusb-tegra210.c
@@ -3170,8 +3170,10 @@ static int tegra210_utmi_port_reset(struct phy *phy)
 		goto out;
 	}
 
-	if (!platform_get_drvdata(pdev))
+	if (!platform_get_drvdata(pdev)) {
+		put_device(&pdev->dev);
 		return ERR_PTR(-EPROBE_DEFER);
+	}
 
 	padctl->regmap = dev_get_regmap(&pdev->dev, "usb_sleepwalk");
 	if (!padctl->regmap)
-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH linux-next] phy/tegra: add put_device() after of_find_device_by_node()
  2021-08-20  2:46 [PATCH linux-next] phy/tegra: add put_device() after of_find_device_by_node() jing yangyang
@ 2021-08-20 11:34 ` Thierry Reding
  0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2021-08-20 11:34 UTC (permalink / raw)
  To: jing yangyang, Mark Brown
  Cc: JC Kuo, Kishon Vijay Abraham I, Vinod Koul, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel, jing yangyang, Zeal Robot

[-- Attachment #1: Type: text/plain, Size: 1799 bytes --]

On Thu, Aug 19, 2021 at 07:46:33PM -0700, jing yangyang wrote:
> This was found by coccicheck:
> ./drivers/phy/tegra/xusb-tegra210.c:3174: 2-8:ERROR:
> missing put_device;call of_find_device_by_node on line 3167,
> but without a corresponding object release within this function.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: jing yangyang <jing.yangyang@zte.com.cn>
> ---
>  drivers/phy/tegra/xusb-tegra210.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c
> index eedfc7c..f26eb5a 100644
> --- a/drivers/phy/tegra/xusb-tegra210.c
> +++ b/drivers/phy/tegra/xusb-tegra210.c
> @@ -3170,8 +3170,10 @@ static int tegra210_utmi_port_reset(struct phy *phy)
>  		goto out;
>  	}
>  
> -	if (!platform_get_drvdata(pdev))
> +	if (!platform_get_drvdata(pdev)) {
> +		put_device(&pdev->dev);
>  		return ERR_PTR(-EPROBE_DEFER);
> +	}
>  
>  	padctl->regmap = dev_get_regmap(&pdev->dev, "usb_sleepwalk");
>  	if (!padctl->regmap)

I think we also need that put_device() after getting the regmap because
we loose the reference to the platform device after that.

On the other hand, I suppose we might have to hang on to the reference
until tegra210_xusb_padctl_remove() so that the platform device that the
regmap is provided by doesn't suddenly go away.

Mark, I couldn't find how the lifetime of regmaps is getting tracked.
dev_get_regmap() seems to only return a pointer to the regmap if it
exists, but doesn't actually increment a reference or anything. So do we
need to hold on to the struct device that we get it from until we no
longer need the reference? Or is there some other way to make sure the
regmap doesn't disappear on us?

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-20 11:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20  2:46 [PATCH linux-next] phy/tegra: add put_device() after of_find_device_by_node() jing yangyang
2021-08-20 11:34 ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).