All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org,
	wsa+renesas@sang-engineering.com, robh@kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/4] drm/bridge: display-connector: Fix I2C adapter resource leak
Date: Sun, 05 Jul 2026 21:48:25 +0000	[thread overview]
Message-ID: <20260705214826.628831F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260705213542.28987-3-laurent.pinchart+renesas@ideasonboard.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-After-Free of devm-managed resources due to DRM bridge lifetime mismatch
- [Medium] Hardware state leak of `ddc_en` GPIO on probe error paths
--

commit 9c76898e592dfddd3f50beaa692cc32ae295e2c7
Author: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

drm/bridge: display-connector: Fix I2C adapter resource leak

If the probe function returns an error after getting the I2C adapter for
DDC, the reference to the adapter is never released. Fix it by releasing
it in the bridge .destroy() handler.

> diff --git a/drivers/gpu/drm/bridge/display-connector.c b/drivers/gpu/drm/bridge/display-connector.c
> index d1e74dd2e0518..eb3412ec30a07 100644
> --- a/drivers/gpu/drm/bridge/display-connector.c
> +++ b/drivers/gpu/drm/bridge/display-connector.c
> @@ -43,6 +43,13 @@ static int display_connector_attach(struct drm_bridge *bridge,
>  	return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL;
>  }
>  
> +static void display_connector_destroy(struct drm_bridge *bridge)
> +{
> +	struct display_connector *conn = to_display_connector(bridge);
> +
> +	i2c_put_adapter(conn->bridge.ddc);
> +}
> +
>  static enum drm_connector_status display_connector_detect(struct drm_bridge *bridge)
>  {
>  	struct display_connector *conn = to_display_connector(bridge);

[ ... ]

> @@ -439,9 +447,6 @@ static void display_connector_remove(struct platform_device *pdev)
>  		regulator_disable(conn->supply);
>  
>  	drm_bridge_remove(&conn->bridge);
> -
> -	if (!IS_ERR(conn->bridge.ddc))
> -		i2c_put_adapter(conn->bridge.ddc);
>  }
>  
>  static const struct of_device_id display_connector_match[] = {

[Severity: High]
This isn't a bug introduced by this patch, but does the bridge lifetime 
mismatch with devm resources cause a use-after-free?

In display_connector_probe(), the bridge is allocated with 
devm_drm_bridge_alloc(), tying its lifetime to the DRM bridge kref:

display_connector_probe() {
    ...
    conn = devm_drm_bridge_alloc(&pdev->dev, struct display_connector, bridge,
                                 &display_connector_bridge_funcs);
    ...
}

However, devm-managed resources like the HPD GPIO and IRQ are tied to the 
platform device unbind. If the device is unbound via sysfs while the DRM 
core still holds a reference to the bridge, devres will free the GPIO and 
IRQ resources.

If the DRM core later invokes callbacks like detect or hpd_disable, would it 
dereference the freed GPIO or attempt to disable the freed IRQ?

display_connector_detect() {
    ...
    if (gpiod_get_value_cansleep(conn->hpd_gpio))
    ...
}

display_connector_hpd_disable() {
    ...
    disable_irq(conn->hpd_irq);
    ...
}

[Severity: Medium]
This is a pre-existing issue, but is there a hardware state leak on the 
probe error path?

In display_connector_probe(), the DDC enable GPIO is acquired and 
immediately asserted high:

display_connector_probe() {
    ...
    if (type == DRM_MODE_CONNECTOR_HDMIA) {
        ...
        conn->ddc_en = devm_gpiod_get_optional(&pdev->dev, "ddc-en",
                                               GPIOD_OUT_HIGH);

        if (IS_ERR(conn->ddc_en)) {
            ...
        }

        ret = display_connector_get_supply(pdev, conn, "hdmi-pwr");
        if (ret < 0)
            return dev_err_probe(...);
    ...
}

If a subsequent step like display_connector_get_supply() or 
regulator_enable() fails, the function returns an error. While devres will 
free the GPIO descriptor, it doesn't revert the physical pin state.

Unlike display_connector_remove() which explicitly sets the GPIO to 0, does 
this error path leave the DDC bus permanently enabled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260705213542.28987-1-laurent.pinchart+renesas@ideasonboard.com?part=2

  reply	other threads:[~2026-07-05 21:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-05 21:35 [PATCH 0/4] drm: bridge: display-connector: Support hardcoding EDID for VGA Laurent Pinchart
2026-07-05 21:35 ` [PATCH 1/4] dt-bindings: display: vga-connector: Allow hardcoding EDID Laurent Pinchart
2026-07-06  8:08   ` Geert Uytterhoeven
2026-07-06 10:03     ` Laurent Pinchart
2026-07-06  8:52   ` Maxime Ripard
2026-07-06  9:45     ` Laurent Pinchart
2026-07-06 15:40       ` Maxime Ripard
2026-07-06 16:02         ` Laurent Pinchart
2026-07-07  7:46           ` Maxime Ripard
2026-07-07  8:01             ` Laurent Pinchart
2026-07-05 21:35 ` [PATCH 2/4] drm/bridge: display-connector: Fix I2C adapter resource leak Laurent Pinchart
2026-07-05 21:48   ` sashiko-bot [this message]
2026-07-05 23:38     ` Laurent Pinchart
2026-07-05 21:35 ` [PATCH 3/4] drm/bridge: display-connector: Support hardcoded EDID for VGA connectors Laurent Pinchart
2026-07-05 21:44   ` sashiko-bot
2026-07-05 23:38     ` Laurent Pinchart
2026-07-05 21:35 ` [PATCH 4/4] [DNI] arm64: dts: renesas: salvator: Add overlay for Dell P1911 VGA display Laurent Pinchart
2026-07-05 21:37   ` sashiko-bot
2026-07-05 23:39     ` Laurent Pinchart
2026-07-06  8:16   ` Geert Uytterhoeven
2026-07-06  9:48     ` Laurent Pinchart

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=20260705214826.628831F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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.