Thank you for your contribution! Sashiko AI review found 1 potential issue(s) 
to consider:
- [High] The loop reading DSI RX data in `mtk_dsi_host_transfer` incorrectly 
uses the loop counter to offset the `reg_main` array index instead of the MMIO 
base offset, causing out-of-bounds array reads and accessing incorrect hardware 
registers.
--

--- Patch [5]: [PATCH v2 05/10] drm/mediatek: mtk_dsi: Transfer register 
offsets to per-SoC const ---
commit 43b878ef0a8fe56d80e1c26ea5be280083d3ccaf
Author: AngeloGioacchino Del Regno <[email protected]>

drm/mediatek: mtk_dsi: Transfer register offsets to per-SoC const

This patch refactors the MediaTek DSI driver by moving register offsets
into per-SoC constant arrays. This separates the main DSI registers from the
advanced and SoC-specific ones, preparing the driver for newer hardware
generations with different register layouts.

> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c 
> b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index 284dae372c7c2..6a77ce8eea91f 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
[ ... ]
> @@ -1259,7 +1394,8 @@ static ssize_t mtk_dsi_host_transfer(struct 
> mipi_dsi_host *host,
>       }
>  
>       for (i = 0; i < 16; i++)
> -             *(read_data + i) = readb(dsi->regs + DSI_RX_DATA0 + i);
> +             *(read_data + i) = readb(dsi->regs +
> +                                      
> dsi->driver_data->reg_main[DSI_RX_DATA0 + i]);

[Severity: High]
Does this code read out of bounds on the reg_main array?

The original code added i to the DSI_RX_DATA0 offset to read consecutive bytes.
In the new code, DSI_RX_DATA0 is an enum value (17). When adding i (which goes
up to 15) to DSI_RX_DATA0 inside the index, this accesses reg_main up to index
32, but DSI_MAIN_REG_MAX is only 28.

This means for i >= 4, the code will fetch unrelated register offsets (such as
DSI_RACK or DSI_PHY_LCCON) instead of the expected RX data bytes. For i >= 11,
it reads past the end of the reg_main array, which could cause MMIO reads at
unexpected addresses.

Should the loop counter i be added after the array lookup instead, such as
dsi->driver_data->reg_main[DSI_RX_DATA0] + i?

>  
>       recv_cnt = mtk_dsi_recv_cnt(read_data[0], read_data);
>  
[ ... ]

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=5

Reply via email to