From: Jonas Karlman <jonas@kwiboo.se>
To: sashiko-reviews@lists.linux.dev
Cc: Frank.Li@kernel.org, linux-sunxi@lists.linux.dev,
imx@lists.linux.dev, neil.armstrong@linaro.org,
linux-amlogic@lists.infradead.org
Subject: Re: [PATCH v6 13/22] drm: bridge: dw_hdmi: Use generic CEC notifier helpers
Date: Sat, 16 May 2026 21:43:30 +0200 [thread overview]
Message-ID: <533dd01f-9516-4267-9376-1e5ba42ba124@kwiboo.se> (raw)
In-Reply-To: <20260516192001.27E4EC19425@smtp.kernel.org>
On 5/16/2026 9:20 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Use-After-Free and Memory Leak in CEC notifier cleanup due to drmm and manual lifecycle mismatch
> --
>
> commit eb59f6fe976b03aa5f719b79a28355b27f403bfe
> Author: Jonas Karlman <jonas@kwiboo.se>
> Subject: drm: bridge: dw_hdmi: Use generic CEC notifier helpers
>
> This commit replaces open-coded CEC notifier handling with generic CEC
> helpers using drmm_connector_hdmi_cec_notifier_register. It also removes
> the manual notifier unregistration from dw_hdmi_connector_destroy.
>
>> The drmm release action for the generic CEC notifier should run just
>> before dw_hdmi_connector_destroy(), closely matching the lifetime of
>> the replaced CEC notifier and the connector.
>
> Is this lifecycle assumption accurate for drivers that do not use drmm
> for mode config?
Yes, drm_mode_config_init() was converted to call its drmm_ variant in
v5.8-rc1, with commit c3b790ea07a1 ("drm: Manage drm_mode_config_init
with drmm_"). Effectively meaning that all drm drivers use drmm for mode
config.
>> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
>> --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
>> +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
> [ ... ]
>> @@ -2547,9 +2543,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() zeroes the connector memory, and
> drm_bridge_put() can drop the final reference to the bridge (which frees
> the dw_hdmi structure and its embedded connector), could this lead to a
> use-after-free?
It should not, destroy() is the last call made for the connector, and
the drm_bridge_put() is here to ensure that the struct dw_hdmi is still
around when drm_connector_cleanup() is called, to avoid a use-after-free.
> If a user-space application holds an open file descriptor to the DRM device
> during driver unbind, the DRM device remains alive. The deferred drmm
> release action will only execute later when the file descriptor is closed
> and the DRM device's refcount drops to zero.
>
> When the drmm action eventually runs, it will dereference the freed
> connector pointer.
>
> Additionally, because drm_connector_cleanup() executes
> memset(connector, 0, sizeof(*connector)), won't connector->cec.data become
> NULL? This would cause the delayed drmm release action to silently skip
> unregistration, leaking the cec_notifier object.
It should not, drmm release actions are called in reverse order, and
drmm_connector_hdmi_cec_notifier_register() is called last, meaning its
release action should be called before drm_mode_config_cleanup() is
called by the the release action for drmm_mode_config_init().
Regards,
Jonas
> [ ... ]
>> @@ -2609,15 +2600,8 @@ static int dw_hdmi_connector_create(struct dw_hdmi *hdmi)
> [ ... ]
>> - 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);
>> }
>
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2026-05-16 19:44 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 18:38 [PATCH v6 00/22] drm: bridge: dw_hdmi: Misc enable/disable, CEC and EDID cleanup Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 01/22] drm: bridge: dw_hdmi: Disable scrambler feature when not supported Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 02/22] drm: bridge: dw_hdmi: Only notify connected status on HPD interrupt Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 03/22] drm: bridge: dw_hdmi: Call poweron/poweroff from atomic enable/disable Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 04/22] drm: bridge: dw_hdmi: Use passed mode instead of stored previous_mode Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 05/22] drm: bridge: dw_hdmi: Fold poweron and setup functions Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 06/22] drm: bridge: dw_hdmi: Remove previous_mode and mode_set Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 07/22] drm: bridge: dw_hdmi: Hold bridge ref until connector cleanup Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 08/22] drm: bridge: dw_hdmi: Unregister CEC notifier during " Jonas Karlman
2026-05-16 19:28 ` sashiko-bot
2026-05-16 18:38 ` [PATCH v6 09/22] drm: bridge: dw_hdmi: Invalidate CEC phys addr from connector detect Jonas Karlman
2026-05-16 19:07 ` sashiko-bot
2026-05-16 19:12 ` Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 10/22] drm: bridge: dw_hdmi: Remove cec_notifier_mutex Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 11/22] drm: bridge: dw_hdmi: Extract dw_hdmi_connector_status_update() Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 12/22] drm: bridge: dw_hdmi: Use dw_hdmi_connector_status_update() Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 13/22] drm: bridge: dw_hdmi: Use generic CEC notifier helpers Jonas Karlman
2026-05-16 19:20 ` sashiko-bot
2026-05-16 19:43 ` Jonas Karlman [this message]
2026-05-16 18:38 ` [PATCH v6 14/22] drm: bridge: dw_hdmi: Update EDID and CEC phys addr in bridge detect() Jonas Karlman
2026-05-16 19:52 ` sashiko-bot
2026-05-16 18:38 ` [PATCH v6 15/22] drm: bridge: dw_hdmi: Declare bridge CEC notifier support Jonas Karlman
2026-05-16 19:30 ` sashiko-bot
2026-05-16 18:38 ` [PATCH v6 16/22] drm: bridge: dw_hdmi: Use display_info is_hdmi and has_audio Jonas Karlman
2026-05-16 19:26 ` sashiko-bot
2026-05-18 9:02 ` Jani Nikula
2026-05-16 18:38 ` [PATCH v6 17/22] drm: bridge: dw_hdmi: Drop call to drm_bridge_hpd_notify() Jonas Karlman
2026-05-16 19:52 ` sashiko-bot
2026-05-16 20:00 ` Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 18/22] drm: bridge: dw_hdmi: Use delayed_work to debounce hotplug event Jonas Karlman
2026-05-16 19:42 ` sashiko-bot
2026-05-16 18:38 ` [PATCH v6 19/22] drm: bridge: dw_hdmi: Rework HDP and RXSENSE interrupt handling Jonas Karlman
2026-05-16 19:43 ` sashiko-bot
2026-05-16 19:55 ` Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 20/22] drm: bridge: dw_hdmi: Remove the empty dw_hdmi_setup_rx_sense() Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 21/22] drm: bridge: dw_hdmi: Remove the empty dw_hdmi_phy_update_hpd() Jonas Karlman
2026-05-16 18:38 ` [PATCH v6 22/22] drm: bridge: dw_hdmi: Merge top and bottom half IRQ handlers Jonas Karlman
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=533dd01f-9516-4267-9376-1e5ba42ba124@kwiboo.se \
--to=jonas@kwiboo.se \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=neil.armstrong@linaro.org \
--cc=sashiko-reviews@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
all inboxes | Powered by JetHome®