From 6eafd1cf386d93bb9e34660227ca6f26aadfeb32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Fr=C3=B6hlich?= Date: Tue, 3 Nov 2009 11:41:26 -0500 Subject: radeon: fix allocation The old code increments the command stream size by another kbyte, but does not make sure that the requested packet size fits into the stream. The patch ensures that the whole next packet fits there and rounds the allocated size to a power of two. Signed-off-by: Alex Deucher --- libdrm/radeon/radeon_cs_gem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdrm/radeon/radeon_cs_gem.c b/libdrm/radeon/radeon_cs_gem.c index e42ec48f..232ea7f3 100644 --- a/libdrm/radeon/radeon_cs_gem.c +++ b/libdrm/radeon/radeon_cs_gem.c @@ -226,7 +226,8 @@ static int cs_gem_begin(struct radeon_cs *cs, if (cs->cdw + ndw > cs->ndw) { uint32_t tmp, *ptr; - tmp = (cs->ndw + 1 + 0x3FF) & (~0x3FF); + /* round up the required size to a multiple of 1024 */ + tmp = (cs->cdw + ndw + 0x3FF) & (~0x3FF); ptr = (uint32_t*)realloc(cs->packets, 4 * tmp); if (ptr == NULL) { return -ENOMEM; -- cgit v1.2.3