ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jonas Karlman" <jonas@kwiboo.se>
Cc: linux-sunxi@lists.linux.dev, Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v5 14/21] drm: bridge: dw_hdmi: Use generic CEC notifier helpers
Date: Tue, 12 May 2026 04:41:11 +0000	[thread overview]
Message-ID: <20260512044111.DF05FC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260510124111.1226584-15-jonas@kwiboo.se>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free and Memory Leak due to lifecycle mismatch with drmm-managed CEC notifier registration
--

commit f25787cb94e7936f6b23599ef90d85d636679290
Author: Jonas Karlman <jonas@kwiboo.se>

drm: bridge: dw_hdmi: Use generic CEC notifier helpers

This commit replaces the open-coded CEC notifier handling with generic CEC
notifier helpers, specifically utilizing drmm_connector_hdmi_cec_notifier_register.
It also selects DRM_DISPLAY_HDMI_CEC_NOTIFIER_HELPER when DRM_DW_HDMI_CEC
is enabled.

> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> index 6fb21399f1370..bf893c754539b 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c

[ ... ]

> @@ -2525,9 +2521,6 @@ static void dw_hdmi_connector_destroy(struct drm_connector *connector)
>  {
>  	struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, connector);
>  
> -	cec_notifier_conn_unregister(hdmi->cec_notifier);
> -	hdmi->cec_notifier = NULL;
> -
>  	drm_connector_cleanup(connector);
>  	drm_bridge_put(&hdmi->bridge);
>  }

Since drm_connector_cleanup() clears the connector memory with a memset, could
this cause a memory leak of the cec_notifier?

Because drmm_connector_hdmi_cec_notifier_register() ties the notifier cleanup
to the drm_device release, the delayed drmm action will eventually run. But by
that time, connector->cec.data will be NULL due to the memset in
drm_connector_cleanup(). Will cec_notifier_conn_unregister(NULL) then
silently return and leave the notifier allocated?

> @@ -2587,15 +2578,8 @@ static int dw_hdmi_connector_create(struct dw_hdmi *hdmi)
>  
>  	drm_connector_attach_encoder(connector, hdmi->bridge.encoder);
>  
> -	cec_fill_conn_info_from_drm(&conn_info, connector);
> -
> -	notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info);
> -	if (!notifier)
> -		return -ENOMEM;
> -
> -	hdmi->cec_notifier = notifier;
> -
> -	return 0;
> +	return drmm_connector_hdmi_cec_notifier_register(connector, NULL,
> +							 hdmi->dev);
>  }

Could tying the CEC registration to the drmm lifecycle lead to a use-after-free
if the bridge unbinds while the DRM device is kept open by userspace?

The dw_hdmi structure (which embeds the connector) is typically allocated via
devm and tied to the bridge platform device. If the bridge unbinds, the
connector memory is freed. However, the drmm cleanup action remains queued on
the DRM device. When the DRM device is finally released, will the drmm
cleanup action dereference the already freed connector pointer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260510124111.1226584-1-jonas@kwiboo.se?part=14

  reply	other threads:[~2026-05-12  4:41 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-10 12:40 [PATCH v5 00/21] drm: bridge: dw_hdmi: Misc enable/disable, CEC and EDID cleanup Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 01/21] drm: bridge: dw_hdmi: Disable scrambler feature when not supported Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 02/21] drm: bridge: dw_hdmi: Only notify connected status on HPD interrupt Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 03/21] drm: bridge: dw_hdmi: Call poweron/poweroff from atomic enable/disable Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 04/21] drm: bridge: dw_hdmi: Use passed mode instead of stored previous_mode Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 05/21] drm: bridge: dw_hdmi: Fold poweron and setup functions Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 06/21] drm: bridge: dw_hdmi: Remove previous_mode and mode_set Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 07/21] drm: bridge: dw_hdmi: Hold bridge ref until connector cleanup Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 08/21] drm: bridge: dw_hdmi: Unregister CEC notifier during " Jonas Karlman
2026-05-12  1:41   ` sashiko-bot
2026-05-10 12:40 ` [PATCH v5 09/21] drm: bridge: dw_hdmi: Invalidate CEC phys addr from connector detect Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 10/21] drm: bridge: dw_hdmi: Remove cec_notifier_mutex Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 11/21] drm: bridge: dw_hdmi: Extract dw_hdmi_connector_status_update() Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 12/21] drm: bridge: dw_hdmi: Use dw_hdmi_connector_status_update() Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 13/21] drm: bridge: dw_hdmi: Use display_info is_hdmi and has_audio Jonas Karlman
2026-05-10 12:40 ` [PATCH v5 14/21] drm: bridge: dw_hdmi: Use generic CEC notifier helpers Jonas Karlman
2026-05-12  4:41   ` sashiko-bot [this message]
2026-05-10 12:40 ` [PATCH v5 15/21] drm: bridge: dw_hdmi: Add common suspend helper Jonas Karlman
2026-05-12  3:35   ` sashiko-bot
2026-05-10 12:41 ` [PATCH v5 16/21] drm: bridge: dw_hdmi: Use delayed_work to debounce hotplug event Jonas Karlman
2026-05-12  3:32   ` sashiko-bot
2026-05-10 12:41 ` [PATCH v5 17/21] drm: bridge: dw_hdmi: Rework HDP and RXSENSE interrupt handling Jonas Karlman
2026-05-12  3:51   ` sashiko-bot
2026-05-10 12:41 ` [PATCH v5 18/21] drm: bridge: dw_hdmi: Remove the empty dw_hdmi_setup_rx_sense() Jonas Karlman
2026-05-10 12:41 ` [PATCH v5 19/21] drm: bridge: dw_hdmi: Remove the empty dw_hdmi_phy_update_hpd() Jonas Karlman
2026-05-10 12:41 ` [PATCH v5 20/21] drm: bridge: dw_hdmi: Merge top and bottom half IRQ handlers Jonas Karlman
2026-05-10 12:41 ` [PATCH v5 21/21] drm: bridge: dw_hdmi: Drop call to drm_bridge_hpd_notify() Jonas Karlman
2026-05-12  3:50   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260512044111.DF05FC2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=jonas@kwiboo.se \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=sashiko@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox