Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>
Cc: robh@kernel.org, conor+dt@kernel.org, krzk+dt@kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v2 12/16] drm/tidss: oldi: Convert OLDI to an aux driver
Date: Thu, 14 May 2026 10:55:04 +0000	[thread overview]
Message-ID: <20260514105504.C05F1C2BCB8@smtp.kernel.org> (raw)
In-Reply-To: <20260513-beagley-ai-display-v2-12-9e9bcefde6bc@ideasonboard.com>

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Dangling device link pointer leads to Use-After-Free if auxiliary_device_add() fails.
- [High] Improper cleanup on `auxiliary_device_init()` failure causes OF node leaks and potential Double Free memory corruption.
- [High] Unchecked array bounds on Device Tree inputs lead to buffer overflows.
- [High] Hardware access proceeds despite `pm_runtime_get_sync()` failure, causing bus errors.
- [High] Asynchronous runtime PM suspend is cancelled by `pm_runtime_disable()`, permanently leaking power.
- [Medium] Resource leaks in error paths and device removal (Device Tree nodes and Clocks).
--

commit 9cc9bfd52317bd0c6d94b12a2ebe2e87339428e8
Author: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Subject: drm/tidss: oldi: Convert OLDI to an aux driver

This commit converts the OLDI to an auxiliary device/driver, created by
tidss, to allow the driver framework to handle enabling and disabling the
power domains.

> diff --git a/drivers/gpu/drm/tidss/tidss_oldi.c b/drivers/gpu/drm/tidss/tidss_oldi.c
> index e925ddaa4fd6a..5331732ac99ee 100644
> --- a/drivers/gpu/drm/tidss/tidss_oldi.c
> +++ b/drivers/gpu/drm/tidss/tidss_oldi.c
[ ... ]
> @@ -251,6 +259,8 @@ static void tidss_oldi_atomic_pre_enable(struct drm_bridge *bridge,
>  	if (oldi->link_type == OLDI_MODE_SECONDARY_CLONE_SINGLE_LINK)
>  		return;
>  
> +	WARN_ON(pm_runtime_get_sync(oldi->dev) < 0);
> +
>  	connector = drm_atomic_get_new_connector_for_encoder(state,
>  							     bridge->encoder);

If pm_runtime_get_sync() fails and returns an error like -ENODEV, should
this function abort?

Proceeding to access hardware registers after a failure could trigger
asynchronous external aborts or kernel panics.

Does this also need pm_runtime_put_noidle() to drop the usage counter on
failure?

[ ... ]
> +static int tidss_oldi_probe(struct auxiliary_device *auxdev,
> +			    const struct auxiliary_device_id *id)
> +{
[ ... ]
> +	link_type = get_oldi_mode(node, &companion_instance);
> +	if (link_type == OLDI_MODE_UNSUPPORTED) {

Looking at get_oldi_mode() which is called here, if the companion reg
property read fails or is out of bounds, it returns early but fails to call
of_node_put(companion).

Does this cause a device node reference leak?

[ ... ]
> +		oldi->serial = of_clk_get_by_name(node, "serial");
> +		if (IS_ERR(oldi->serial)) {
> +			ret = dev_err_probe(oldi->dev, PTR_ERR(oldi->serial),

The oldi->serial clock is acquired via of_clk_get_by_name() here.

Should there be a matching clk_put() in the probe error paths and in
tidss_oldi_remove() to prevent a clock resource leak?

[ ... ]
> +	if (link_type != OLDI_MODE_SECONDARY_DUAL_LINK) {
> +		/* Register the bridge. */
> +		oldi->bridge.of_node = node;
> +		oldi->bridge.driver_private = oldi;
> +
> +		tidss->is_ext_vp_clk[oldi->parent_vp] = true;

The parent_vp value is parsed directly from the device tree's reg property
and used as an array index here.

Is a bounds check against TIDSS_MAX_PORTS (4) needed to prevent a potential
out-of-bounds write?

[ ... ]
> +static void tidss_oldi_remove(struct auxiliary_device *auxdev)
> +{
> +	struct tidss_oldi *oldi = auxiliary_get_drvdata(auxdev);
> +	struct tidss_device *tidss = oldi->tidss;
> +	struct device *dev = &auxdev->dev;
> +
> +	pm_runtime_dont_use_autosuspend(dev);
> +	pm_runtime_disable(dev);

During driver unbinding, drm_atomic_helper_shutdown() calls
tidss_oldi_atomic_post_disable() which queues an asynchronous suspend via
pm_runtime_put_autosuspend(). Immediately afterward, this teardown logic
calls pm_runtime_disable().

Since pm_runtime_disable() cancels any pending asynchronous idle or suspend
work, will the OLDI hardware be left permanently powered on?

[ ... ]
> +static struct auxiliary_device *
> +tidss_oldi_create_device(struct tidss_device *tidss,
> +			 struct device_node *oldi_tx)
> +{
[ ... ]
> +	ret = auxiliary_device_add(auxdev);
> +	if (ret) {
> +		dev_err(tidss->dev, "OLDI auxiliary_device_add failed: %d\n",
> +			ret);
> +		goto err_uninit_auxdev;
> +	}

A managed device link is created between the consumer and supplier before
the consumer (auxdev) is registered. If auxiliary_device_add() fails, the
code jumps to err_uninit_auxdev which frees the auxdev.

Since the consumer was never successfully added to the system, the automatic
link cleanup via device_del() won't trigger.

Will this leave a dangling device link in the supplier's consumer list
pointing to the freed auxdev, resulting in a use-after-free when the
supplier is later purged? Would explicitly calling device_link_del() be
needed on this error path?

> +
> +	tidss->oldis[tidss->num_oldis++] = auxdev;

When adding the parsed child nodes from the device tree, is there a risk
that num_oldis could exceed the statically allocated TIDSS_MAX_OLDI_TXES (2)
array bounds if the device tree is malformed?

> +
> +	return auxdev;
> +
> +err_uninit_auxdev:
> +	auxiliary_device_uninit(auxdev);
> +	/* return here, as the rest are done in auxdev's release */
> +	return ERR_PTR(ret);
> +
> +err_free_auxdev:
> +	kfree(auxdev);
> +err_free_pdata:
> +	kfree(oldi_pdata);
> +err_free_ida:
> +	ida_free(&tidss_oldi_ida, oldi_aux_id);
> +
> +	return ERR_PTR(ret);
> +}

If auxiliary_device_init() fails, jumping to err_free_auxdev calls kfree()
directly on the device structure.

Does bypassing put_device() skip the release callback
(tidss_oldi_aux_device_release) and permanently leak the OF node reference
acquired earlier?

Also, if auxiliary_device_init() internally calls put_device() on failure,
could these explicit kfree() and ida_free() calls in the error path trigger
a double free?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260513-beagley-ai-display-v2-0-9e9bcefde6bc@ideasonboard.com?part=12

  reply	other threads:[~2026-05-14 10:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 13:17 [PATCH v2 00/16] drm/tidss: Add BeagleY-AI display support (and some more) Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 01/16] dt-bindings: display: ti: Move ti,am62l-dss binding to a new binding file Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 02/16] dt-bindings: display: ti,am65x-dss: Simplify binding Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 03/16] dt-bindings: display: ti,am625-oldi: Add optional power-domain for OLDI Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 04/16] dt-bindings: display: ti,am65x-dss: Add ti,dpi-io-ctrl Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 05/16] dt-bindings: display: ti,am65x-dss: Add AM62P DSS Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 06/16] drm/tidss: Remove extra pm_runtime_mark_last_busy Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 07/16] drm/tidss: oldi: Remove define for unused register OLDI_LB_CTRL Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 08/16] drm/tidss: Add mechanism to detect DPI output Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 09/16] drm/tidss: Add external data and sync signal edge configuration Tomi Valkeinen
