[Mesa-dev] [PATCH 3/4] radeonsi: Prevent overflow when calculating the scratch size.

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Tue Apr 19 22:50:45 UTC 2016


Signed-off-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
---
 src/gallium/drivers/radeonsi/si_compute.c       | 5 ++++-
 src/gallium/drivers/radeonsi/si_state_shaders.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c
index b4981b4..b46a2fe 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -201,7 +201,10 @@ static bool si_setup_compute_scratch_buffer(struct si_context *sctx,
 {
 	uint64_t scratch_bo_size, scratch_needed;
 	scratch_bo_size = 0;
-	scratch_needed = config->scratch_bytes_per_wave * sctx->scratch_waves;
+
+	scratch_needed = config->scratch_bytes_per_wave *
+	                                          (uint64_t)sctx->scratch_waves;
+
 	if (sctx->compute_scratch_buffer)
 		scratch_bo_size = sctx->compute_scratch_buffer->size;
 
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 412a4c9..fef676b 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1679,7 +1679,7 @@ static bool si_update_spi_tmpring_size(struct si_context *sctx)
 	unsigned scratch_bytes_per_wave =
 		si_get_max_scratch_bytes_per_wave(sctx);
 	unsigned scratch_needed_size = scratch_bytes_per_wave *
-		sctx->scratch_waves;
+		(uint64_t)sctx->scratch_waves;
 	unsigned spi_tmpring_size;
 	int r;
 
-- 
2.8.0



More information about the mesa-dev mailing list