linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4] media: s5p-cec: fix possible object reference leak
@ 2019-02-09  2:54 Wen Yang
  0 siblings, 0 replies; only message in thread
From: Wen Yang @ 2019-02-09  2:54 UTC (permalink / raw)
  To: Marek Szyprowski, Mauro Carvalho Chehab, Kevin Hilman
  Cc: Wen Yang, linux-samsung-soc, linux-kernel, linux-arm-kernel, linux-media

The call to of_parse_phandle() returns a node pointer with refcount
incremented thus it must be explicitly decremented here after the last
usage.
The of_find_device_by_node() takes a reference to the underlying device
structure, we also should release that reference.
This patch fixes those two issues.

Fixes: a93d429b51fb ("[media] s5p-cec: add cec-notifier support, move out of staging")
Signed-off-by: Wen Yang <yellowriver2010@hotmail.com>
---
 drivers/media/platform/s5p-cec/s5p_cec.c | 38 ++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-cec/s5p_cec.c b/drivers/media/platform/s5p-cec/s5p_cec.c
index 8837e26..4af47ce 100644
--- a/drivers/media/platform/s5p-cec/s5p_cec.c
+++ b/drivers/media/platform/s5p-cec/s5p_cec.c
@@ -192,47 +192,64 @@ static int s5p_cec_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 	hdmi_dev = of_find_device_by_node(np);
-	if (hdmi_dev == NULL)
+	if (hdmi_dev == NULL) {
+		of_node_put(np);
 		return -EPROBE_DEFER;
+	}
 
+	of_node_put(np);
 	cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL);
-	if (!cec)
+	if (!cec) {
+		put_device(&hdmi_dev->dev);
 		return -ENOMEM;
+	}
 
 	cec->dev = dev;
 
 	cec->irq = platform_get_irq(pdev, 0);
-	if (cec->irq < 0)
+	if (cec->irq < 0) {
+		put_device(&hdmi_dev->dev);
 		return cec->irq;
+	}
 
 	ret = devm_request_threaded_irq(dev, cec->irq, s5p_cec_irq_handler,
 		s5p_cec_irq_handler_thread, 0, pdev->name, cec);
-	if (ret)
+	if (ret) {
+		put_device(&hdmi_dev->dev);
 		return ret;
+	}
 
 	cec->clk = devm_clk_get(dev, "hdmicec");
-	if (IS_ERR(cec->clk))
+	if (IS_ERR(cec->clk)) {
+		put_device(&hdmi_dev->dev);
 		return PTR_ERR(cec->clk);
+	}
 
 	cec->pmu = syscon_regmap_lookup_by_phandle(dev->of_node,
 						 "samsung,syscon-phandle");
-	if (IS_ERR(cec->pmu))
+	if (IS_ERR(cec->pmu)) {
+		put_device(&hdmi_dev->dev);
 		return -EPROBE_DEFER;
+	}
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	cec->reg = devm_ioremap_resource(dev, res);
-	if (IS_ERR(cec->reg))
+	if (IS_ERR(cec->reg)) {
+		put_device(&hdmi_dev->dev);
 		return PTR_ERR(cec->reg);
+	}
 
 	cec->notifier = cec_notifier_get(&hdmi_dev->dev);
-	if (cec->notifier == NULL)
+	if (cec->notifier == NULL) {
+		put_device(&hdmi_dev->dev);
 		return -ENOMEM;
+	}
 
 	cec->adap = cec_allocate_adapter(&s5p_cec_adap_ops, cec, CEC_NAME,
 		CEC_CAP_DEFAULTS | (needs_hpd ? CEC_CAP_NEEDS_HPD : 0), 1);
 	ret = PTR_ERR_OR_ZERO(cec->adap);
 	if (ret)
-		return ret;
+		goto err_put_notifier;
 
 	ret = cec_register_adapter(cec->adap, &pdev->dev);
 	if (ret)
@@ -248,6 +265,9 @@ static int s5p_cec_probe(struct platform_device *pdev)
 
 err_delete_adapter:
 	cec_delete_adapter(cec->adap);
+err_put_notifier:
+	cec_notifier_put(cec->notifier);
+	dev_err(&pdev->dev, "CEC controller registration failed\n");
 	return ret;
 }
 
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-02-09  2:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-09  2:54 [PATCH 3/4] media: s5p-cec: fix possible object reference leak Wen Yang

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).