Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/sti: skipped GDP clock update on modeset in
  sti_gdp_atomic_update()
- [Medium] drm/sti: clock enabled before rate setup and leaked in
  sti_gdp_atomic_update()
--

commit d592a33824a375f249463d88ff389958a6b8400e
Author: Minseo Park <[email protected]>

drm/sti: gdp: set the pixel clock from .atomic_update()

This commit moves the GDP pixel clock reparenting and rate configuration
from sti_gdp_atomic_check() to sti_gdp_atomic_update(), using
clk_round_rate() in sti_gdp_atomic_check() to validate the mode clock
when the parent clock does not change.

> diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
> index d0c886029c570..4a01bc64f4ab0 100644
> --- a/drivers/gpu/drm/sti/sti_gdp.c
> +++ b/drivers/gpu/drm/sti/sti_gdp.c
[ ... ]
> @@ -757,6 +760,32 @@ static void sti_gdp_atomic_update(struct drm_plane 
> *drm_plane,
>       }
>  
>       mode = &crtc->mode;
> +
> +     /* Set gdp clock */
> +     if (mode->clock && gdp->clk_pix) {
> +             struct sti_mixer *mixer = to_sti_mixer(crtc);
> +             int rate = mode->clock * 1000;
> +             struct clk *clkp;
> +
> +             /*
> +              * According to the mixer used, the gdp pixel clock
> +              * should have a different parent clock.
> +              */
> +             if (mixer->id == STI_MIXER_MAIN)
> +                     clkp = gdp->clk_main_parent;
> +             else
> +                     clkp = gdp->clk_aux_parent;
> +
> +             if (clkp)
> +                     clk_set_parent(gdp->clk_pix, clkp);
> +
> +             if (clk_set_rate(gdp->clk_pix, rate) < 0) {
> +                     drm_err_once(drm_plane->dev,
> +                                  "Cannot set rate (%dHz) for gdp\n", rate);
> +                     return;
> +             }
> +     }

[Severity: High]
Can sti_gdp_atomic_update() skip this clock update when a modeset changes
mode->clock or moves the plane to another CRTC without changing the plane's
framebuffer or coordinates?

Earlier in sti_gdp_atomic_update(), the function returns early if fb and
the crtc_* and src_* coordinates are unchanged:

drivers/gpu/drm/sti/sti_gdp.c:sti_gdp_atomic_update() {
    ...
        if ((oldstate->fb == newstate->fb) &&
            (oldstate->crtc_x == newstate->crtc_x) &&
            (oldstate->crtc_y == newstate->crtc_y) &&
            (oldstate->crtc_w == newstate->crtc_w) &&
            (oldstate->crtc_h == newstate->crtc_h) &&
            (oldstate->src_x == newstate->src_x) &&
            (oldstate->src_y == newstate->src_y) &&
            (oldstate->src_w == newstate->src_w) &&
            (oldstate->src_h == newstate->src_h)) {
                /* No change since last update, do not post cmd */
                DRM_DEBUG_DRIVER("No change, not posting cmd\n");
                plane->status = STI_PLANE_UPDATED;
                return;
        }
    ...
}

Previously, sti_gdp_atomic_check() always ran clk_set_parent() and
clk_set_rate() when the CRTC mode or CRTC assignment changed.  With the
clock setup placed after this early return, a refresh-rate change at the
same resolution or a switch between STI_MIXER_MAIN and STI_MIXER_AUX with
the same fb and coordinates returns before updating gdp->clk_pix, leaving
the plane scanning out with the old pixel clock rate or wrong parent clock.

[Severity: Medium]
When a disabled GDP plane is first enabled (!gdp->vtg), does returning on
clk_set_rate() failure leak the VTG client registration and gdp->clk_pix
enable count?

Just above the new clock block, sti_gdp_atomic_update() sets gdp->vtg,
registers gdp->vtg_field_nb, and calls clk_prepare_enable(gdp->clk_pix):

drivers/gpu/drm/sti/sti_gdp.c:sti_gdp_atomic_update() {
    ...
        if (!gdp->vtg) {
                struct sti_compositor *compo = dev_get_drvdata(gdp->dev);
                struct sti_mixer *mixer = to_sti_mixer(crtc);

                /* Register gdp callback */
                gdp->vtg = compo->vtg[mixer->id];
                sti_vtg_register_client(gdp->vtg, &gdp->vtg_field_nb, crtc);
                clk_prepare_enable(gdp->clk_pix);
        }
    ...
}

Besides enabling gdp->clk_pix before its parent and rate are configured,
sti_gdp_atomic_check() skips clk_round_rate() when the parent clock
changes, so clk_set_rate() can fail here.  Returning early leaves
gdp->clk_pix enabled and gdp->vtg_field_nb registered while plane->status
remains STI_PLANE_DISABLED, so disabling the CRTC will not call
sti_gdp_disable() to clean them up.

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

Reply via email to