phy: fix device leaks at unbind
Subsystems (4)
cover phy: fix device leaks at unbind
This series fixes device leaks due to failure to drop the reference taken by of_find_device_by_node().
Johan
Johan Hovold (3):
phy: tegra: xusb: fix device and OF node leak at probe
phy: ti: omap-usb2: fix device leak at unbind
phy: ti-pipe3: fix device leak at unbind
drivers/phy/tegra/xusb-tegra210.c | 6 +++++- drivers/phy/ti/phy-omap-usb2.c | 13 +++++++++++++ drivers/phy/ti/phy-ti-pipe3.c | 13 +++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-)
Signature · 1 line
2.49.1
PATCH 1/3 phy: tegra: xusb: fix device and OF node leak at probe
Make sure to drop the references taken to the PMC OF node and device by of_parse_phandle() and of_find_device_by_node() during probe.
Note the holding a reference to the PMC device does not prevent the PMC regmap from going away (e.g. if the PMC driver is unbound) so there is no need to keep the reference.
--- drivers/phy/tegra/xusb-tegra210.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/phy/tegra/xusb-tegra210.c +5 -1
@@ -3164,18 +3164,22 @@ tegra210_xusb_padctl_probe(struct device *dev, } pdev =of_find_device_by_node (np); +of_node_put (np);if (!pdev) {dev_warn (dev,"PMC device is not available\n" ); 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)dev_info (dev,"failed to find PMC regmap\n" ); +put_device (&pdev->dev); out:return &padctl->base; }
Signature · 1 line
2.49.1
Re: [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe
Quoted 15 lines · Johan Hovold
Make sure to drop the references taken to the PMC OF node and device by
of_parse_phandle()andof_find_device_by_node()during probe.Note the holding a reference to the PMC device does not prevent the PMC regmap from going away (e.g. if the PMC driver is unbound) so there is no need to keep the reference.
Fixes 2d1021487273 ("phy: tegra: xusb: Add wake/sleepwalk for Tegra210")Cc [email protected] # 5.14Cc JC Kuo <[email protected]>Signed-off-by Johan Hovold <[email protected]>--- drivers/phy/tegra/xusb-tegra210.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
<snip>
PATCH 2/3 phy: ti: omap-usb2: fix device leak at unbind
In reply to Johan HovoldMake sure to drop the reference to the control device taken by of_find_device_by_node() during probe when the driver is unbound.
--- drivers/phy/ti/phy-omap-usb2.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/phy/ti/phy-omap-usb2.c +13 -0
@@ -363,6 +363,13 @@ static void omap_usb2_init_errata(struct omap_usb *phy) phy->flags |=OMAP_USB2_DISABLE_CHRG_DET ; } +static void omap_usb2_put_device (void *_dev) +{ +struct device *dev = _dev; + +put_device (dev); +} +static int omap_usb2_probe (struct platform_device *pdev) {struct omap_usb *phy;
@@ -373,6 +380,7 @@ static int omap_usb2_probe(struct platform_device *pdev)struct device_node *control_node;struct platform_device *control_pdev;const struct usb_phy_data *phy_data; +int ret; phy_data =device_get_match_data (&pdev->dev);if (!phy_data)
@@ -423,6 +431,11 @@ static int omap_usb2_probe(struct platform_device *pdev)return -EINVAL ; } phy->control_dev = &control_pdev->dev; + + ret =devm_add_action_or_reset (&pdev->dev, omap_usb2_put_device, + phy->control_dev); +if (ret) +return ret; }else { if (of_property_read_u32_index(node, "syscon-phy-power", 1,
Signature · 1 line
2.49.1
PATCH 3/3 phy: ti-pipe3: fix device leak at unbind
In reply to Johan HovoldMake sure to drop the reference to the control device taken by of_find_device_by_node() during probe when the driver is unbound.
--- drivers/phy/ti/phy-ti-pipe3.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/phy/ti/phy-ti-pipe3.c +13 -0
@@ -667,12 +667,20 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)return 0 ; } +static void ti_pipe3_put_device (void *_dev) +{ +struct device *dev = _dev; + +put_device (dev); +} +static int ti_pipe3_get_sysctrl (struct ti_pipe3 *phy) {struct device *dev = phy->dev;struct device_node *node = dev->of_node;struct device_node *control_node;struct platform_device *control_pdev; +int ret; phy->phy_power_syscon =syscon_regmap_lookup_by_phandle (node,"syscon-phy-power" );
@@ -704,6 +712,11 @@ static int ti_pipe3_get_sysctrl(struct ti_pipe3 *phy) } phy->control_dev = &control_pdev->dev; + + ret =devm_add_action_or_reset (dev, ti_pipe3_put_device, + phy->control_dev); +if (ret) +return ret; }if (phy->mode ==PIPE3_MODE_PCIE ) {
Signature · 1 line
2.49.1
Quoted 11 lines · Johan Hovold
This series fixes device leaks due to failure to drop the reference taken by
of_find_device_by_node().Johan
Johan Hovold (3):
phy: tegra: xusb: fix device and OF node leak at probe
phy: ti: omap-usb2: fix device leak at unbind
phy: ti-pipe3: fix device leak at unbind[...]
Applied, thanks!
[1/3] phy: tegra: xusb: fix device and OF node leak at probe
commit: bca065733afd1e3a89a02f05ffe14e966cd5f78e
[2/3] phy: ti: omap-usb2: fix device leak at unbind
commit: 64961557efa1b98f375c0579779e7eeda1a02c42
[3/3] phy: ti-pipe3: fix device leak at unbind
commit: e19bcea99749ce8e8f1d359f68ae03210694ad56Best regards,
Signature · 1 line
~Vinod