diff mbox

[RFC,027/111] staging: etnaviv: ensure that ring buffer wraps

Message ID 1427988653-754-28-git-send-email-l.stach@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Stach April 2, 2015, 3:29 p.m. UTC
From: Russell King <rmk+kernel@arm.linux.org.uk>

Ensure that the ring buffer wraps when we fill the buffer.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
 drivers/staging/etnaviv/etnaviv_buffer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/staging/etnaviv/etnaviv_buffer.c b/drivers/staging/etnaviv/etnaviv_buffer.c
index a93d5091828e..a8b42a1ec7db 100644
--- a/drivers/staging/etnaviv/etnaviv_buffer.c
+++ b/drivers/staging/etnaviv/etnaviv_buffer.c
@@ -30,7 +30,7 @@ 
 static inline void OUT(struct etnaviv_gem_object *buffer, uint32_t data)
 {
 	u32 *vaddr = (u32 *)buffer->vaddr;
-	BUG_ON(buffer->offset * sizeof(*vaddr) >= buffer->base.size);
+	BUG_ON(buffer->offset >= buffer->base.size / sizeof(*vaddr));
 
 	vaddr[buffer->offset++] = data;
 }
@@ -154,6 +154,12 @@  void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event, struct et
 	if (drm_debug & DRM_UT_DRIVER)
 		etnaviv_buffer_dump(gpu, buffer, 0, 0x50);
 
+	/*
+	 * if we are going to completely overflow the buffer, we need to wrap.
+	 */
+	if (buffer->offset + 6 > buffer->base.size / sizeof(uint32_t))
+		buffer->offset = 0;
+
 	/* save offset back into main buffer */
 	back = buffer->offset;
 	link_target = buffer->paddr + buffer->offset * 4;