Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/msm/dsi: pin count leak in dsi_dma_base_get_6g() [1]
--

commit d8fea90d2c8669ea251b525d2dbbf6c4872f4096
Author: Vladimir Bely <[email protected]>

drm/msm/dsi: implement transfer_batch using multi-packet CMD DMA

This commit implements mipi_dsi_host_ops.transfer_batch() by packing
contiguous write-only DSI messages that share the same LPM flag into a
single command DMA buffer.

> diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
> b/drivers/gpu/drm/msm/dsi/dsi_host.c
> index 78f0fd2594216..6e1630edc1caa 100644
> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
[ ... ]
> @@ -1568,6 +1578,90 @@ static int dsi_cmds2buf_tx(struct msm_dsi_host 
> *msm_host,
>       return len;
>  }
>  
> +static int dsi_cmds2buf_tx_batch(struct msm_dsi_host *msm_host,
> +                              const struct mipi_dsi_msg *msgs, size_t count)
> +{
> +     const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
> +     int max_len = msm_host->tx_size;
> +     int offset = 0, last_offset = 0;
> +     u8 *data = NULL;
> +     size_t i;
> +     int ret;
> +
> +     if ((msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) && msm_host->mode) {
> +             int bllp_len = msm_host->mode->hdisplay *
> +                     mipi_dsi_pixel_format_to_bpp(msm_host->format) / 8;
> +
> +             max_len = min(max_len, bllp_len);
> +     }
> +
> +     for (i = 0; i < count; i++) {
> +             struct mipi_dsi_packet packet;
> +             int pkt_len;
> +
> +             ret = mipi_dsi_create_packet(&packet, &msgs[i]);
> +             if (ret) {
> +                     pr_err("%s: create packet failed, %d\n", __func__, ret);
> +                     goto err_put;
> +             }
> +             pkt_len = (packet.size + 3) & (~0x3);
> +             if (pkt_len > max_len) {
> +                     pr_err("%s: cmd cannot fit into transfer buffer, 
> len=%d\n",
> +                            __func__, pkt_len);
> +                     ret = -EINVAL;
> +                     goto err_put;
> +             }
> +
> +             if (offset > 0 && offset + pkt_len > max_len) {
> +                     data[last_offset + 3] |= BIT(7); /* Last packet */
> +                     if (cfg_hnd->ops->tx_buf_put)
> +                             cfg_hnd->ops->tx_buf_put(msm_host);
> +                     data = NULL;
> +
> +                     ret = dsi_cmd_dma_tx(msm_host, offset);

[Severity: High]
This problem wasn't introduced by this patch, but does dsi_cmd_dma_tx()
leak the pin count on msm_host->tx_gem_obj [1]?

On DSI 6G, dsi_cmd_dma_tx() calls cfg_hnd->ops->dma_base_get(), which
resolves to dsi_dma_base_get_6g():

drivers/gpu/drm/msm/dsi/dsi_host.c:dsi_dma_base_get_6g() {
        ...
        return msm_gem_get_and_pin_iova(msm_host->tx_gem_obj,
                                priv->kms->vm, dma_base);
}

Nothing unpins msm_host->tx_gem_obj after the DMA transfer finishes, so
every command transmission increments pin_count.  Over repeated command
transfers such as brightness updates, the 32-bit pin_count can eventually
overflow, risking premature unpinning and a use-after-free during DMA.

[1] https://sashiko.dev/#/bug/linux-e5a035ef-dc12-4992-93df-f5006f073546

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

Reply via email to