drm/i915/dsb: Fix DSB command buffer size checks
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Fri, 16 Dec 2022 00:38:01 +0000 (02:38 +0200)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Fri, 13 Jan 2023 14:48:57 +0000 (16:48 +0200)
free_pos is in dwords, DSB_BUF_SIZE in bytes. Directly
comparing the two is nonsense. Fix it up, and make sure
we also account for the 8byte alignment requirement for
each instruction, and also assume that each instruction
normally eats two dwords.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221216003810.13338-5-ville.syrjala@linux.intel.com
Reviewed-by: Animesh Manna <animesh.manna@intel.com>
drivers/gpu/drm/i915/display/intel_dsb.c

index 6abfd0f..fbcbf9e 100644 (file)
@@ -97,7 +97,7 @@ void intel_dsb_indexed_reg_write(struct intel_dsb *dsb,
        u32 *buf = dsb->cmd_buf;
        u32 reg_val;
 
-       if (drm_WARN_ON(&dev_priv->drm, dsb->free_pos >= DSB_BUF_SIZE)) {
+       if (drm_WARN_ON(&dev_priv->drm, ALIGN(dsb->free_pos, 2) > DSB_BUF_SIZE / 4 - 2)) {
                drm_dbg_kms(&dev_priv->drm, "DSB buffer overflow\n");
                return;
        }
@@ -167,7 +167,7 @@ void intel_dsb_reg_write(struct intel_dsb *dsb,
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        u32 *buf = dsb->cmd_buf;
 
-       if (drm_WARN_ON(&dev_priv->drm, dsb->free_pos >= DSB_BUF_SIZE)) {
+       if (drm_WARN_ON(&dev_priv->drm, ALIGN(dsb->free_pos, 2) > DSB_BUF_SIZE / 4 - 2)) {
                drm_dbg_kms(&dev_priv->drm, "DSB buffer overflow\n");
                return;
        }