On Fri, 2023-10-27 at 17:27 +0530, Animesh Manna wrote: > Refactor DSB implementation to be compatible with Xe driver. > > v1: RFC version. > v2: Make intel_dsb structure opaque from external usage. [Jani] > v3: Rebased on latest. > v4: > - Add boundary check in dsb_buffer_memset(). [Luca] > - Use size_t instead of u32. [Luca] > > Cc: Jani Nikula <jani.nikula@xxxxxxxxx> > Signed-off-by: Animesh Manna <animesh.manna@xxxxxxxxx> > --- [...] > +void intel_dsb_buffer_memset(struct intel_dsb_buffer *dsb_buf, u32 idx, u32 val, size_t size) > +{ > + if ((idx > dsb_buf->buf_size / 4) || (size > dsb_buf->buf_size - idx * 4)) You actually don't need the first expression. This expression should enough: dsb_buf->buf_size <= (idx + size) * sizeof(*dsb_buf->cmd_buf) > + return; Blindly returning here doesn't solve the problem, it just hides it. I think the best would be to use WARN_ON() instead of if. So: WARN_ON(dsb_buf->buf_size <= (idx + size) * sizeof(*dsb_buf->cmd_buf)); > + > + memset(&dsb_buf->cmd_buf[idx], val, size); > +} [...] -- Cheers, Luca.