usb: musb: Fix missing of_node_put() in omap2430_probe
PATCH 1/1 usb: musb: Fix missing of_node_put() in omap2430_probe
The device_node pointer is returned by of_parse_phandle() with refcount incremented. We should use of_node_put() on it when done.
--- drivers/usb/musb/omap2430.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/musb/omap2430.c +1 -0
@@ -363,6 +363,7 @@ static int omap2430_probe(struct platform_device *pdev) control_node =of_parse_phandle (np,"ctrl-module" ,0 );if (control_node) { control_pdev =of_find_device_by_node (control_node); +of_node_put (control_node);if (!control_pdev) {dev_err (&pdev->dev,"Failed to get control device\n" ); ret = -EINVAL ;
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerQuoted 24 lines · Miaoqian Lin
The
device_nodepointer is returned byof_parse_phandle()with refcount incremented. We should useof_node_put()on it when done.Fixes 8934d3e4d0e7 ("usb: musb: omap2430: Don't use omap_get_control_dev()")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/usb/musb/omap2430.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/musb/omap2430.c +1
-0@@ -363,6 +363,7 @@ static int omap2430_probe(struct platform_device *pdev) control_node =of_parse_phandle (np,"ctrl-module" ,0 );if (control_node) { control_pdev =of_find_device_by_node (control_node); +of_node_put (control_node);if (!control_pdev) {dev_err (&pdev->dev,"Failed to get control device\n" ); ret = -EINVAL ;Signature · 1 line
2.17.1
How was this tested?
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Miaoqian Lin
The
device_nodepointer is returned byof_parse_phandle()with refcount incremented. We should useof_node_put()on it when done.Fixes 8934d3e4d0e7 ("usb: musb: omap2430: Don't use omap_get_control_dev()")Signed-off-by Miaoqian Lin <[email protected]>--- drivers/usb/musb/omap2430.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/musb/omap2430.c +1
-0@@ -363,6 +363,7 @@ static int omap2430_probe(struct platform_device *pdev) control_node =of_parse_phandle (np,"ctrl-module" ,0 );if (control_node) { control_pdev =of_find_device_by_node (control_node); +of_node_put (control_node);
Quoted 8 lines
Quoted 6 lines
drivers/usb/musb/omap2430.c +0
-0if (!control_pdev) {dev_err (&pdev->dev,"Failed to get control device\n" ); ret = -EINVAL ;Signature · 1 line
2.17.1How was this tested?
Hi, Greg Kroah-Hartman
I mainly went through the specifications of of_parse_phandle() and
of_find_device_by_node(), and checked their usages in the codebase to infer their correct usages then found out the deviant one, and manually confirmed it.
In doc of of_parse_phandle() it mentions :
Quoted 2 lines
Return: The
device_nodepointer with refcount incremented. Use
*of_node_put()on it when done.
In the doc of and of_find_device_by_node() it mentions:
Quoted 3 lines
* Takes a reference to the embedded struct device which needs to be dropped
* after use.
In this case, control_node is a local variable, and it never be used
after of_find_device_by_node(), of_find_device_by_node() call will take its own reference. So the reference holded by control_node should be released.
I checked the usages
pattern——$ret=of_parse_phandle();of_find_device_by_node($ret); in codebase and most of them handle the reference after use. For example:
- function pwm_omap_dmtimer_probe in drivers/pwm/pwm-omap-dmtimer.c
- function mtk_smi_device_link_common in drivers/memory/mtk-smi.c,
- function devm_tegra_memory_controller_get in drivers/memory/tegra/mc.c.
I also took similar bugfixes for reference, for exmaple:
- commit c8d0ccfd73da ("media: mtk-vpu: fix leaked of_node references")
- commit 3d38faef0de1 ("ath11k: add missing of_node_put() to avoid leak")
So I sent patch for this one. Still not sure if it's correct, I hope the developers could double check this, Thanks.