Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/rockchip: vop2: unaligned block offset for 10-bit packed
  YUV in vop2_plane_atomic_update()
--

commit e065b869dbf756b6652ed995b5a03b6d5409975e
Author: Chaoyi Chen <[email protected]>

drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets

This commit replaces fb->format->cpp[] with drm_format_info_min_pitch()
when calculating plane byte offsets in vop2_plane_atomic_update() to
support block-packed 10-bit formats such as NV15, NV20, and NV30.

> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c 
> b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
> index bfb3841425687..0de038acb56fc 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
> @@ -1290,7 +1290,7 @@ static void vop2_plane_atomic_update(struct drm_plane 
> *plane,
>  
>       afbc_en = drm_is_afbc(fb->modifier);
>  
> -     offset = (src->x1 >> 16) * fb->format->cpp[0];
> +     offset = drm_format_info_min_pitch(fb->format, 0, src->x1 >> 16);
>  
>       /*
>        * AFBC HDR_PTR must set to the zero offset of the framebuffer.
> @@ -1309,7 +1309,7 @@ static void vop2_plane_atomic_update(struct drm_plane 
> *plane,
>               int hsub = fb->format->hsub;
>               int vsub = fb->format->vsub;
>  
> -             offset = (src->x1 >> 16) * fb->format->cpp[1] / hsub;
> +             offset = (u32)drm_format_info_min_pitch(fb->format, 1, src->x1 
> >> 16) / hsub;
>               offset += (src->y1 >> 16) * fb->pitches[1] / vsub;
>  
>               if ((pstate->rotation & DRM_MODE_REFLECT_Y) && !afbc_en)

[Severity: Medium]
Can this compute misaligned yrgb_mst and uv_mst offsets for NV15, NV20,
and NV30 when src->x1 >> 16 is not a multiple of 4?

Those formats pack 4 luma pixels and 2 chroma pairs into 5-byte blocks
(char_per_block = { 5, 5, 0 }, block_w = { 4, 2, 0 }), but
vop2_plane_atomic_check() only requires 2-pixel alignment on src_x for YUV
formats:

drivers/gpu/drm/rockchip/rockchip_drm_vop2.c:vop2_plane_atomic_check() {
    ...
        if (fb->format->is_yuv && src_x % 2) {
                drm_dbg_kms(vop2->drm, "Invalid Source: Yuv format not support 
odd xpos\n");
                return -EINVAL;
        }
    ...
}

When src_x % 4 == 2 (2.5 bytes into a 5-byte block),
drm_format_info_min_pitch() rounds plane 0 up via DIV_ROUND_UP_ULL() to a
3-byte offset inside a packed 4-pixel block, while dividing plane 1's
5-byte result by hsub = 2 on NV15 and NV20 truncates uv_mst down to a
2-byte offset.  This corrupts scanout and, when src_x + src_w reaches
fb->width with src_w % 4 == 2, can cause DMA to read 1 byte past the
validated framebuffer pitch on the final scanline.  Should
vop2_plane_atomic_check() also require src_x to be aligned to
drm_format_info_block_width()?

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

Reply via email to