From 794ddbd1a046ff5744209e615bdfcfd0f34c4c8d Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Thu, 17 May 2018 16:10:25 +0300 Subject: gpu: nvgpu: fix oob access in submit profiling dump The number of samples has to be at least the number of percentile ranges (here 20) for the reporting to work as expected and also to not cause negative indices in reading the sorted profile data. If there are not enough samples, just report all zeroes. Change-Id: Ie893859d95074f5ceabf6abe873941873668861d Signed-off-by: Konsta Holtta Reviewed-on: https://git-master.nvidia.com/r/1721892 Reviewed-by: Terje Bergstrom Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/debug_fifo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/common/linux/debug_fifo.c b/drivers/gpu/nvgpu/common/linux/debug_fifo.c index b2a87e0d..f2aaef58 100644 --- a/drivers/gpu/nvgpu/common/linux/debug_fifo.c +++ b/drivers/gpu/nvgpu/common/linux/debug_fifo.c @@ -222,10 +222,11 @@ static unsigned int __gk20a_fifo_create_stats(struct gk20a *g, __profile_cmp, NULL); /* build ranges */ - for (index = 0; index < PERCENTILE_RANGES; index++) - percentiles[index] = + for (index = 0; index < PERCENTILE_RANGES; index++) { + percentiles[index] = nelem < PERCENTILE_RANGES ? 0 : g->fifo.profile.sorted[(PERCENTILE_WIDTH * (index + 1) * nelem)/100 - 1]; + } return nelem; } -- cgit v1.2.2