Skip to contentSkip to conversation

drm/imx/tve: fix probe device leak

PATCH Superseded Johan Hovold 3 participants 5 messages Sep 23, 2025 – Oct 30, 2025

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/imx/tve: fix probe device leak

Make sure to drop the reference taken to the DDC device during probe on probe failure (e.g. probe deferral) and on driver unbind.

Fixes fcbc51e54d2a ("staging: drm/imx: Add support for Television Encoder (TVEv2)")
Cc Philipp Zabel <[email protected]>
---
 drivers/gpu/drm/imx/ipuv3/imx-tve.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/imx/ipuv3/imx-tve.c +12 -0
index c5629e155d25..895413d26113 100644
@@ -525,6 +525,13 @@ static const struct component_ops imx_tve_ops = {
 	.bind	= imx_tve_bind,
 };
 
+static void imx_tve_put_device(void *_dev)
+{
+	struct device *dev = _dev;
+
+	put_device(dev);
+}
+
 static int imx_tve_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -546,6 +553,11 @@ static int imx_tve_probe(struct platform_device *pdev)
 	if (ddc_node) {
 		tve->ddc = of_find_i2c_adapter_by_node(ddc_node);
 		of_node_put(ddc_node);
+
+		ret = devm_add_action_or_reset(dev, imx_tve_put_device,
+					       &tve->ddc->dev);
+		if (ret)
+			return ret;
 	}
 
 	tve->mode = of_get_tve_mode(np);
Signature · 1 line
2.49.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Johan Hovold

Make sure to drop the reference taken to the DDC device during probe on probe failure (e.g. probe deferral) and on driver unbind.

Fixes fcbc51e54d2a ("staging: drm/imx: Add support for Television Encoder (TVEv2)")
Cc Philipp Zabel <[email protected]>
Quoted 37 lines
---
 drivers/gpu/drm/imx/ipuv3/imx-tve.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/imx/ipuv3/imx-tve.c +12 -1
index c5629e155d25..895413d26113 100644
@@ -525,6 +525,13 @@ static const struct component_ops imx_tve_ops = {
 	.bind	= imx_tve_bind,
 };
 
+static void imx_tve_put_device(void *_dev)
+{
+	struct device *dev = _dev;
+
+	put_device(dev);
+}
+
 static int imx_tve_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -546,6 +553,11 @@ static int imx_tve_probe(struct platform_device *pdev)
 	if (ddc_node) {
 		tve->ddc = of_find_i2c_adapter_by_node(ddc_node);
 		of_node_put(ddc_node);
+
+		ret = devm_add_action_or_reset(dev, imx_tve_put_device,
+					       &tve->ddc->dev);
+		if (ret)
+			return ret;
 	}
 
 	tve->mode = of_get_tve_mode(np);
--

2.49.1

maintainer
#3 lore raw
In reply to Johan Hovold
Quoted 30 lines · Johan Hovold

Make sure to drop the reference taken to the DDC device during probe on probe failure (e.g. probe deferral) and on driver unbind.

Fixes fcbc51e54d2a ("staging: drm/imx: Add support for Television Encoder (TVEv2)")
Cc Philipp Zabel <[email protected]>
---
 drivers/gpu/drm/imx/ipuv3/imx-tve.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/imx/ipuv3/imx-tve.c +7 -0
index c5629e155d25..895413d26113 100644
@@ -525,6 +525,13 @@ static const struct component_ops imx_tve_ops = {
 	.bind	= imx_tve_bind,
 };
 
+static void imx_tve_put_device(void *_dev)
+{
+	struct device *dev = _dev;
+
+	put_device(dev);
+}
+
 static int imx_tve_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;

drivers/gpu/drm/imx/ipuv3/imx-tve.c static int imx_tve_probe(struct platform_device *pdev) · line 558

Quoted 6 lines
drivers/gpu/drm/imx/ipuv3/imx-tve.c +3 -0
@@ -546,6 +553,11 @@ static int imx_tve_probe(struct platform_device *pdev)
 	if (ddc_node) {
 		tve->ddc = of_find_i2c_adapter_by_node(ddc_node);
 		of_node_put(ddc_node);
+
+		ret = devm_add_action_or_reset(dev, imx_tve_put_device,
+					       &tve->ddc->dev);

I think this needs to be wrapped in "if (tve->ddc) { }", of_find_i2c_adapter_by_node() can return NULL.

regards
Philipp

#4 lore raw
Quoted 15 lines · Philipp Zabel

drivers/gpu/drm/imx/ipuv3/imx-tve.c static int imx_tve_probe(struct platform_device *pdev) · line 558

Quoted 10 lines · Johan Hovold

static int imx_tve_probe(struct platform_device *pdev) {

drivers/gpu/drm/imx/ipuv3/imx-tve.c +3 -0
 	struct device *dev = &pdev->dev;
@@ -546,6 +553,11 @@ static int imx_tve_probe(struct platform_device *pdev)
 	if (ddc_node) {
 		tve->ddc = of_find_i2c_adapter_by_node(ddc_node);
 		of_node_put(ddc_node);
+
+		ret = devm_add_action_or_reset(dev, imx_tve_put_device,
+					       &tve->ddc->dev);

I think this needs to be wrapped in "if (tve->ddc) { }", of_find_i2c_adapter_by_node() can return NULL.

Indeed, thanks for catching that. Just sent a v2.

Johan