All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 3/4] media: s5p-cec: fix possible object reference leak
@ 2019-02-12 23:47 ` Wen Yang
  2019-03-21 11:51   ` Marek Szyprowski
  0 siblings, 1 reply; 2+ messages in thread
From: Wen Yang @ 2019-02-12 23:47 UTC (permalink / raw)
  To: m.szyprowski
  Cc: mchehab, linux-samsung-soc, linux-media, linux-kernel,
	xue.zhihong, wang.yi59, Wen Yang, Hans Verkuil (hansverk),
	Hans Verkuil, Wen Yang

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.

Hans Verkuil says:
The cec driver should never take a reference of the hdmi device.
It never accesses the HDMI device, it only needs the HDMI device pointer as
a key in the notifier list.
The real problem is that several CEC drivers take a reference of the HDMI
device and never release it. So those drivers need to be fixed.

Fixes: a93d429b51fb ("[media] s5p-cec: add cec-notifier support, move out of staging")
Suggested-by: Hans Verkuil (hansverk) <hansverk@cisco.com>
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Hans Verkuil (hansverk) <hansverk@cisco.com>
Cc: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Wen Yang <yellowriver2010@hotmail.com>
Cc: linux-samsung-soc@vger.kernel.org
Cc: linux-media@vger.kernel.org
---
v2->v1: 
- move of_node_put() to just after the 'hdmi_dev = of_find_device_by_node(np)'.
- put_device() can be done before the cec = devm_kzalloc line.

 drivers/media/platform/s5p-cec/s5p_cec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/s5p-cec/s5p_cec.c b/drivers/media/platform/s5p-cec/s5p_cec.c
index 8837e26..1f5c355 100644
--- a/drivers/media/platform/s5p-cec/s5p_cec.c
+++ b/drivers/media/platform/s5p-cec/s5p_cec.c
@@ -192,9 +192,11 @@ static int s5p_cec_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 	hdmi_dev = of_find_device_by_node(np);
+	of_node_put(np);
 	if (hdmi_dev == NULL)
 		return -EPROBE_DEFER;
 
+	put_device(&hdmi_dev->dev);
 	cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL);
 	if (!cec)
 		return -ENOMEM;
-- 
2.9.5


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

* Re: [PATCH v2 3/4] media: s5p-cec: fix possible object reference leak
  2019-02-12 23:47 ` [PATCH v2 3/4] media: s5p-cec: fix possible object reference leak Wen Yang
@ 2019-03-21 11:51   ` Marek Szyprowski
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Szyprowski @ 2019-03-21 11:51 UTC (permalink / raw)
  To: Wen Yang
  Cc: mchehab, linux-samsung-soc, linux-media, linux-kernel,
	xue.zhihong, wang.yi59, Hans Verkuil (hansverk),
	Hans Verkuil, Wen Yang

Hi

On 2019-02-13 00:47, Wen Yang wrote:
> 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.
>
> Hans Verkuil says:
> The cec driver should never take a reference of the hdmi device.
> It never accesses the HDMI device, it only needs the HDMI device pointer as
> a key in the notifier list.
> The real problem is that several CEC drivers take a reference of the HDMI
> device and never release it. So those drivers need to be fixed.
>
> Fixes: a93d429b51fb ("[media] s5p-cec: add cec-notifier support, move out of staging")
> Suggested-by: Hans Verkuil (hansverk) <hansverk@cisco.com>
> Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
> Cc: Hans Verkuil (hansverk) <hansverk@cisco.com>
> Cc: Hans Verkuil <hans.verkuil@cisco.com>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: Wen Yang <yellowriver2010@hotmail.com>
> Cc: linux-samsung-soc@vger.kernel.org
> Cc: linux-media@vger.kernel.org

Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
> v2->v1:
> - move of_node_put() to just after the 'hdmi_dev = of_find_device_by_node(np)'.
> - put_device() can be done before the cec = devm_kzalloc line.
>
>   drivers/media/platform/s5p-cec/s5p_cec.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/media/platform/s5p-cec/s5p_cec.c b/drivers/media/platform/s5p-cec/s5p_cec.c
> index 8837e26..1f5c355 100644
> --- a/drivers/media/platform/s5p-cec/s5p_cec.c
> +++ b/drivers/media/platform/s5p-cec/s5p_cec.c
> @@ -192,9 +192,11 @@ static int s5p_cec_probe(struct platform_device *pdev)
>   		return -ENODEV;
>   	}
>   	hdmi_dev = of_find_device_by_node(np);
> +	of_node_put(np);
>   	if (hdmi_dev == NULL)
>   		return -EPROBE_DEFER;
>   
> +	put_device(&hdmi_dev->dev);
>   	cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL);
>   	if (!cec)
>   		return -ENOMEM;

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

end of thread, other threads:[~2019-03-21 11:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20190212234951epcas3p3c5dff046aab328e983ecdcecb916148c@epcas3p3.samsung.com>
2019-02-12 23:47 ` [PATCH v2 3/4] media: s5p-cec: fix possible object reference leak Wen Yang
2019-03-21 11:51   ` Marek Szyprowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.