All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chaoyi Chen" <kernel@airkyi.com>
Cc: linux-phy@lists.infradead.org, olteanv@gmail.com,
	vkoul@kernel.org, neil.armstrong@linaro.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 1/6] drm/bridge: Implement generic USB Type-C DP HPD bridge
Date: Thu, 30 Jul 2026 01:50:24 +0000	[thread overview]
Message-ID: <20260730015025.5F58C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730013349.51-2-kernel@airkyi.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Resource leak and duplicate bridge registration on module reload due to lifecycle mismatch.
- [High] Duplicate registration conflict with USB-C controller drivers that natively implement HPD bridges.
- [Medium] Race condition between bus notifier registration and device iteration leading to duplicate bridge registration.
--

--- Patch [1]: [PATCH v5 1/6] drm/bridge: Implement generic USB Type-C DP HPD bridge ---
commit 9877135b6e3e85a72f21170c14a083ad3e0308af
Author: Chaoyi Chen <chaoyi.chen@rock-chips.com>

drm/bridge: Implement generic USB Type-C DP HPD bridge

This patch implements a generic USB Type-C DP HPD bridge that monitors the
Type-C bus for devices containing the DP SVID. It automatically creates an
HPD bridge for these devices without requiring the USB-C controller driver
to implement it manually.

> diff --git a/drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c b/drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
> new file mode 100644
> index 0000000000000..43af3ea20f201
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
> @@ -0,0 +1,64 @@

[ ... ]

> +static int drm_typec_bus_event(struct notifier_block *nb,
> +			       unsigned long action, void *data)
> +{
> +	struct device *dev = (struct device *)data;
> +	struct typec_altmode *alt = to_typec_altmode(dev);
> +
> +	if (action != BUS_NOTIFY_ADD_DEVICE)
> +		return NOTIFY_OK;
> +
> +	/*
> +	 * alt->dev.parent->parent : USB-C controller device
> +	 * alt->dev.parent         : USB-C connector device
> +	 */
> +	if (is_typec_port_altmode(&alt->dev) && alt->svid == USB_TYPEC_DP_SID)
> +		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
> +					   to_of_node(alt->dev.parent->fwnode));

[Severity: High]
Does this unconditional registration create duplicate bridges for controller
drivers (like fusb302 or qcom_pmic_typec) that already manually allocate
their own HPD bridge for the same device node?

If the DRM subsystem binds to the generic bridge instead of the native one,
could HPD events sent by the controller via drm_aux_hpd_bridge_notify() to
its private bridge be lost?

[ ... ]

> +static void drm_aux_hpd_typec_dp_bridge_module_exit(void)
> +{
> +	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
> +}

[Severity: High]
Does this leak resources and create duplicate bridges if the module is unloaded
and reloaded?

Since drm_dp_hpd_bridge_register() uses devm semantics tied to the USB-C
controller device (alt->dev.parent->parent) rather than this observer module,
the bridges will outlive the module. When the module is reloaded, it will
iterate the bus and unconditionally allocate a second set of duplicate bridges.

> +
> +static int __init drm_aux_hpd_typec_dp_bridge_module_init(void)
> +{
> +	bus_register_notifier(&typec_bus, &drm_typec_event_nb);
> +	/*
> +	 * Before module initialization, some devices may have already been added.
> +         * Register the HPD bridge for these devices.
> +	 */
> +	bus_for_each_dev(&typec_bus, NULL, NULL, check_device_already_added);

[Severity: Medium]
Is there a race condition here between registering the bus notifier and iterating
over the existing devices?

If a Type-C altmode device is added concurrently during module initialization,
could it trigger the notifier callback and also be processed by the bus iteration
loop? Since drm_dp_hpd_bridge_register() lacks deduplication logic, this TOCTOU
race might result in duplicate bridge registrations.

> +	return 0;
> +}
> +
> +module_init(drm_aux_hpd_typec_dp_bridge_module_init);
> +module_exit(drm_aux_hpd_typec_dp_bridge_module_exit);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730013349.51-1-kernel@airkyi.com?part=1

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Chaoyi Chen" <kernel@airkyi.com>
Cc: linux-phy@lists.infradead.org, olteanv@gmail.com,
	vkoul@kernel.org, neil.armstrong@linaro.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 1/6] drm/bridge: Implement generic USB Type-C DP HPD bridge
Date: Thu, 30 Jul 2026 01:50:24 +0000	[thread overview]
Message-ID: <20260730015025.5F58C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730013349.51-2-kernel@airkyi.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Resource leak and duplicate bridge registration on module reload due to lifecycle mismatch.
- [High] Duplicate registration conflict with USB-C controller drivers that natively implement HPD bridges.
- [Medium] Race condition between bus notifier registration and device iteration leading to duplicate bridge registration.
--

