RE: [PATCH] drm/i915/pfit: Prevent negative coordinates in center mode

Garg, Nemesa
2026-03-31T18:24:30Z

> -----Original Message-----
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Sent: Tuesday, March 31, 2026 11:32 PM
> To: Garg, Nemesa <nemesa.garg@intel.com>
> Cc: intel-gfx@lists.freedesktop.org; intel-xe@lists.freedesktop.org
> Subject: Re: [PATCH] drm/i915/pfit: Prevent negative coordinates in center
> mode
>
> On Tue, Mar 31, 2026 at 11:10:44PM +0530, Nemesa Garg wrote:
> > When the pipe_src width or height are greater than adjusted_mode
> > hdisplay and vdisplay, computed x and y offsets for center mode can be
> negative.
> > Writing negative values into the pch_fit registers result in a state error.
> > Add a check to clamp these values so that they are never negative.
> >
> > Signed-off-by: Nemesa Garg <nemesa.garg@intel.com>
> > ---
> > drivers/gpu/drm/i915/display/intel_pfit.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_pfit.c
> > b/drivers/gpu/drm/i915/display/intel_pfit.c
> > index 6dda496190e0..1507c2b5b5c7 100644
> > --- a/drivers/gpu/drm/i915/display/intel_pfit.c
> > +++ b/drivers/gpu/drm/i915/display/intel_pfit.c
> > @@ -186,6 +186,7 @@ static int pch_panel_fitting(struct intel_crtc_state
> *crtc_state,
> > const struct drm_connector_state *conn_state) {
> > struct intel_display *display = to_intel_display(crtc_state);
> > + struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
> > const struct drm_display_mode *adjusted_mode =
> > &crtc_state->hw.adjusted_mode;
> > int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
> > @@ -204,6 +205,16 @@ static int pch_panel_fitting(struct intel_crtc_state
> *crtc_state,
> > height = pipe_src_h;
> > x = (adjusted_mode->crtc_hdisplay - width + 1)/2;
> > y = (adjusted_mode->crtc_vdisplay - height + 1)/2;
> > + if (adjusted_mode->crtc_hdisplay < width ||
> > + adjusted_mode->crtc_vdisplay < height) {
> > + drm_dbg_kms(display->drm,
> > + "[CRTC:%d:%s] pfit center mode source
> (%dx%d) exceeds display (%dx%d)\n",
> > + crtc->base.base.id, crtc->base.name,
> > + width, height,
>
> width,height represent the pfit output window size. So I think it'd be better to
> do the check in terms of pipe_src_w,pipe_src_h.
>
> And I guess then we can do it before we even compute x,y,width,height.
>
Sure. Will change.

Thanks and Regards,
Nemesa
> > + adjusted_mode->crtc_hdisplay,
> > + adjusted_mode->crtc_vdisplay);
> > + return -EINVAL;
> > + }
> > break;
> >
> > case DRM_MODE_SCALE_ASPECT:
> > --
> > 2.25.1
>
> --
> Ville Syrjälä
> Intel