[igt-dev] [PATCH 1/2] gputop: fix region array max iteration index loop bug

Adrián Larumbe adrian.larumbe at collabora.com
Tue Aug 8 21:03:30 UTC 2023


If c->regions->num_regions equals 1, then c->regions->max_region_id equals
0, so neither of the cumulative memory region size loops will be executed.
Fix it by adjusting loop termination condition.

Signed-off-by: Adrián Larumbe <adrian.larumbe at collabora.com>
---
 tools/gputop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/gputop.c b/tools/gputop.c
index ac106abea2ee..ea95e0333dd2 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -166,11 +166,11 @@ print_client(struct igt_drm_client *c, struct igt_drm_client **prevc,
 	len = printf("%*s ", c->clients->max_pid_len, c->pid_str);
 
 	if (c->regions->num_regions) {
-		for (sz = 0, i = 0; i < c->regions->max_region_id; i++)
+		for (sz = 0, i = 0; i <= c->regions->max_region_id; i++)
 			sz += c->memory[i].total;
 		len += print_size(sz);
 
-		for (sz = 0, i = 0; i < c->regions->max_region_id; i++)
+		for (sz = 0, i = 0; i <= c->regions->max_region_id; i++)
 			sz += c->memory[i].resident;
 		len += print_size(sz);
 	}
-- 
2.41.0



More information about the igt-dev mailing list