--- Patch [1]: [PATCH v5 1/6] drm/bridge: Implement generic USB Type-C DP HPD bridge ---
commit 9877135b6e3e85a72f21170c14a083ad3e0308af
Author: Chaoyi Chen <chaoyi.chen@rock-chips.com>

drm/bridge: Implement generic USB Type-C DP HPD bridge

This patch implements a generic USB Type-C DP HPD bridge that monitors the
Type-C bus for devices containing the DP SVID. It automatically creates an
HPD bridge for these devices without requiring the USB-C controller driver
to implement it manually.

> diff --git a/drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c b/drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
> new file mode 100644
> index 0000000000000..43af3ea20f201
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
> @@ -0,0 +1,64 @@

[ ... ]

> +static int drm_typec_bus_event(struct notifier_block *nb,
> +			       unsigned long action, void *data)
> +{
> +	struct device *dev = (struct device *)data;
> +	struct typec_altmode *alt = to_typec_altmode(dev);
> +
> +	if (action != BUS_NOTIFY_ADD_DEVICE)
> +		return NOTIFY_OK;
> +
> +	/*
> +	 * alt->dev.parent->parent : USB-C controller device
> +	 * alt->dev.parent         : USB-C connector device
> +	 */
> +	if (is_typec_port_altmode(&alt->dev) && alt->svid == USB_TYPEC_DP_SID)
> +		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
> +					   to_of_node(alt->dev.parent->fwnode));

[Severity: High]
Does this unconditional registration create duplicate bridges for controller
drivers (like fusb302 or qcom_pmic_typec) that already manually allocate
their own HPD bridge for the same device node?

If the DRM subsystem binds to the generic bridge instead of the native one,
could HPD events sent by the controller via drm_aux_hpd_bridge_notify() to
its private bridge be lost?

[ ... ]

> +static void drm_aux_hpd_typec_dp_bridge_module_exit(void)
> +{
> +	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
> +}

[Severity: High]
Does this leak resources and create duplicate bridges if the module is unloaded
and reloaded?

Since drm_dp_hpd_bridge_register() uses devm semantics tied to the USB-C
controller device (alt->dev.parent->parent) rather than this observer module,
the bridges will outlive the module. When the module is reloaded, it will
iterate the bus and unconditionally allocate a second set of duplicate bridges.

> +
> +static int __init drm_aux_hpd_typec_dp_bridge_module_init(void)
> +{
> +	bus_register_notifier(&typec_bus, &drm_typec_event_nb);
> +	/*
> +	 * Before module initialization, some devices may have already been added.
> +         * Register the HPD bridge for these devices.
> +	 */
> +	bus_for_each_dev(&typec_bus, NULL, NULL, check_device_already_added);

[Severity: Medium]
Is there a race condition here between registering the bus notifier and iterating
over the existing devices?

If a Type-C altmode device is added concurrently during module initialization,
could it trigger the notifier callback and also be processed by the bus iteration
loop? Since drm_dp_hpd_bridge_register() lacks deduplication logic, this TOCTOU
race might result in duplicate bridge registrations.

> +	return 0;
> +}
> +
> +module_init(drm_aux_hpd_typec_dp_bridge_module_init);
> +module_exit(drm_aux_hpd_typec_dp_bridge_module_exit);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730013349.51-1-kernel@airkyi.com?part=1

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-07-30  1:50 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  1:33 [PATCH v5 0/6] drm/bridge: Implement generic USB Type-C DP HPD bridge Chaoyi Chen
2026-07-30  1:33 ` Chaoyi Chen
2026-07-30  1:33 ` Chaoyi Chen
2026-07-30  1:33 ` [PATCH v5 1/6] " Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:50   ` sashiko-bot [this message]
2026-07-30  1:50     ` sashiko-bot
2026-07-30  1:33 ` [PATCH v5 2/6] drm/display: Add soft depend for aux-hpd-typec-dp-bridge module Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33 ` [PATCH v5 3/6] drm/bridge: aux: Add drm_aux_bridge_register_from_node() Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:42   ` sashiko-bot
2026-07-30  1:42     ` sashiko-bot
2026-07-30  1:33 ` [PATCH v5 4/6] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:47   ` sashiko-bot
2026-07-30  1:47     ` sashiko-bot
2026-07-30  1:33 ` [PATCH v5 5/6] drm/rockchip: cdn-dp: Support handle lane info without extcon Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:46   ` sashiko-bot
2026-07-30  1:46     ` sashiko-bot
2026-07-30  1:33 ` [PATCH v5 6/6] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:33   ` Chaoyi Chen
2026-07-30  1:48   ` sashiko-bot
2026-07-30  1:48     ` 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=20260730015025.5F58C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel@airkyi.com \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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 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.