Skip to contentSkip to conversation

drm/meson: Fix refcount leak in meson_encoder_hdmi_init

PATCH Applied Miaoqian Lin 3 participants 5 messages May 11, 2022 – May 18, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/meson/meson_encoder_hdmi.c +3 -1
index 5e306de6f485..de87f02cd388 100644
@@ -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;
 	}
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Miaoqian Lin

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")
---
  drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/meson/meson_encoder_hdmi.c +0 -0
index 5e306de6f485..de87f02cd388 100644
@@ -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);

drivers/gpu/drm/meson/meson_encoder_hdmi.c int meson_encoder_hdmi_init(struct meson_drm *priv) · line 444

Quoted 10 lines
drivers/gpu/drm/meson/meson_encoder_hdmi.c +3 -1
 
  		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;
  	}
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin
Quoted 8 lines · Miaoqian Lin

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

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

#3 lore raw

Hi,

Quoted 9 lines · Martin Blumenstingl
Quoted 8 lines · Miaoqian Lin

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")
Quoted 9 lines

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

Quoted 3 lines

Best regards,
Martin

#4 lore raw
In reply to Miaoqian Lin

Hi,

Quoted 6 lines · Miaoqian Lin

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
Signature · 1 line
Neil