All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: dri-devel@lists.freedesktop.org, conor+dt@kernel.org,
	robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v7 02/13] drm/mediatek: Implement Display Stream Compression support
Date: Mon, 14 Sep 2026 12:14:22 +0000	[thread overview]
Message-ID: <20260914121422.EE1DC1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914115812.22751-3-angelogioacchino.delregno@collabora.com>

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] DSI and DSC component detection loop misses the terminal component of the display pipeline, preventing DSC configuration.
- [High] Incorrect execution order for DSC setup and missing state reset causes DSC hardware corruption on subsequent modesets or resume.
- [High] DSI link data rate, horizontal blanking timings, and clock lane word counts do not adjust for DSC compression, breaking timing synchronization.
- [High] The pixel stream word count incorrectly hardcodes an assumption of exactly 2 DSC slices per line.
- [High] DSI power-on accesses uninitialized DSC parameters by invoking `mtk_dsi_ps_control` before computing them.
- [Medium] The `dsi->dsc` pointer is set to NULL during panel unbind without serialization, leading to a Use-After-Free or NULL pointer dereference during modeset.
--

commit d2929d85efc73eb974427b3e2c2a0afbfbe66701
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Subject: drm/mediatek: Implement Display Stream Compression support

This commit adds Display Stream Compression (DSC) support for the MediaTek
DRM driver. It introduces a new standalone mtk_disp_dsc driver and modifies
the existing CRTC and DSI drivers to configure and integrate DSC.

> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index 97e3ff412e6ee..c0a53c153b8d5 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -398,6 +401,17 @@ static int mtk_crtc_ddp_hw_init(struct mtk_crtc *mtk_crtc)
>  		if (!mtk_ddp_comp_add(mtk_crtc->ddp_comp[i], mtk_crtc->mutex))
>  			mtk_mutex_add_comp(mtk_crtc->mutex,
>  					   mtk_crtc->ddp_comp[i]->id);
> +
> +		/* For now, only single DSI is supported */
> +		if (mtk_crtc->ddp_comp[i]->id >= DDP_COMPONENT_DSI0 &&
> +		    mtk_crtc->ddp_comp[i]->id <= DDP_COMPONENT_DSI3)
> +			if (!comp_dsi)
> +				comp_dsi = mtk_crtc->ddp_comp[i];
> +
> +		if (mtk_crtc->ddp_comp[i]->id == DDP_COMPONENT_DSC0 ||
> +		    mtk_crtc->ddp_comp[i]->id == DDP_COMPONENT_DSC1)
> +			if (!comp_dsc)
> +				comp_dsc = mtk_crtc->ddp_comp[i];
>  	}

[Severity: High]
Will this loop successfully find the DSI component? 

The loop condition in mtk_crtc_ddp_hw_init iterates until
mtk_crtc->ddp_comp_nr - 1. Because the DSI encoder is always the terminal
component of the display pipeline at ddp_comp_nr - 1, the loop appears to
terminate before inspecting it.

Could this leave comp_dsi as NULL and skip the DSC configuration entirely?

> @@ -413,6 +427,13 @@ static int mtk_crtc_ddp_hw_init(struct mtk_crtc *mtk_crtc)
>  		mtk_ddp_comp_start(comp);
>  	}
>  
> +	/* Setup the DSC if present, with the config coming from DSI */
> +	if (comp_dsc && comp_dsi) {
> +		dsc_cfg = mtk_dsi_get_dsc_config(comp_dsi->dev);
> +		if (dsc_cfg)
> +			mtk_ddp_comp_dsc_setup(comp_dsc, dsc_cfg);
> +	}

[Severity: High]
Is the hardware started before it is fully configured? 

The preceding loop calls mtk_ddp_comp_start on all components, which will
invoke mtk_dsc_start and write the DSC_EN bit to the control register.

If mtk_ddp_comp_dsc_setup is executed afterwards, could the hardware enter
an invalid state by being enabled before its parameters are applied?

> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_dsc.c b/drivers/gpu/drm/mediatek/mtk_disp_dsc.c
[ ... ]
> +void mtk_dsc_stop(struct device *dev)
> +{
> +	struct mtk_dsc *disp_dsc = dev_get_drvdata(dev);
> +
> +	writel(0, disp_dsc->reg + DISP_REG_DSC_CON);
> +}

[Severity: High]
Should dsc_config_done be reset to false when stopping the hardware?

If mtk_dsc_stop writes 0 to the register but leaves dsc_config_done as
true, a subsequent resume or modeset might cause mtk_dsc_start to see
dsc_config_done == true. 

Would this skip the bypass mode fallback and write DSC_EN over a zeroed
configuration register, potentially hanging the display pipeline?

> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index f82506e10fd59..97b8a91874f5b 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
[ ... ]
> +static void mtk_dsi_ps_control_dsc(struct mtk_dsi *dsi, bool config_vact)
> +{
> +	const struct mtk_dsi_driver_data *data = dsi->driver_data;
> +	const u16 *reg_main = dsi->driver_data->reg_main;
> +	const short dsi_buf_bpp = 3;
> +	u32 ps_wc;
> +
> +	/* Word count */
> +	ps_wc = FIELD_PREP(DSI_PS_WC, 2 * dsi->dsc->slice_chunk_size);

[Severity: High]
Can this hardcoded multiplier cause incorrect word counts on different panels?

Using 2 here assumes there are always exactly 2 DSC slices per line.

Should this use dsi->dsc->slice_count to ensure the payload bytes are
calculated correctly for displays with other slice layouts?

> +	if (config_vact) {
> +		writel(FIELD_PREP(VACT_NL, dsi->vm.vactive),
> +		       dsi->regs + reg_main[DSI_VACT_NL]);
> +		writel(ps_wc, dsi->regs + reg_main[DSI_HSTX_CKL_WC]);
> +	}

[Severity: High]
Does this blindly overwrite the clock lane word count register?

In mtk_dsi_config_vdo_timing_per_frame_lp, hstx_cklp_wc is carefully
calculated based on front porch, back porch, and trailing lengths, and then
written to DSI_HSTX_CKL_WC. When mtk_dsi_ps_control_dsc is subsequently
called, it overwrites that same register with ps_wc (the raw compressed
payload size). 

Additionally, the calculations for dsi->data_rate in mtk_dsi_poweron and
horizontal blanking timings use uncompressed pixel bit depths rather than
adjusting for DSC compression.

Will these issues combined break clock lane timing synchronization?

> @@ -741,10 +828,17 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
>  
>  	mtk_dsi_ps_control(dsi, true);
>  	mtk_dsi_set_vm_cmd(dsi);
> -	mtk_dsi_config_vdo_timing(dsi);
> +	ret = mtk_dsi_config_vdo_timing(dsi);

[Severity: High]
Could this sequence write uninitialized values to the hardware?

mtk_dsi_poweron calls mtk_dsi_ps_control, which reads
dsi->dsc->slice_chunk_size to program the DSI payload size registers.

However, dsi->dsc->slice_chunk_size is only populated when
mtk_dsi_config_vdo_timing eventually calls drm_dsc_compute_rc_parameters.

Does this imply the payload size registers are initially programmed with
zeros or uninitialized memory?

> @@ -1030,6 +1157,8 @@ static int mtk_dsi_host_detach(struct mipi_dsi_host *host,
>  
>  	component_del(host->dev, &mtk_dsi_component_ops);
>  	drm_bridge_remove(&dsi->bridge);
> +	dsi->dsc = NULL;
> +
>  	return 0;
>  }

[Severity: Medium]
Is it safe to clear dsi->dsc without modeset synchronization?

If a user unbinds the panel concurrently while a display modeset is active
(for example, while executing mtk_dsi_config_vdo_timing), could the pointer
become NULL immediately after the check for dsi->dsc? 

Could this lead to a NULL pointer dereference or use-after-free in
mtk_dsi_set_dsc_params?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260914115812.22751-1-angelogioacchino.delregno@collabora.com?part=2

  reply	other threads:[~2026-09-14 12:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 11:57 [PATCH v7 00/13] drm/mediatek: Add DSC, WDMA, MT8189/96 DSI support AngeloGioacchino Del Regno
2026-09-14 11:58 ` [PATCH v7 01/13] dt-bindings: display: mediatek: dsc: Add MT8196 compatible AngeloGioacchino Del Regno
2026-09-14 11:58 ` [PATCH v7 02/13] drm/mediatek: Implement Display Stream Compression support AngeloGioacchino Del Regno
2026-09-14 12:14   ` sashiko-bot [this message]
2026-09-14 11:58 ` [PATCH v7 03/13] dt-bindings: display: mediatek: dsi: Document MT8189 and MT8196 AngeloGioacchino Del Regno
2026-09-14 11:58 ` [PATCH v7 04/13] drm/mediatek: mtk_dsi: Cleanup encoder if reset fails during bind AngeloGioacchino Del Regno
2026-09-14 12:12   ` sashiko-bot
2026-09-14 11:58 ` [PATCH v7 05/13] drm/mediatek: mtk_dsi: Enable interrupt at component bind time AngeloGioacchino Del Regno
2026-09-14 12:11   ` sashiko-bot
2026-09-14 11:58 ` [PATCH v7 06/13] drm/mediatek: mtk_dsi: Transfer register offsets to per-SoC const AngeloGioacchino Del Regno
2026-09-14 11:58 ` [PATCH v7 07/13] drm/mediatek: mtk_dsi: Move max link rate parameter to platform data AngeloGioacchino Del Regno
2026-09-14 12:16   ` sashiko-bot
2026-09-14 11:58 ` [PATCH v7 08/13] drm/mediatek: mtk_dsi: Add support for MT8189 AngeloGioacchino Del Regno
2026-09-14 12:20   ` sashiko-bot
2026-09-14 11:58 ` [PATCH v7 09/13] drm/mediatek: mtk_dsi: Add support for SRAM QoS setting AngeloGioacchino Del Regno
2026-09-14 11:58 ` [PATCH v7 10/13] drm/mediatek: mtk_dsi: Add support for MT8196 AngeloGioacchino Del Regno
2026-09-14 11:58 ` [PATCH v7 11/13] drm/mediatek: mtk_dsi: Enable PM Runtime on probe AngeloGioacchino Del Regno
2026-09-14 12:37   ` sashiko-bot
2026-09-14 11:58 ` [PATCH v7 12/13] dt-bindings: display: mediatek: wdma: Add compatibles for more SoCs AngeloGioacchino Del Regno
2026-09-14 12:30   ` sashiko-bot
2026-09-14 11:58 ` [PATCH v7 13/13] drm/mediatek: Add Write DMA (WDMA) Engine for Writeback support AngeloGioacchino Del Regno
2026-09-14 12:31   ` 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=20260914121422.EE1DC1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.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 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.