[PATCH i-g-t 05/12] lib/igt_drm_fdinfo: Detect invalid drm-client-id

Lucas De Marchi lucas.demarchi at intel.com
Fri Apr 5 06:00:49 UTC 2024


Use strtol() for string to long conversion which allows us to detect if
there was an invalid number. It also has the advantage that it already
ignores leading spaces.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/igt_drm_fdinfo.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
index de1962efa..8eb5e5eed 100644
--- a/lib/igt_drm_fdinfo.c
+++ b/lib/igt_drm_fdinfo.c
@@ -216,6 +216,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
 		uint64_t val = 0;
 		size_t keylen;
 		const char *v;
+		char *end_ptr;
 		int idx;
 
 		_buf = NULL;
@@ -229,11 +230,9 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
 			}
 		}  else if (strstartswith(l, "drm-client-id:", &keylen)) {
 			v = l + keylen;
-			v = ignore_space(v);
-			if (*v) {
-				info->id = atol(v);
+			info->id = strtol(v, &end_ptr, 10);
+			if (end_ptr != v)
 				good++;
-			}
 		} else if (strstartswith(l, "drm-pdev:", &keylen)) {
 			v = l + keylen;
 			v = ignore_space(v);
-- 
2.44.0



More information about the igt-dev mailing list