2022-05-11 09:02:11

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH] drm/meson: Fix refcount leak in meson_encoder_hdmi_init

of_find_device_by_node() takes reference, we should use put_device()
to release it when not need anymore.
Add missing put_device() in error path to avoid refcount
leak.

Fixes: 0af5e0b41110 ("drm/meson: encoder_hdmi: switch to bridge DRM_BRIDGE_ATTACH_NO_CONNECTOR")
Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
index 5e306de6f485..de87f02cd388 100644
--- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c
+++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
@@ -435,8 +435,10 @@ int meson_encoder_hdmi_init(struct meson_drm *priv)
cec_fill_conn_info_from_drm(&conn_info, meson_encoder_hdmi->connector);

notifier = cec_notifier_conn_register(&pdev->dev, NULL, &conn_info);
- if (!notifier)
+ if (!notifier) {
+ put_device(&pdev->dev);
return -ENOMEM;
+ }

meson_encoder_hdmi->cec_notifier = notifier;
}
--
2.25.1



2022-05-13 16:47:22

by Martin Blumenstingl

[permalink] [raw]
Subject: Re: [PATCH] drm/meson: Fix refcount leak in meson_encoder_hdmi_init

On Wed, May 11, 2022 at 7:41 AM Miaoqian Lin <[email protected]> wrote:
>
> of_find_device_by_node() takes reference, we should use put_device()
> to release it when not need anymore.
> Add missing put_device() in error path to avoid refcount
> leak.
>
> Fixes: 0af5e0b41110 ("drm/meson: encoder_hdmi: switch to bridge DRM_BRIDGE_ATTACH_NO_CONNECTOR")
> Signed-off-by: Miaoqian Lin <[email protected]>
Reviewed-by: Martin Blumenstingl <[email protected]>

Thanks for sending this patch!

Neil, while reviewing this I noticed that on module unload we're also
not calling put_device().
This note doesn't affect this patch - but I am wondering if we need to
put that put_device() during module unload on our TODO-list?


Best regards,
Martin

2022-05-14 03:32:59

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH] drm/meson: Fix refcount leak in meson_encoder_hdmi_init

On 11/05/2022 07:40, Miaoqian Lin wrote:
> of_find_device_by_node() takes reference, we should use put_device()
> to release it when not need anymore.
> Add missing put_device() in error path to avoid refcount
> leak.
>
> Fixes: 0af5e0b41110 ("drm/meson: encoder_hdmi: switch to bridge DRM_BRIDGE_ATTACH_NO_CONNECTOR")
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> index 5e306de6f485..de87f02cd388 100644
> --- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> +++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> @@ -435,8 +435,10 @@ int meson_encoder_hdmi_init(struct meson_drm *priv)
> cec_fill_conn_info_from_drm(&conn_info, meson_encoder_hdmi->connector);
>
> notifier = cec_notifier_conn_register(&pdev->dev, NULL, &conn_info);
> - if (!notifier)
> + if (!notifier) {
> + put_device(&pdev->dev);
> return -ENOMEM;
> + }
>
> meson_encoder_hdmi->cec_notifier = notifier;
> }

Reviewed-by: Neil Armstrong <[email protected]>

2022-05-14 04:09:33

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH] drm/meson: Fix refcount leak in meson_encoder_hdmi_init

Hi,

On 12/05/2022 14:38, Martin Blumenstingl wrote:
> On Wed, May 11, 2022 at 7:41 AM Miaoqian Lin <[email protected]> wrote:
>>
>> of_find_device_by_node() takes reference, we should use put_device()
>> to release it when not need anymore.
>> Add missing put_device() in error path to avoid refcount
>> leak.
>>
>> Fixes: 0af5e0b41110 ("drm/meson: encoder_hdmi: switch to bridge DRM_BRIDGE_ATTACH_NO_CONNECTOR")
>> Signed-off-by: Miaoqian Lin <[email protected]>
> Reviewed-by: Martin Blumenstingl <[email protected]>
>
> Thanks for sending this patch!
>
> Neil, while reviewing this I noticed that on module unload we're also
> not calling put_device().
> This note doesn't affect this patch - but I am wondering if we need to
> put that put_device() during module unload on our TODO-list?
>

Indeed, it should be fixed.

Neil


>
> Best regards,
> Martin


2022-05-18 07:24:23

by Neil Armstrong

[permalink] [raw]
Subject: Re: [PATCH] drm/meson: Fix refcount leak in meson_encoder_hdmi_init

Hi,

On Wed, 11 May 2022 09:40:51 +0400, Miaoqian Lin wrote:
> of_find_device_by_node() takes reference, we should use put_device()
> to release it when not need anymore.
> Add missing put_device() in error path to avoid refcount
> leak.
>
>

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-next)

[1/1] drm/meson: Fix refcount leak in meson_encoder_hdmi_init
https://cgit.freedesktop.org/drm/drm-misc/commit/?id=7381076809586528e2a812a709e2758916318a99

--
Neil