2026-05-14  7:57   ` sashiko-bot
2026-05-13 13:17 ` [PATCH v2 10/16] drm/tidss: Add support for DPIENABLE bit Tomi Valkeinen
2026-05-14  8:36   ` sashiko-bot
2026-05-13 13:17 ` [PATCH v2 11/16] drm/tidss: oldi: Fix OLDI signal polarities Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 12/16] drm/tidss: oldi: Convert OLDI to an aux driver Tomi Valkeinen
2026-05-14 10:55   ` sashiko-bot [this message]
2026-05-13 13:17 ` [PATCH v2 13/16] drm/tidss: Add support for AM62P display subsystem Tomi Valkeinen
2026-05-13 13:17 ` [PATCH v2 14/16] arm64: dts: ti: k3-am62p-j722s-common-main: Make main_conf a syscon Tomi Valkeinen
2026-05-14 11:19   ` sashiko-bot
2026-05-13 13:17 ` [PATCH v2 15/16] arm64: dts: ti: k3-am62p-j722s-common-main: Add support for DSS Tomi Valkeinen
2026-05-14 11:32   ` sashiko-bot
2026-05-13 13:17 ` [PATCH v2 16/16] arm64: dts: ti: beagley-ai: Enable HDMI display and audio Tomi Valkeinen
2026-05-14 11:56   ` 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=20260514105504.C05F1C2BCB8@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tomi.valkeinen@ideasonboard.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox