[PATCH i-g-t 5/8] lib/igt_drm_fdinfo: Simplify find_kv()
Lucas De Marchi
lucas.demarchi at intel.com
Tue Apr 2 22:17:13 UTC 2024
index() is deprecate from libc and strchr() should rather be used.
Moreover the return value is NULL or a pointer to the occurrence, never
the initial string and `(p - buf) != keylen` can only be true if ':' is
the next char after the key.
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
lib/igt_drm_fdinfo.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/lib/igt_drm_fdinfo.c b/lib/igt_drm_fdinfo.c
index 17cac4009..15f71e172 100644
--- a/lib/igt_drm_fdinfo.c
+++ b/lib/igt_drm_fdinfo.c
@@ -106,20 +106,17 @@ static int parse_engine(char *line, struct drm_client_fdinfo *info,
static const char *find_kv(const char *buf, const char *key, size_t keylen)
{
- const char *p = buf;
+ const char *p;
if (strncmp(buf, key, keylen))
return NULL;
- p = index(buf, ':');
- if (!p || p == buf)
- return NULL;
- if ((p - buf) != keylen)
+ p = buf + keylen;
+ if (*p != ':')
return NULL;
- p++;
- while (*p && isspace(*p))
- p++;
+ for (p++; *p && isspace(*p); p++)
+ ;
return *p ? p : NULL;
}
@@ -233,8 +230,7 @@ __igt_parse_drm_fdinfo(int dir, const char *fd, struct drm_client_fdinfo *info,
if ((v = find_kv(l, "drm-driver", strlen("drm-driver")))) {
strncpy(info->driver, v, sizeof(info->driver) - 1);
good++;
- } else if ((v = find_kv(l, "drm-client-id",
- strlen("drm-client-id")))) {
+ } else if ((v = find_kv(l, "drm-client-id", strlen("drm-client-id")))) {
info->id = atol(v);
good++;
} else if ((v = find_kv(l, "drm-pdev", strlen("drm-pdev")))) {
--
2.43.0
More information about the igt-dev
mailing list